Пример #1
0
        public ActionResult Create(ProductViewModel product)
        {
            if (ModelState.IsValid)
            {
                var brandModel = new BrandModel()
                {
                    BrandId = product.Brand.BrandId,
                    Name    = product.Brand.Name
                };
                var categoryModel = new CategoryModel()
                {
                    CategoryId = product.Category.CategoryId,
                    Name       = product.Category.Name
                };
                var BrandCategoryId = productHandler.GetBrandCategoryId(brandModel, categoryModel);

                var productToCreate = new ProductModel
                {
                    BrandCategoryId = BrandCategoryId,
                    Name            = product.Name,
                    Description     = product.Description,
                    Price           = product.Price,
                    DateCreated     = DateTime.Now
                };
                var productId = productHandler.CreateProductAndGetId(productToCreate);

                return(RedirectToAction("Create", "Specifications", new SpecificationsListViewModel
                {
                    ProductId = productId,
                    CategoryId = product.Category.CategoryId
                }));
            }
            else
            {
                return(RedirectToAction("Create"));
            }
        }