public async Task <DALChangeDTO> FindDTOAsync(int changeId)
        {
            var change = await RepoDbSet
                         .Include(c => c.ChangeName)
                         .ThenInclude(name => name.Translations)
                         .Include(c => c.ChangeInCategories)
                         .ThenInclude(obj => obj.Category)
                         .Include(c => c.Prices)
                         .Where(c => c.IsDeleted == false && c.Id == changeId)
                         .SingleOrDefaultAsync();

            if (change == null)
            {
                return(null);
            }

            var currentPrice = PriceFinder.ForChange(change, change.Prices, DateTime.Now);

            if (currentPrice == null)
            {
                return(null);
            }

            return(ChangeMapper.FromDomain(change));
        }
        public async Task <DALChangeDTO> AddAsync(DALChangeDTO changeDTO)
        {
            var change = ChangeMapper.FromDAL(changeDTO);

            change = (await RepoDbSet.AddAsync(change)).Entity;
            if (change == null)
            {
                return(null);
            }
            await RepoDbContext.Entry(change).Reference(c => c.ChangeName).LoadAsync();

            await RepoDbContext.Entry(change.ChangeName).Collection(c => c.Translations).LoadAsync();

            return(ChangeMapper.FromDomain(change));
        }
        public async Task <DALChangeDTO> EditAsync(DALChangeDTO changeDTO)
        {
            var change = await RepoDbSet.FindAsync(changeDTO.Id);

            if (change == null)
            {
                return(null);
            }

            await RepoDbContext.Entry(change).Reference(c => c.ChangeName).LoadAsync();

            await RepoDbContext.Entry(change.ChangeName).Collection(c => c.Translations).LoadAsync();


            change.ChangeName.SetTranslation(changeDTO.Name);

            return(ChangeMapper.FromDomain(change));
        }
Beispiel #4
0
        public async Task <List <DALChangeDTO> > GetChangesByCategoryIdsAsync(int[] categoryIds)
        {
            var changeInCategories = await RepoDbSet
                                     .Include(obj => obj.Category)
                                     .ThenInclude(category => category.CategoryName)
                                     .ThenInclude(name => name.Translations)
                                     .Include(obj => obj.Change)
                                     .ThenInclude(change => change.ChangeName)
                                     .ThenInclude(name => name.Translations)
                                     .Include(obj => obj.Change)
                                     .ThenInclude(change => change.Prices)
                                     .Where(obj => categoryIds.Contains(obj.CategoryId) && obj.Change.IsDeleted == false)
                                     .ToListAsync();

            return(changeInCategories
                   .Select(changeInCategory => ChangeMapper.FromDomain(changeInCategory.Change))
                   .Where(dto => dto.CurrentPrice != decimal.MinusOne)
                   .Distinct()
                   .ToList());
        }