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)); } }
public async Task<UpdatePerItemModel> UpdateUserInfoItemAsync(ClaimsPrincipal claimsPrincipal, [Service] IUserResolver userResolver, UpdatePerItemModel criterias) { return await userResolver.UpdateUserInfoItemAsync(claimsPrincipal, criterias); }
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; } }