Ejemplo n.º 1
0
        public ActionResult Edit(AdminUserEditModel model)
        {
            //修改的时候密码为空表示不修改,这样的话属性验证过不了,直接去掉这个了
            //if (!ModelState.IsValid)
            //{
            //    return Json(new AjaxResult() { Status = "error", ErrorMsg = MVCHelper.GetValidMesg(ModelState) });
            //}

            var user = AdminUserService.GetByPhoneNum(model.PhoneNum);

            if (user == null)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "该手机号不存在"
                }));
            }
            //TODO:这里应该用事务
            AdminUserService.UpdateAdminUser(user.Id, model.Name, model.PhoneNum, model.PassWord, model.Email, model.CityId);
            RoleService.UpdateRoleIds(user.Id, model.RoleIds);

            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(AdminUserEditModel AdminUser)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    Msg = Web.Common.WebCommonHelper.GetValidMsg(ModelState)
                }));
            }
            if (string.IsNullOrEmpty(AdminUser.Password))
            {
                AdminUserService.UpdateAdminUser(AdminUser.Id, AdminUser.Name, AdminUser.PhoneNum, AdminUser.Email, AdminUser.CityId);
            }
            else
            {
                AdminUserService.UpdateAdminUser(AdminUser.Id, AdminUser.Name, AdminUser.PhoneNum, AdminUser.Password, AdminUser.Email, AdminUser.CityId);
            }

            RoleService.UpdateRoleIds(AdminUser.Id, AdminUser.RoleIds);

            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }
Ejemplo n.º 3
0
 public ActionResult EditAdmin(EditAdminPost editModel)
 {
     //更新用户表
     //更新用户角色表
     if (ModelState.IsValid)
     {
         //如果密码什么都没写,则不更新密码,否则就更新密码
         //注意此处的细节,前端如果密码都没填写,那么可以向后端发请求(留空不修改密码),如果前端的密码和确认密码不一致,那么就不能往后端发请求,前端注意这个细节!
         AdminUserService.UpdateAdminUser(editModel.Id, editModel.Name, editModel.PhoneNum, editModel.Pwd);
         //更新用户角色关系表...
         RoleService.UpdateRoleIds(editModel.Id, editModel.RoleIds);
         return(Json(new AjaxResult()
         {
             Status = "ok"
         }));
     }
     else
     {
         string errorMsg = CommonHelper.GetValidMsg(ModelState);//验证具体的错误信息
         return(Json(new AjaxResult()
         {
             Status = "no", ErrorMsg = errorMsg
         }));
     }
 }
Ejemplo n.º 4
0
 public ActionResult Edit(AdminUserEditModel model)
 {
     AdminUserService.UpdateAdminUser(model.Id, model.Name, model.PhoneNum, model.Password, model.Email, model.CityId == 0?null: model.CityId);
     RoleService.UpdateRoleIds(model.Id, model.RoleIds);
     return(Json(new AjaxResult {
         Status = "ok"
     }));
 }
Ejemplo n.º 5
0
 public void TestAdminUser()
 {
     long id = userService.AddAdminUser("abc", "13132131131", "123456", "*****@*****.**", null);
     var user= userService.GetById(id);
     Assert.AreEqual(user.Name, "abc");
     Assert.AreEqual(user.PhoneNum, "13132131131");
     Assert.AreEqual(user.Email, "*****@*****.**");
     Assert.IsNull(user.CityId);
     Assert.IsTrue(userService.CheckLogin("13132131131", "123456"));
     Assert.IsFalse(userService.CheckLogin("13132131131", "324"));
     userService.GetAll();
     Assert.IsNull(userService.GetByPhoneNum("2325252"));
     userService.GetAll(1);
     userService.UpdateAdminUser(id, "bbc", "*****@*****.**", null);
     userService.MarkDeleted(id);
 }
        public ActionResult Edit(AdminUserEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult <object>
                {
                    code = 1,
                    msg = CommonHelper.GetValidMsg(ModelState)
                }));
            }
            try
            {
                using (TransactionScope sc = new TransactionScope())
                {
                    long?cityId = null;
                    if (model.CityId != 0)
                    {
                        cityId = model.CityId;
                    }
                    AdminUserService.UpdateAdminUser(model.Id, model.Name, model.PhoneNum, model.Password, model.Email, cityId);
                    AdminUserService.AddAdminUserRole(model.Id, model.RoleIds);

                    sc.Complete();
                    sc.Dispose();
                }
                return(Json(new AjaxResult <object>
                {
                    code = 0,
                    msg = "编辑成功"
                }));
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("编辑管理员用户失败:{0}", ex.Message);
                return(Json(new AjaxResult <object>
                {
                    code = 1,
                    msg = ex.Message
                }));
            }
        }
Ejemplo n.º 7
0
        public ActionResult Edit(AdminUserEditPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }
            long?cityId = null;

            if (model.CityId != 0)
            {
                cityId = model.CityId;
            }

            AdminUserService.UpdateAdminUser(model.Id, model.Name, model.PhoneNum, model.Password, model.Email, cityId);

            RoleService.UpdateRoleIds(model.Id, model.RoleIds);
            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }