< Summary

Class:WinSolutions.Sveta.Server.Services.Implements.DownloadGoodsImagesTaskService
Assembly:WinSolutions.Sveta.Server
File(s):/opt/dev/sveta_api_build/WinSolutions.Sveta.Server/Services/Implements/DownloadGoodsImagesTaskService.cs
Covered lines:0
Uncovered lines:34
Coverable lines:34
Total lines:68
Line coverage:0% (0 of 34)
Covered branches:0
Total branches:4
Branch coverage:0% (0 of 4)

Metrics

MethodLine coverage Branch coverage
.ctor(...)0%100%
Create()0%0%
FindCurrent()0%100%
FindNextPending()0%100%
Update()0%100%

File(s)

/opt/dev/sveta_api_build/WinSolutions.Sveta.Server/Services/Implements/DownloadGoodsImagesTaskService.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Microsoft.Extensions.Logging;
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6using System.Text;
 7using System.Threading.Tasks;
 8using WinSolutions.Sveta.Common;
 9using WinSolutions.Sveta.Server.Data.DataModel.Contexts;
 10using WinSolutions.Sveta.Server.Data.DataModel.Entities;
 11using WinSolutions.Sveta.Server.Services.Interfaces;
 12
 13namespace WinSolutions.Sveta.Server.Services.Implements
 14{
 15    public class DownloadGoodsImagesTaskService : SvetaServiceBase, IDownloadGoodsImagesTaskService
 16    {
 17        private readonly SvetaDbContext _db;
 18        private readonly ILogger<DownloadGoodsImagesTaskService> _logger;
 19
 20        public DownloadGoodsImagesTaskService(SvetaDbContext db, ILogger<DownloadGoodsImagesTaskService> logger, IAuthen
 021            : base(authenticationService)
 022        {
 023            _db = db;
 024            _logger = logger;
 025        }
 26
 27        public async Task<DownloadGoodsImagesTask> Create(bool activeGoodsOnly)
 028        {
 029            var currentTask = await _db.DownloadGoodsImagesTasks.FirstOrDefaultAsync(x => !x.IsDeleted
 030                && (x.InProgress || (!x.InProgress && !x.FinishedDate.HasValue))
 031                && x.CreatedByUserId == CurrentUserId);
 032            if (currentTask != null)
 033            {
 034                return currentTask;
 35            }
 36
 037            var tasks = _db.DownloadGoodsImagesTasks.Where(x => !x.IsDeleted && x.CreatedByUserId == CurrentUserId);
 038            foreach(var t in tasks)
 039            {
 040                t.IsDeleted = true;
 041            }
 042            await _db.SaveChangesAsync(CurrentUserId);
 43
 044            currentTask = new DownloadGoodsImagesTask();
 045            currentTask.ActiveGoodsOnly = activeGoodsOnly;
 046            _db.Add(currentTask);
 047            await _db.SaveChangesAsync(CurrentUserId);
 48
 049            return currentTask;
 050        }
 51
 52        public async Task<DownloadGoodsImagesTask> FindCurrent()
 053        {
 054            return await _db.DownloadGoodsImagesTasks.FirstOrDefaultAsync(x => !x.IsDeleted && x.CreatedByUserId == Curr
 055        }
 56
 57        public async Task<DownloadGoodsImagesTask> FindNextPending()
 058        {
 059            return await _db.DownloadGoodsImagesTasks.FirstOrDefaultAsync(x => !x.IsDeleted && !x.InProgress && !x.Finis
 060        }
 61
 62        public async Task Update(DownloadGoodsImagesTask data)
 063        {
 064            _db.Update(data);
 065            await _db.SaveChangesAsync();
 066        }
 67    }
 68}