示例#1
0
        public async Task <UserDetailsModel> SetUserDetails(UserDetailsModel model)
        {
            var user = await GetUser(model.UserId, model);

            if (user == null)
            {
                return(LogErrorReturnModel(model));
            }

            //TODO Check this is not a bug, as cannot update username at the moment (overwritten be stored username)
            // Leave a comment to say this is intentional if it is.
            model.Username = user.UserName;

            var setPhoneNumber = await _userManager.SetPhoneNumberAsync(user, model.PhoneNumber);

            if (!setPhoneNumber.Succeeded)
            {
                model.Errors = setPhoneNumber.Errors.ToList();
                LogErrors(model, "Failed to set phone number");
            }

            try
            {
                await _usersData.UpdateUser(new UserModel { Id = model.UserId, DisplayName = model.DisplayName });
            }
            catch (Exception e)
            {
                model.Errors.Add(Error($"Error when saving custom User Settings. Message: {e.Message}"));
                LogErrors(model, "Failed to set custom settings");
            }

            return(model);
        }