Ejemplo n.º 1
0
        public JsonResult AddUser([DataSourceRequest] DataSourceRequest request, UserModel userModel)
        {
            try
            {
                if (userModel != null)
                {
                    this.userService = new UserService();
                    var user = DataTransfer.Transfer<User>(userModel, typeof(UserModel));
                    userModel.ID = this.userService.AddUser(user);
                    if (userModel.ID <= 0)
                    {
                        return this.Json(string.Empty);
                    }

                    userModel.UserLevelName = "普通会员";
                    userModel.StateName = "锁定会员";
                    LogUtils.Log("用户" + this.SystemUserSession.LoginName + "成功添加会员" + userModel.Email, "AddUser", Category.Info, Session.SessionID);
                    return this.Json(new[] { userModel }.ToDataSourceResult(request, this.ModelState));
                }

                return this.Json(string.Empty);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }
        }
Ejemplo n.º 2
0
 public ActionResult AddUser(UserModel userModel)
 {
     try
     {
         var orderService = new OrderService(this.SystemUserSession.EmployeeID);
         var user = new User
                        {
                            UserLevelID = 1,
                            Email = userModel.Email ?? userModel.Mobile,  // 优先使用邮箱作为登录用户名,其次使用手机号。
                            EmailValidate = false,
                            Name = userModel.Name,
                            LoginName = userModel.Email ?? "*****@*****.**", // 后台客户添加用户信息时,若用户没有邮箱,则设置默认值“[email protected]”
                            Mobile = userModel.Mobile,
                            MobileValidate = false,
                            Tel = userModel.Tel,
                            NickName = userModel.Name,
                            Address = userModel.Address,
                            LoginPassword = Encrypt.HashByMD5("123456"),  // 对会员密码进行加密
                            Birthday = null,
                            LastLoginTime = null,
                            Integral = 0,
                            Status = 1,
                            CreateTime = DateTime.Now,
                            CountyID = userModel.CountyID
                        };
         orderService.AddUserInfo(user);
         var addressModel = new UserReceiveAddressModel { CountyID = user.CountyID };
         return
             this.Json(
                 new AjaxResponse(
                     1,
                     new { UserID = user.ID, CountyId = user.CountyID, CountyInfo = addressModel.CountyName }));
         //this.Content(
         //    "{State:'Ok',UserID:'" + user.ID + "',CountyInfo:'" + addressModel.CountyName + "'}");
     }
     catch
     {
         return this.Content("{State:'Error'}");
     }
 }