コード例 #1
0
        public void Update(UpdateUserCommand user)
        {
            if (string.IsNullOrEmpty(user.Password))
            {
                throw new LogException(LogicExceptionMessage.LoginNameOrPasswordIsNull);
            }
            if (!IsNumAndEnCh(user.Password))
            {
                throw new LogException(LogicExceptionMessage.LoginNameOrPasswordIsAlphabet);
            }
            if (!IsLengthMoreThanSix(user.Password))
            {
                throw new LogException(LogicExceptionMessage.LoginNameOrPasswordLengthMoreThanSix);
            }
            var info = _systemUserRepository.Get(user.Id);

            info.Password = user.Password;
            info.EditUser = LoginUserSection.CurrentUser.LoginName;
            info.EditDate = _currentTimeProvider.CurrentTime();
            _systemUserRepository.Update(info);
        }
コード例 #2
0
 public async Task UpdateAsync(SystemUser user)
 {
     await _usersRepository.Update(user);
 }
コード例 #3
0
        /// <summary>
        /// Edit user profile by ID, if you don't want to change some of the fields just put null there.
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="UserName"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="image"></param>
        /// <param name="moneyToAdd">a delta, can also be negative</param>
        /// <param name="rankToAdd">a delta, can also be negative</param>
        /// <param name="playedAnotherGame"></param>
        /// <returns>true if user has been edited succesfully</returns>
        public bool EditUserById(int Id, string UserName, string password, string email, Image image, int?moneyToAdd, int?rankToAdd, bool playedAnotherGame)
        {
            string imagesDirectory = String.Empty;

            if (image != null)
            {
                string filePath = String.Join("_", Guid.NewGuid(), UserName, "updated");
                imagesDirectory = Path.Combine(Environment.CurrentDirectory, "images", filePath);

                // Save image to disc. (produces error but saves it anyway. we will just wrap it with a 'try' clause.
                try
                {
                    image.Save(imagesDirectory);
                }
                catch
                {
                }
            }

            Database.Domain.SystemUser user = systemUserRepository.GetById(Id);
            if (UserName != null)
            {
                user.UserName = UserName;
            }
            if (password != null)
            {
                user.Salt     = generateSalt();
                user.Password = GetMd5Hash(password + user.Salt);
            }
            if (email != null)
            {
                user.Email = email;
            }
            if (image != null)
            {
                user.Email = email;
            }
            if (image != null)
            {
                user.Image = imagesDirectory;
            }
            if (moneyToAdd != null)
            {
                user.Money = Math.Max(0, user.Money + (int)moneyToAdd);
            }
            if (rankToAdd != null)
            {
                user.Rank = Math.Max(0, user.Rank + (int)rankToAdd);
            }
            if (playedAnotherGame)
            {
                user.GamesPlayed++;
            }

            if (!systemUserRepository.Update(user))
            {
                return(false);
            }

            var updatedUser = databaseSystemUserToBackendSystemUser(systemUserRepository.GetById(Id));

            if (image != null)
            {
                updatedUser.userImageByteArray = imageToByteArray(image);
            }
            systemUserCache.addOrUpdate(updatedUser);

            return(true);

            //SqlConnection connection = new SqlConnection(connectionString);
            //SqlCommand cmd = new SqlCommand();
            //int psikCount = -1 +
            //(UserName == null ? 0 : 1) +
            //(password == null ? 0 : 1) +
            //(email == null ? 0 : 1) +
            //(image == null ? 0 : 1) +
            //(money == null ? 0 : 1) +
            //(rankToAdd == null ? 0 : 1) +
            //(playedAnotherGame ? 1 : 0);

            //cmd.CommandText = "Update SystemUsers SET " +
            //    (UserName == null ? "" : "UserName=@UserName" + (psikCount-- > 0 ? "," : "")) +
            //    (password == null ? "" : "password=HASHBYTES(\'MD5\', CONCAT(@password,@salt)),salt=@salt" + (psikCount-- > 0 ? "," : "")) +
            //    (email == null ? "" : "email=@email" + (psikCount-- > 0 ? "," : "")) +
            //    (image == null ? "" : "image=@image" + (psikCount-- > 0 ? "," : "")) +
            //    (money == null ? "" : "money=money+@money" + (psikCount-- > 0 ? "," : "")) +
            //    (rankToAdd == null ? "" : "rank=(CASE WHEN rank+@rankToAdd > 0 THEN rank+@rankToAdd ELSE 0 END)" + (psikCount-- > 0 ? "," : "")) +
            //    (!playedAnotherGame ? "" : "gamesPlayed=gamesPlayed+1") +
            //     " WHERE Id=@Id";
            //cmd.CommandType = CommandType.Text;
            //cmd.Connection = connection;
            //cmd.Parameters.AddWithValue("@Id", Id);
            //if (UserName != null) cmd.Parameters.AddWithValue("@UserName", UserName);
            //if (password != null) cmd.Parameters.AddWithValue("@password", password);
            //if (email != null) cmd.Parameters.AddWithValue("@email", email);
            //if (image != null) cmd.Parameters.AddWithValue("@image", image);
            //if (password != null) cmd.Parameters.AddWithValue("@salt", getRandomSalt());
            //if (money != null) cmd.Parameters.AddWithValue("@money", money);
            //if (rankToAdd != null) cmd.Parameters.AddWithValue("@rankToAdd", rankToAdd);


            //connection.Open();
            //bool ans = cmd.ExecuteNonQuery() > 0;
            //connection.Close();
            //return ans;
        }
コード例 #4
0
ファイル: SystemUserService.cs プロジェクト: zzdxpq007/xms
 public bool Update(SystemUser entity)
 {
     return(_repository.Update(entity));
 }
コード例 #5
0
 public async Task Update(SystemUser systemUser)
 {
     await _systemUserRepository.Update(systemUser);
 }