public async Task <bool> InsertProduct(ProductsCreateViewModel model)
        {
            bool status = false;

            try
            {
                if (ModelState.IsValid)
                {
                    var product = new Product()
                    {
                        CategoryID = 2,
                        Count      = model.Count,
                        Name       = model.Name,
                        Price      = model.Price
                    };
                    await _uw.BaseRepository <Product>().CreateAsync(product);

                    await _uw.Commit();

                    status = true;
                }
            }
            catch (Exception ex)
            {
                status = false;
            }
            return(status);
        }
Example #2
0
        public IActionResult Create(ProductsCreateViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            this.productService.CreateProduct(model);

            return(this.Redirect("/"));
        }
        public void CreateProduct(ProductsCreateViewModel model)
        {
            var product = new Product
            {
                Name        = model.Name,
                Price       = model.Price,
                Description = model.Description,
                Type        = Enum.Parse <ProductType>(model.Type)
            };

            this.db.Products.Add(product);
            this.db.SaveChanges();
        }
        public async Task <IActionResult> Create(ProductsCreateViewModel model)
        {
            var product = new Product
            {
                Description = model.Description,
                Name        = model.Name,
                Price       = model.Price,
                Type        = model.Type
            };

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

            await this.chushkaDbContext.SaveChangesAsync();

            return(this.RedirectToAction("Index", "Home"));
        }
Example #5
0
        public IActionResult Create(ProductsCreateViewModel model)
        {
            this.productsService.CreateProduct(model);

            return(this.RedirectToAction("/"));
        }