private async void btnUpdate_Click(object sender, EventArgs e) { Product product = new Product() { ProductID = _id, ProductName = txtUpdateProduct.Text, CategoryId = (int)cmbUpdateCategories.SelectedValue, UnitPrice = decimal.Parse(txtUpdateUnitPrice.Text), UnitsInStock = short.Parse(txtUpdateUnitsInStock.Text) }; bool result = await _productPrecessor.UpdateProduct(product); await GetList(); }
public ActionResult UpdateProduct(ProductModel model) { if (ModelState.IsValid) { List <DataLibrary.Models.ProductModel> products = ProductProcessor.LoadProducts(); ProductModel sessionModel = (ProductModel)Session["ProductUpdateModel"]; //recreating list without the session model in it. products = products.Where(a => a.ProductID != sessionModel.ProductID).ToList(); //isolate(if any) duplicates products = products.Where(a => a.ProductID == model.ProductID || a.ProductName == model.ProductName).ToList(); //if the session model's identifying variable is the same as the parameter model, then it is okay to update (same account, same update) //if the session model's identifying variable is NOT the same, then it is NOT okay to update (updating the current model to a duplicate that already exists) //checking to see if the session model is the same as the parameter model. If same, update, if not, proceed. if (sessionModel.ProductName == model.ProductName) { //left as int for testing purposes int recordsCreated = ProductProcessor.UpdateProduct(model.ProductID, model.ProductName, model.Manufacturer, model.Style, model.PurchasePrice, model.SalePrice, model.Qty, model.CommissionPercentage); return(RedirectToAction("ViewProduct")); } else { //if duplicates exist, throw alert and deny update. 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.UpdateProduct(model.ProductID, model.ProductName, model.Manufacturer, model.Style, model.PurchasePrice, model.SalePrice, model.Qty, model.CommissionPercentage); return(RedirectToAction("ViewProduct")); } } } return(View()); }
public ActionResult EditProduct(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); //Updating Product in database int recordsCreated = ProductProcessor.UpdateProduct(productModel.Id, productModel.ProductCode, productModel.Description, productModel.UnitOfMeasure, productModel.Category, productModel.Price, productModel.ImageTitle, productModel.ImagePath, productModel.IsActive); return(RedirectToAction("ListProducts")); } return(View()); }
public void UpdateProduct([FromBody] ProductModel product) { ProductProcessor.UpdateProduct(product); }