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)); } }