Exemple #1
0
        private int UpdateUser(UserDto user)
        {
            var usr = _userRepository.GetUser(user.Id);

            usr.Email  = user.Email;
            usr.Phone  = user.Phone;
            usr.Avatar = user.Avatar;
            usr.Name   = user.Name;
            var row = usr.Save();

            if (row > 0)
            {
                if (usr.GetCredential().UserName != user.Credential.UserName)
                {
                    if (_userRepository.GetUserIdByUserName(user.Credential.UserName) > 0)
                    {
                        throw new ArgumentException("用户名已经使用!");
                    }
                }
                user.Credential.UserId = usr.GetAggregaterootId();
                usr.SaveCredential(user.Credential);
            }

            return(row);
        }
Exemple #2
0
        private int CreateUser(UserDto user)
        {
            if (_userRepository.GetUserIdByUserName(user.Credential.UserName) > 0)
            {
                throw new ArgumentException("用户名已经使用!");
            }
            var usr = _userRepository.CreateUser(0, 1);

            usr.Email         = user.Email;
            usr.Phone         = user.Phone;
            usr.Avatar        = user.Avatar;
            usr.Name          = user.Name;
            usr.CreateTime    = DateTime.Now;
            usr.LastLoginTime = usr.CreateTime.AddHours(-1);
            user.CheckCode    = "";
            if (user.Avatar == "" || string.IsNullOrEmpty(usr.Avatar))
            {
                usr.Avatar = "/public/mui/css/latest/avatar.gif";
            }
            if (user.IsMaster)
            {
                usr.Flag = Role.Master.Flag;
            }

            var userId = usr.Save();

            usr = _userRepository.GetUser(userId);
            usr.SaveCredential(new Credential(0, userId, user.Credential.UserName,
                                              user.Credential.Password, user.Credential.Enabled));
            return(userId);
        }
Exemple #3
0
 public int SaveUser(UserDto user)
 {
     if (user.Id > 0)
     {
         return(UpdateUser(user));
     }
     return(CreateUser(user));
 }
Exemple #4
0
        public UserDto GetUser(int id)
        {
            var user = _userRepository.GetUser(id);

            if (user != null)
            {
                var u = UserDto.Convert(user);

                u.Credential = user.GetCredential();
                u.Roles      = user.GetAppRole();
                return(u);
            }

            return(null);
        }