public async Task RemovePhotosAsync(Guid remarkId, params string[] names) { if (names == null || !names.Any()) { throw new ServiceException(OperationCodes.NoFiles, $"There are no photos to be removed from the remark with id: '{remarkId}'."); } var remark = await _remarkRepository.GetOrFailAsync(remarkId); Logger.Debug($"Removing {names.Count()} photos from the remark with id: '{remarkId}'."); foreach (var name in names) { if (remark.GetPhoto(name).HasNoValue) { throw new ServiceException(OperationCodes.FileNotFound, $"Remark photo with name: '{name}' was not found in the remark with id: '{remarkId}'."); } remark.RemovePhoto(name); } await _remarkRepository.UpdateAsync(remark); var tasks = new List <Task>(); foreach (var photo in names) { var task = _fileHandler.DeleteAsync(photo); tasks.Add(task); } await Task.WhenAll(tasks); Logger.Debug($"Removed {names.Count()} photos from the remark with id: '{remarkId}'."); }
private async Task RemoveAsync(Maybe <User> user, string userId) { if (user.HasNoValue) { throw new ServiceException(OperationCodes.UserNotFound, $"User with id: '{userId}' has not been found."); } if (user.Value.Avatar == null) { return; } if (user.Value.Avatar.IsEmpty) { return; } await _fileHandler.DeleteAsync(user.Value.Avatar.Name); user.Value.RemoveAvatar(); }
private async Task RemoveAsync(User user, Guid userId) { if (user.HasNoValue()) { throw new ServiceException(Codes.UserNotFound, $"User with id: '{userId}' has not been found."); } if (user.Avatar.HasNoValue()) { return; } if (user.Avatar.IsEmpty) { return; } await _fileHandler.DeleteAsync(user.Avatar.Name); user.RemoveAvatar(); }