Esempio n. 1
0
        public ActionResult Add(UserEditInfo user)
        {
            try
            {
                string       partialPath = CustomerEnumDesc.GetResxTypePath(ResxType.UserHeadImage);
                ImageHandler resx        = new ImageHandler
                {
                    ResxTypes          = ResxConfigManager.IMAGE_FILE_TYPES,
                    ResxSize           = ResxConfigManager.IMAGE_MAX_SIZE,
                    IsThumbnail        = false,
                    SaveLocalDirectory = string.Format("{0}{1}", AppConfigManager.UploadDirectory, partialPath),
                    AccessUrl          = string.Format("{0}{1}", ResxConfigManager.FileAccessUrl, partialPath)
                };
                ResxImageResult result = resx.Upload(Request.Form.Files.FirstOrDefault());
                if (!result.Success)
                {
                    return(Json(new { state = -1, error = result.Message }));
                }
                else
                {
                    user.HeadImage = result.ResxAccessUrl;
                }

                int userId = userService.AddUser(user);
                if (userId <= 0)
                {
                    return(Json(new { state = -1, error = "Create user failed." }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { state = -1, error = ex.Message }));
            }
            return(Json(new { state = 1 }));
        }
Esempio n. 2
0
 /// <summary>
 /// 获取用户的单条信息
 /// </summary>
 /// <param name="uid"></param>
 /// <returns></returns>
 public UserEditInfo EditUser(int uid)
 {
     using (IDbConnection conn = new SqlConnection(connStr))
     {
         UserEditInfo info = new UserEditInfo();
         string       sql  = @"SELECT u.UserName,u.Email,a.AddressId,ro.RoleId FROM dbo.UserInfo u
                             JOIN dbo.UserAddressMapInfo ua ON ua.UserId = u.UserId
                             JOIN dbo.AddressInfo a ON a.AddressId = ua.AddressId
                             JOIN dbo.UserRoleMapInfo r ON r.UserId = u.UserId
                             JOIN dbo.RoleInfo ro ON ro.RoleId = r.RoleId where u.UserId=@id";
         info = conn.QueryFirstOrDefault <UserEditInfo>(sql, new { id = uid });
         return(info);
     }
 }
Esempio n. 3
0
        public int AddUser(UserEditInfo user)
        {
            #region check user
            if (user == null)
            {
                throw new Exception("用户数据不能为空.");
            }

            if (string.IsNullOrEmpty(user.Email) && string.IsNullOrEmpty(user.Mobile))
            {
                throw new Exception("手机或者邮箱不能为空");
            }
            if (string.IsNullOrEmpty(user.Password))
            {
                throw new Exception("密码不能为空");
            }
            if (string.IsNullOrEmpty(user.PasswordOK))
            {
                throw new Exception("密码确认不能为空");
            }
            if (user.PasswordOK.Trim() != user.Password.Trim())
            {
                throw new Exception("两次密码输入不一致");
            }
            #endregion

            IQueryable <t_user> query = db.t_user;
            if (!string.IsNullOrEmpty(user.Mobile))
            {
                query = query.Where(u => u.mobile == user.Mobile);
            }
            else
            {
                query = query.Where(u => u.email == user.Email);
            }

            if (query.Count() >= 1)
            {
                throw new Exception("该帐号已经被注册");
            }

            t_user model = new t_user()
            {
                email      = user.Email ?? "",
                mobile     = user.Mobile ?? "",
                password   = user.PasswordOK,
                name       = string.IsNullOrEmpty(user.Name) ? $"{AppConfigManager.DefaultEAppName}-{RandomText.GetNum()}" : user.Name,
                life_notes = user.LifeNotes,
                head_image = string.IsNullOrEmpty(user.HeadImage) ? AppConfigManager.UserDefaultHeadImage : user.HeadImage,

                source            = UserSource.System,
                status            = UserStatus.Normal,
                sex               = UserSex.Unknow,
                register_date     = DateTime.Now,
                update_date       = DateTime.Now,
                circle_back_image = AppConfigManager.UserCircleBackImage,
            };
            db.t_user.Add(model);
            db.SaveChanges();

            return(model.id);
        }