Exemplo n.º 1
0
        public async Task <ServiceResponse <AddPhoneBookEntryResponse> > AddEntry(AddPhoneBookEntryRequest phoneBookEntry, Guid userId)
        {
            var bookEntryRecord = phoneBookEntry.MapGeneric <EntryEntity, AddPhoneBookEntryRequest>();

            bookEntryRecord.PhoneBookId = userId;

            if (await _phoneBookRepository.ExistAsync(phoneBookEntry.Name))
            {
                throw new BadRequestException("Entry already exist");
            }

            await _phoneBookRepository.SaveAsync(bookEntryRecord);

            return(new ServiceResponse <AddPhoneBookEntryResponse>("Successfully added an entry")
            {
                Data = new AddPhoneBookEntryResponse
                {
                    IsAdded = true
                }
            });
        }