public async void SubmitButton() { if (VerifyFields()) { int ProductID = await ProductProcessor.CreateProduct(Product).ConfigureAwait(false); //save Product Images await ImageProcessor.SaveImage(ImageDisplayPath, ProductID).ConfigureAwait(false); ((PostLogInViewModel)Parent).ActiveItem = new UserViewModel(((PostLogInViewModel)Parent)?.User); } }
public ActionResult AddProduct(ProductModel productModel) { if (ModelState.IsValid) { //Saving image to folder string fileName = Path.GetFileNameWithoutExtension(productModel.ImageFile.FileName); string extension = Path.GetExtension(productModel.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; productModel.ImagePath = "~/Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Images/"), fileName); productModel.ImageFile.SaveAs(fileName); //Saving Product to database int recordsCreated = ProductProcessor.CreateProduct(productModel.ProductCode, productModel.Description, productModel.UnitOfMeasure, productModel.Category, productModel.Price, productModel.ImageTitle, productModel.ImagePath, productModel.IsActive); return(RedirectToAction("ListProducts")); } return(View()); }
public ActionResult CreateProduct(ProductModel model) { if (ModelState.IsValid) { List <DataLibrary.Models.ProductModel> products = ProductProcessor.LoadProducts(); products = products.Where(a => a.ProductID == model.ProductID || a.ProductName == model.ProductName).ToList(); if (products.Count() > 0) { TempData["DuplicateProduct"] = "You have entered a duplicate product, please enter a new product."; return(View()); } else { //left as int for testing purposes int recordsCreated = ProductProcessor.CreateProduct(model.ProductID, model.ProductName, model.Manufacturer, model.Style, model.PurchasePrice, model.SalePrice, model.Qty, model.CommissionPercentage); return(RedirectToAction("ViewProduct")); } } return(View()); }
// POST: api/Product public async Task <int> Post([FromBody] ProductModel product) { int id = await ProductProcessor.CreateProduct(product); return(id); }