예제 #1
0
            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);
            }
예제 #2
0
            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);
            }
예제 #3
0
            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);
            }
예제 #4
0
            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);
            }