public ActionResult Update(int id, IFormCollection collection) { var product = new Product { ProductId = Int32.Parse(collection["ProductId"]), Name = collection["Name"], Manufacturer = collection["Manufacturer"], Style = collection["Style"], PurchasePrice = Decimal.Parse(collection["PurchasePrice"]), SalePrice = Decimal.Parse(collection["SalePrice"]), QtyOnHand = Int32.Parse(collection["QtyOnHand"]), CommissionPercentage = Decimal.Parse(collection["CommissionPercentage"]) }; try { if (!productService.UpdateProduct(product)) { throw (new Exception("Failure to update product. Check the database connection or if you are creating a duplicate salesperson.")); } return(RedirectToAction(nameof(Index))); } catch (Exception e) { var error = new Models.ErrorViewModel(); error.ErrorMessage = e.Message; return(View("Error", error)); } }
public ActionResult Update(int id, IFormCollection collection) { var startDate = DateTime.Parse(collection["StartDate"]); DateTime?terminationDate; if (String.IsNullOrEmpty(collection["TerminationDate"])) { terminationDate = null; } else { terminationDate = DateTime.Parse(collection["TerminationDate"]); } var salesperson = new Salesperson { SalespersonId = Int32.Parse(collection["SalespersonId"]), FirstName = collection["FirstName"], LastName = collection["LastName"], Address = collection["Address"], Phone = collection["Phone"], StartDate = startDate, TerminationDate = terminationDate, Manager = collection["Manager"] }; try { if (!salespersonService.UpdateSalesperson(salesperson)) { throw (new Exception("Failure to update salesperson. Check the database connection or if you are creating a duplicate salesperson.")); } return(RedirectToAction(nameof(Index))); } catch (Exception e) { var error = new Models.ErrorViewModel(); error.ErrorMessage = e.Message; return(View("Error", error)); } }
public ActionResult CreateSale(IFormCollection collection) { var sale = new Sale { ProductId = Int32.Parse(collection["ProductId"]), SalespersonId = Int32.Parse(collection["SalespersonId"]), CustomerId = Int32.Parse(collection["CustomerId"]), SalesDate = DateTime.Parse(collection["SalesDate"]) }; try { salesService.CreateSale(sale); return(RedirectToAction(nameof(Index))); } catch (Exception e) { var error = new Models.ErrorViewModel(); error.ErrorMessage = "Failure to create sale. Check the database connection or if you are entering valid values."; return(View("Error", error)); } }