public async Task HandleAsync(UpdatePhoneBook command)
        {
            var entity = await _repository.GetById(command.Id);

            _mapper.Map(command, entity);
            await _repository.Update(entity);
        }
Exemplo n.º 2
0
        public async Task AddEntry(PhoneBookEntry entry)
        {
            var existingEntry = await phoneBookRepository.GetById(entry.Name.Trim());

            if (existingEntry != null)
            {
                throw new ApplicationException("An entry with the same name already exists in this phone book. Please use another name or update the existing entry.");
            }

            var phoneBook = new PhoneBook();

            phoneBook.AddEntry(entry);

            await phoneBookRepository.AddEntry(entry);
        }
        public async Task <PhoneBookViewModel> HandleAsync(GetPhoneBook query)
        {
            if (query.Id == default)
            {
                throw new PhoneBookException("undefined id of phonebook");
            }

            var entity = await _repository.GetById(query.Id);

            var model = new PhoneBookViewModel {
                Id = entity.Id, Name = entity.Name, Phone = entity.Phone
            };

            return(model);
        }
Exemplo n.º 4
0
 public PhoneBook GetById(int Id)
 {
     return(_phonebookRepository.GetById(Id));
 }