public async Task <IActionResult> Create(ProductAdminCreateViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            await this.productsService.CreateProductAsync(inputModel);

            return(this.RedirectToAction("AllProducts"));
        }
        public IActionResult Create()
        {
            var categories = this.categoriesService.GetAllProductCategories();

            var productViewmodel = new ProductAdminCreateViewModel
            {
                Categories = categories,
            };

            return(this.View(productViewmodel));
        }
Exemplo n.º 3
0
        public async Task CreateProductAsync(ProductAdminCreateViewModel inputModel)
        {
            if (!this.dbContext.ProductCategories.Any(u => u.Id == inputModel.CategoryId))
            {
                throw new ArgumentNullException(string.Format(ServicesConstants.InvalidProductCategoryId, inputModel.CategoryId));
            }

            var product = new Product
            {
                Name        = inputModel.Name,
                Price       = inputModel.Price,
                Size        = inputModel.Size,
                Color       = inputModel.Color,
                Sort        = inputModel.Sort,
                Type        = inputModel.Type,
                Rating      = inputModel.Rating,
                Description = inputModel.Description,
                CategoryId  = inputModel.CategoryId,
            };

            await this.dbContext.Products.AddAsync(product);

            await this.dbContext.SaveChangesAsync();
        }