Exemplo n.º 1
0
        public ActionResult Update(RoleEditModel model)
        {
            if (model == null || model.Role == null)
                throw new ArgumentNullException("the model is null!!!");

            ReadOnlyCollection<BrokenRule> brokenRules = model.Role.GetBrokenRules();

            if (brokenRules.Count > 0)
            {
                TempData["InvalidModel"] = model;
                TempData["BrokenRules"] = brokenRules;
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = String.Format("角色({0})修改失败,请检查你的输入", model.Role.Name) };
            }
            else
            {
                repository[model.Role.Key] = model.Role;
                unitOfWork.Commit();
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = String.Format("人员({0})修改成功", model.Role.Name) };
            }
            return this.RedirectToAction("Edit", new { id = model.Role.Key });
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            Role role = null;

            if (TempData["HintMessage"] != null)
            {
                ViewData["HintMessage"] = TempData["HintMessage"];
            }
            if (TempData["InvalidModel"] != null && TempData["BrokenRules"] != null)
            {
                role = TempData["InvalidModel"] as Role;
            }

            if (role == null)
            {
                role = this.repository.FindBy(id);

                if (role == null)
                    throw new HttpException(404, "无法找到角色!!");
            }
            else
            {
                ViewData["BrokenRules"] = TempData["BrokenRules"];
            }

            RoleEditModel model = new RoleEditModel(role);

            return View(model);
        }