Exemplo n.º 1
0
        public ActionResult Add(AdminUserAddNewModel 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 = "该手机号已被注册"
                }));
            }
            //发现在service里面也判断了一次手机是否注册,感觉越早判断越好,service那个就没必要了
            //TODO:这里应该用事务
            long adminUserId = AdminUserService.AddAdminUser(model.Name, model.PhoneNum, model.PassWord, model.Email, model.CityId);

            RoleService.AddRoleIds(adminUserId, model.RoleIds);

            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }
Exemplo n.º 2
0
        public ActionResult Add(AdminUserAddNewModel adminUser)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    Msg = Web.Common.WebCommonHelper.GetValidMsg(ModelState)
                }));
            }
            // todo 检查用户名,手机号是否重复
            adminUser.CityId = adminUser.CityId > 0 ? adminUser.CityId : null;
            long adminUserId = AdminUserService.AddAdminUser(adminUser.Name, adminUser.PhoneNum, adminUser.Password, adminUser.Email,
                                                             adminUser.CityId);

            RoleService.AddRoleIds(adminUserId, adminUser.RoleIds);
            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }