Пример #1
0
        public async Task <ProductsCompareModel> GetProductCompareViewData(params string[] products)
        {
            if (products is null || products.Length == 0)
            {
                return(null);
            }

            var compareProducts = await _accessManager.Filter(_productDataService.Query)
                                  .Where(x => products.Contains(x.Url))
                                  .Include(x => x.Fields)
                                  .Include(x => x.Pictures)
                                  .ToListAsync();

            if (!AllProductHasSameSchemeAndCat(compareProducts))
            {
                return(null);
            }

            var retVal = new ProductsCompareModel
            {
                Products        = compareProducts,
                Scheme          = await _schemeDataService.GetAsync(compareProducts.First().SchemeId),
                PrimaryCategory = await _productCategoryDataService.GetAsync(compareProducts.First().PrimaryCategoryId)
            };

            retVal.Products.ForEach(FetchAvalailbleDiscounts);

            return(retVal);
        }
Пример #2
0
        public async Task <ProductCategoryDeleteResponse> Delete(ProductCategoryDeleteRequest request)
        {
            if (_productDataService.Query.Any(x => x.PrimaryCategoryId == request.Id))
            {
                return new ProductCategoryDeleteResponse
                       {
                           Access  = ResponseAccess.BadRequest,
                           Message = "محصولاتی با این دسته بندی وجود دارند"
                       }
            }
            ;

            var categoryToDelete = await _categoryData.GetAsync(request.Id);

            if (!HasAccessToManage(categoryToDelete, request.RequestOwner))
            {
                return(new ProductCategoryDeleteResponse());
            }


            await BaseBeforeDeleteAsync(categoryToDelete, request.RequestOwner);

            await _categoryData.DeleteAsync(request.Id);

            await BaseAfterDeleteAsync(categoryToDelete, request.RequestOwner);

            return(new ProductCategoryDeleteResponse {
                Access = ResponseAccess.Granted
            });
        }
        private async Task LoadRelatedData(Product product)
        {
            product.Scheme = await _schemeDataService.GetAsync(product.SchemeId);

            product.PrimaryCategory = await _productCategoryDataService.GetAsync(product.PrimaryCategoryId);

            await product.LoadDataByOptionsAsync(_unitOfWork);
        }