public async Task SetCategoriesAsync(Guid discountId, IEnumerable <Guid> categoryIds)
        {
            var discount = await productCategoryDiscountRepository.GetAndEnsureExistAsync(discountId);

            var categories = await productCategoryRepository.GetByIdsAsync(categoryIds);

            await discountCategoryRepository.DeleteRangeAsync(discount);

            var discountCategories = categories.Select(category => new DiscountCategory(category, discount)).ToList();

            await discountCategoryRepository.AddRangeAsync(discountCategories);

            await discountCategoryRepository.SaveChangesAsync();
        }
コード例 #2
0
        public async Task <IList <ProductsCategoriesForDiscountDto> > GetCategoriesForDiscountAsync(Guid id)
        {
            var discount = await discountRepository.GetAndEnsureExistAsync(id);

            var discountCategories = await discountCategoryRepository.GetCategories(discount);

            var categories = await productCategoryRepository.GetChildrenAsync();

            var mapped = MapCategories(categories, discountCategories);

            return(mapped);
        }