public ActionResult Create(BankCreateForHttpPost newItem, FormCollection form) { if (ModelState.IsValid) { try { var createdBank = repo.createBank(newItem); bankToCreate.Clear(); if (createdBank == null) { return View("Error", vme.GetErrorModel(ModelState)); } else { return RedirectToAction("Details", new { Id = createdBank.Id }); } } catch (System.Exception ex) { ModelState.AddModelError("Exception Message", ex.Message); bankToCreate.Clear(); return View("Error", vme.GetErrorModel(ModelState)); } } // No. So report and send back to user to re-enter else { bankToCreate.Name = newItem.Name; bankToCreate.Code = newItem.Code; return View(bankToCreate); } }
public Bank createBank(BankCreateForHttpPost cp) { var c = new Bank(); c.Id = dc.Banks.Max(n => n.Id) + 1; c.Name = cp.Name; c.Code = cp.Code; dc.Banks.Add(c); dc.SaveChanges(); return getBank(c.Id); }