public ActionResult Edit([Bind(Include = "Id,AccountName,BranchId")] EditGlAccountViewModel model, string BranchId) { ViewBag.BranchId = new SelectList(branchRepo.GetAll(), "ID", "Name", model.BranchId); if (ModelState.IsValid) { try { var glaccount = glactRepo.GetById(model.Id); //check for unique name string originalName = glaccount.AccountName; if (!model.AccountName.ToLower().Equals(originalName.ToLower())) //glCategory name has been changed during editting, so check if the new name doesnt exist already { if (!gllogic.IsUniqueName(model.AccountName)) { ViewBag.Msg = "Please select another name"; return(View()); } } var branch = branchRepo.GetById(model.BranchId); if (branch == null) { ViewBag.Msg = "Please select a branch"; return(View(model)); } glaccount.AccountName = model.AccountName; glaccount.Branch = branch; glactRepo.Update(glaccount); ViewBag.Msg = "Data updatded successfully!"; return(View()); } catch (Exception ex) { //ErrorLogger.Log("Message= " + ex.Message + "\nInner Exception= " + ex.InnerException + "\n"); return(PartialView("Error")); } } ViewBag.Msg = "Please enter correct data"; return(View(model)); }
// GET: /GlAccount/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GlAccount glaccount = glactRepo.GetById((int)id); if (glaccount == null) { return(HttpNotFound()); } var model = new EditGlAccountViewModel(); model.Id = glaccount.ID; model.AccountName = glaccount.AccountName; model.BranchId = glaccount.Branch.ID; ViewBag.Msg = ""; ViewBag.BranchId = new SelectList(branchRepo.GetAll(), "ID", "Name", glaccount.Branch.ID); return(View(model)); }