public ActionResult EditBranch(int id) { Branch branch = orderUow.Branches.GetById(id); EditBranchViewModel editBranchViewModel = new EditBranchViewModel { BranchCode = branch.BranchCode, BranchName = branch.BranchName, UserName = branch.Username, Id = branch.Id }; return View(editBranchViewModel); }
public ActionResult EditBranch(EditBranchViewModel model) { if (ModelState.IsValid) { // Attempt to register the user try { Branch branch = orderUow.Branches.GetById(model.Id); if(branch == null) throw new ApplicationException("Branch " + model.BranchName + " not found"); WebSecurity.ChangePassword(branch.Username, model.Password, model.Password); branch.BranchCode = model.BranchCode; branch.BranchName = model.BranchName; orderUow.Branches.Update(branch); orderUow.Commit(); return RedirectToAction("Index", "Branch"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", AccountController.ErrorCodeToString(e.StatusCode)); } catch (Exception ex) { ModelState.AddModelError("", ex.GetInnerMostException()); } } // If we got this far, something failed, redisplay form return View(model); }