public async Task <long> Handle(CreatePhoneBook request, CancellationToken cancellationToken) { var phoneBookEntity = new Phonebook.Model.Entities.PhoneBook { Name = request.Name }; _phoneBookContext.Phonebooks.Add(phoneBookEntity); await _phoneBookContext.SavePhonebookChangesAsync(cancellationToken); return(phoneBookEntity.Id); }
public async Task <Unit> Handle(DeletePhoneBook request, CancellationToken cancellationToken) { var phoneBookEntity = await _phoneBookContext.Phonebooks.FindAsync(request.Id); if (phoneBookEntity == null) { throw new Exception($"Entity \"{nameof(Phonebook)}\" {request.Id} was not found."); } _phoneBookContext.Phonebooks.Remove(phoneBookEntity); await _phoneBookContext.SavePhonebookChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <long> Handle(CreatePhoneBookEntry request, CancellationToken cancellationToken) { var entryEntity = new Model.Entities.PhoneBookEntry { Name = request.Name, PhoneNumber = request.PhoneNumber, PhoneBookId = request.PhonebookId }; _phoneBookContext.PhoneBookEntries.Add(entryEntity); await _phoneBookContext.SavePhonebookChangesAsync(cancellationToken); return(entryEntity.Id); }
public async Task <Unit> Handle(UpdatePhoneBookEntry request, CancellationToken cancellationToken) { var entryEntity = await _phoneBookContext.PhoneBookEntries.FindAsync(request.Id); if (entryEntity == null) { throw new Exception($"Entity \"{nameof(PhoneBookEntry)}\" {request.Id} was not found."); } entryEntity.Name = request.Name; entryEntity.PhoneBookId = request.PhonebookId; entryEntity.PhoneNumber = request.PhoneNumber; await _phoneBookContext.SavePhonebookChangesAsync(cancellationToken); return(Unit.Value); }