Example #1
0
        public async Task <DatabaseResponseWithoutData> UpdateCurrentUserAsync(CurrentUserModel user)
        {
            if (user != null)
            {
                if (!user.IsValid())
                {
                    string message = "";
                    user.GetErrorMessages().ForEach(error => message += error);

                    return(new DatabaseResponseWithoutData(false, message));
                }

                var currentUser = await _userRepository.GetUserAsync(user.Id);

                if (currentUser.Password != user.Password)
                {
                    user.Password = PasswordHashingHelper.HashPassword(user.Password);
                }

                var newUser = _databaseMapper.ToUserFrom(user);

                try {
                    await _userRepository.UpdateUserAsync(newUser);
                } catch (SQLiteException sqliteEx) {
                    return(new DatabaseResponseWithoutData(false, sqliteEx.Message));
                } catch (Exception ex) {
                    return(new DatabaseResponseWithoutData(false, ex.Message));
                }

                return(new DatabaseResponseWithoutData(true));
            }

            return(new DatabaseResponseWithoutData(false, ""));
        }