public async Task UpdateLibraryRecordsWithNewBookTitleAsync(string bookId, string newTitle) { var libraryRecords = await allLibraryRecordsQuery.GetResultsAsync(); foreach (var record in libraryRecords) { if (record.Books.Any(a => a.BookId.Value == bookId)) { await libraryRecordRepository.ModifyAsync(record => { record.UpdateBookTitle(bookId, newTitle); }, record.Id); } } }
public async Task Update(UserDetailDTO userDto) { var allRecords = await allLibraryRecordsQuery.GetResultsAsync(); var userHasSomeRecords = allRecords.Any(a => a.User == UserMapper.MapTo(userDto) && !a.IsClosed); await repository.ModifyAsync(user => { if (userDto.IsBanned) { if (userHasSomeRecords) { throw new InvalidOperationException(ErrorMessages.UserCannotBeBanned); } else { user.SetAsBanned(); } } else { user.Unban(); } user.UpdateUser(userDto.Name, userDto.Surname, userDto.Email); }, new UserId(userDto.Id)); }