Exemple #1
0
        private void ValidateUserInfoItem(UpdatePerItemModel criterias)
        {
            if (!criterias.CanEdit)
            {
                throw new UnauthorizedAccessException();
            }

            if (criterias.PropertyName == null)
            {
                throw new ArgumentException(nameof(criterias.PropertyName));
            }

            if (criterias.Key == null || string.IsNullOrEmpty(criterias.Key.ToString()))
            {
                throw new ArgumentException(nameof(criterias.Key));
            }
        }
Exemple #2
0
 public async Task<UpdatePerItemModel> UpdateUserInfoItemAsync(ClaimsPrincipal claimsPrincipal, [Service] IUserResolver userResolver, UpdatePerItemModel criterias)
 {
     return await userResolver.UpdateUserInfoItemAsync(claimsPrincipal, criterias);
 }
Exemple #3
0
        public async Task <UpdatePerItemModel> UpdateUserInfoItemAsync(ClaimsPrincipal claimsPrincipal, UpdatePerItemModel criterias)
        {
            try
            {
                ValidateUserInfoItem(criterias);
                var currentUserId = GetCurrentUserId(claimsPrincipal);
                var userId        = await _userManager.DecryptUserIdAsync(criterias.Key.ToString());

                if (userId != currentUserId)
                {
                    throw new UnauthorizedAccessException();
                }

                var updatePerItem = new UpdateItemRequest()
                {
                    Key          = criterias.Key,
                    PropertyName = criterias.PropertyName,
                    Value        = criterias.Value
                };
                updatePerItem.Key = userId;
                var updatedItem = await _userService.UpdateInfoItemAsync(updatePerItem);

                return(new UpdatePerItemModel()
                {
                    Key = updatedItem.Key.ToString(),
                    PropertyName = updatedItem.PropertyName,
                    Value = updatedItem.Value.ToString()
                });
            }
            catch (Exception)
            {
                throw;
            }
        }