コード例 #1
0
ファイル: BranchController.cs プロジェクト: oetawan/orders
        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);
        }
コード例 #2
0
ファイル: BranchController.cs プロジェクト: oetawan/orders
        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);
        }