public async Task HandleAsync(UpdateEntryCommand command) { var phoneBook = await _phoneBookRepository.GetPhoneBookByIdAsync(command.PhoneBookId); phoneBook.UpdateEntry(command.EntryId, command.Name, command.PhoneNumber); _phoneBookRepository.Update(phoneBook); await _phoneBookRepository.SaveAsync(); }
public async Task HandleAsync(InsertEntryCommand command) { var phoneBook = await _phoneBookRepository.GetPhoneBookByIdAsync(command.PhoneBookId); if (phoneBook.Entries.Where(a => a.Name == command.Name && a.PhoneNumber == command.PhoneNumber).Any()) { throw new ValidateException("Phone book entry already exists"); } phoneBook.InsertEntry(command.Name, command.PhoneNumber); _phoneBookRepository.Update(phoneBook); await _phoneBookRepository.SaveAsync(); }