public ActionResult Edit(int id, EditAdminUserModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = FindUser(id);
                    if (user != null)
                    {
                        user.Email  = model.Email;
                        user.RoleId = model.RoleId;
                        if (!String.IsNullOrWhiteSpace(model.Password))
                        {
                            user.ChangePassword(model.Password);
                        }
                        SaveChanges();

                        ShowSuccess(MessageResource.UpdateSuccess);
                    }

                    return(RedirectToIndex());
                }
                catch (Exception ex)
                {
                    LogError(ex.ToString());
                    ShowError(MessageResource.UpdateFailed);
                }
            }

            return(View(model));
        }
예제 #2
0
        public ActionResult Edit(EditAdminUserModel model)
        {
            if (model.Id <= 0)
            {
                return(Json(new AjaxResult {
                    Status = "0", ErrorMsg = "参数错误"
                }));
            }
            if (string.IsNullOrEmpty(model.RoleName))
            {
                return(Json(new AjaxResult {
                    Status = "0", ErrorMsg = "请选择所属市级"
                }));
            }
            List <long> lists = new List <long>();

            for (int i = 0; i < model.PermissionIds.Length; i++)
            {
                if (model.PermissionIds[i] == 0)
                {
                    continue;
                }
                lists.Add(model.PermissionIds[i]);
            }
            string description = roleService.GetByName(model.RoleName).Description;
            bool   b           = adminService.Update(model.Id, model.RoleName, description, lists);

            if (!b)
            {
                return(Json(new AjaxResult {
                    Status = "0", ErrorMsg = "编辑管理员用户失败"
                }));
            }
            return(Json(new AjaxResult {
                Status = "1"
            }));
        }