public ActionResult Create([ModelBinder(typeof(DevExpressEditorsBinder))] HovisMillingPortal.Models.t_Milling_Bacs_Customers item) { if (item.CustomerNo == null || item.CustomerNo == "") { ModelState.AddModelError("CustomerNo", "Customer No cannot be blank"); } if (item.SortingCode == null || item.SortingCode == "") { ModelState.AddModelError("SortingCode", "Customers Bank Sort code cannot be blank"); } if (item.BankAccountNo == null || item.BankAccountNo == "") { ModelState.AddModelError("BankAccountNo", "Customers Bank Account No cannot be blank"); } if (item.BankAccountName == null || item.BankAccountName == "") { ModelState.AddModelError("BankAccountName", "Customers Bank Account Name cannot be blank"); } if (item.DDFrequency == null) { ModelState.AddModelError("DDFrequency", "You must choose a Frequency"); } if (item.NewBankMandate == null) { ModelState.AddModelError("NewBankMandate", "You must choose a Bank Mandate"); } if (item.FirstClaim == null) { ModelState.AddModelError("FirstClaim", "You must enter a number"); } if (item.FirstClaim == null) { ModelState.AddModelError("SecondClaim", "You must enter a number"); } var model = db.t_Milling_Bacs_Customers; if (ModelState.IsValid) { try { model.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } ViewBag.Status = new SelectList(db.t_Milling_Bacs_Status, "StatusRecid", "StatusDesc"); ViewBag.DDFrequency = new SelectList(db.t_Milling_Bacs_DDFrequency, "DDFreqRecid", "DDFreqDesc"); ViewBag.NewBankMandate = new SelectList(db.t_Milling_Bacs_NewBankMandate, "MandateRecid", "MandateDesc"); return(View(item)); }
public ActionResult Edit([ModelBinder(typeof(DevExpressEditorsBinder))] HovisMillingPortal.Models.t_Milling_Bacs_Customers item) { var britishZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); var adjusteddate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, britishZone); var model = db.t_Milling_Bacs_Customers; if (item.CustomerNo == null || item.CustomerNo == "") { ModelState.AddModelError("CustomerNo", "Customer No cannot be blank"); } if (item.SortingCode == null || item.SortingCode == "") { ModelState.AddModelError("SortingCode", "Customers Bank Sort code cannot be blank"); } if (item.BankAccountNo == null || item.BankAccountNo == "") { ModelState.AddModelError("BankAccountNo", "Customers Bank Account No cannot be blank"); } if (item.BankAccountName == null || item.BankAccountName == "") { ModelState.AddModelError("BankAccountName", "Customers Bank Account Name cannot be blank"); } if (item.DDFrequency == null) { ModelState.AddModelError("DDFrequency", "You must choose a Frequency"); } if (item.NewBankMandate == null) { ModelState.AddModelError("NewBankMandate", "You must choose a Bank Mandate"); } if (item.FirstClaim == null) { ModelState.AddModelError("FirstClaim", "You must enter a number"); } if (item.FirstClaim == null) { ModelState.AddModelError("SecondClaim", "You must enter a number"); } if (ModelState.IsValid) { if (User.Identity.Name != null) { item.LastChangedBy = User.Identity.Name; item.LastChangedDate = adjusteddate; } try { var modelItem = model.FirstOrDefault(it => it.CustomerRecid == item.CustomerRecid); if (modelItem != null) { this.UpdateModel(modelItem); db.SaveChanges(); return(RedirectToAction("Index", db.t_Milling_Bacs_Customers.ToList())); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } ViewBag.Status = new SelectList(db.t_Milling_Bacs_Status, "StatusRecid", "StatusDesc"); ViewBag.DDFrequency = new SelectList(db.t_Milling_Bacs_DDFrequency, "DDFreqRecid", "DDFreqDesc"); ViewBag.NewBankMandate = new SelectList(db.t_Milling_Bacs_NewBankMandate, "MandateRecid", "MandateDesc"); return(View(item)); }