public async Task <int> AddAsync(string name, string nameEng, decimal price, string description, string descriptionEng, bool acceptCharms, string sizes, Guid productCategoryId)
        {
            var category = await productCategoryRepository.GetAndEnsureExistAsync(productCategoryId);

            var imagesPath = pathManager.GetProductPath(category.UniqueName, name.AppendRandom(5));
            var product    = new Product(name, nameEng, price, description, descriptionEng, acceptCharms, sizes, imagesPath);

            category.AddProduct(product);
            await productCategoryRepository.SaveChangesAsync();

            return(product.Id);
        }
Пример #2
0
        public async Task <int> AddAsync(string name, string nameEng, decimal price, string description, string descriptionEng,
                                         bool acceptCharms, int maxCharmsCount, string sizes, Guid productCategoryId)
        {
            var category = await productCategoryRepository.GetAndEnsureExistAsync(productCategoryId);

            if (category.Products.Count > 1)
            {
                throw new StreetwoodException(ErrorCode.ThisProductCategoryCanHasOnlyOneProduct);
            }

            var imagesPath = pathManager.GetProductPath(category.UniqueName, name.AppendRandom(5));
            var product    = new Product(name, nameEng, price, description, descriptionEng, acceptCharms, maxCharmsCount, sizes, imagesPath);

            category.AddProduct(product);
            await productCategoryRepository.SaveChangesAsync();

            return(product.Id);
        }
Пример #3
0
        public async Task <int> AddAsync(AddProductDto dto)
        {
            var category = await productCategoryRepository.GetAndEnsureExistAsync(dto.ProductCategoryId);

            if (category.HasOneProduct)
            {
                var existingAvailableProducts = category.Products.Where(x => x.Status == ItemStatus.Available);
                if (existingAvailableProducts.Any())
                {
                    throw new StreetwoodException(ErrorCode.ThisProductCategoryCanHasOnlyOneProduct);
                }
            }

            var imagesPath = pathManager.GetProductPath(category.UniqueName, dto.Name.AppendRandom(5));
            var product    = new Product(
                dto.Name, dto.NameEng, dto.Price, dto.Description, dto.DescriptionEng, dto.AcceptCharms, dto.AcceptGraver, dto.MaxCharmCount, dto.Sizes, imagesPath);

            category.AddProduct(product);
            await productCategoryRepository.SaveChangesAsync();

            return(product.Id);
        }