public async Task <PhotoContract> PutAsync(PhotoContract photo) { try { _telemetryClient.TrackEvent("Auth: PhotoController PutAsync invoked"); var registrationReference = await ValidateAndReturnCurrentUserId(); if (!await _photoValidation.IsUserPhotoOwner(registrationReference, photo.Id)) { throw ServiceExceptions.NotAllowed(); } return(await _repository.UpdatePhoto(photo)); } catch (DataLayerException ex) { _telemetryClient.TrackException(ex); if (ex.Error == DataLayerError.Unknown) { throw ServiceExceptions.UnknownInternalFailureException(ServiceExceptions.Source); } throw ServiceExceptions.DataLayerException(ex.Message); } }
public async Task <UserContract> UpdateUserProfile(UserContract user) { try { _telemetryClient.TrackEvent("UserController UpdateUserProfile invoked"); var currentUserId = await ValidateAndReturnCurrentUserId(); if (!currentUserId.Equals(user.RegistrationReference)) { throw ServiceExceptions.NotAllowed(); } var existingUser = await _repository.UpdateUser(user); return(existingUser); } catch (DataLayerException ex) { _telemetryClient.TrackException(ex); if (ex.Error == DataLayerError.Unknown) { throw ServiceExceptions.UnknownInternalFailureException(ServiceExceptions.Source); } throw ServiceExceptions.DataLayerException(ex.Message); } }
public async Task <UserContract> UpdateUserProfile(UserContract user) { try { _telemetryClient.TrackEvent("UserController UpdateUserProfile invoked"); var currentUserId = await ValidateAndReturnCurrentUserId(); // A user should only be able to update his/her own profile. if (!currentUserId.Equals(user.RegistrationReference)) { throw ServiceExceptions.NotAllowed(); } // Check if the user owns the photo that is passed in as profile photo var photo = await _repository.GetPhoto(user.ProfilePhotoId); if (!photo.User.UserId.Equals(user.UserId)) { throw ServiceExceptions.NotAllowed(); } // Refreshing profile photo url user.ProfilePhotoUrl = photo.ThumbnailUrl; var existingUser = await _repository.UpdateUser(user); return(existingUser); } catch (DataLayerException ex) { _telemetryClient.TrackException(ex); if (ex.Error == DataLayerError.Unknown) { throw ServiceExceptions.UnknownInternalFailureException(ServiceExceptions.Source); } throw ServiceExceptions.DataLayerException(ex.Message); } }