Пример #1
0
        public async Task <EntryResponse> SaveAsync(Entry entry)
        {
            try
            {
                var existingPhonebook = await _phonebookRepository.FindByIdAsync(entry.PhoneBookId);

                if (existingPhonebook == null)
                {
                    return(new EntryResponse("Invalid phonebook."));
                }

                await _entryRepository.AddAsync(entry);

                await _unitOfWork.CompleteAsync();

                return(new EntryResponse(entry));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new EntryResponse($"An error occurred when saving the entry: {ex.Message}"));
            }
        }
Пример #2
0
        public async Task <PhoneBookResponse> UpdateAsync(int id, PhoneBook phonebook)
        {
            var existingPhonebook = await _phonebookRepository.FindByIdAsync(id);

            if (existingPhonebook == null)
            {
                return(new PhoneBookResponse("PhoneBook not found."));
            }

            existingPhonebook.PhoneBookName = phonebook.PhoneBookName;

            try
            {
                _phonebookRepository.Update(existingPhonebook);
                await _unitOfWork.CompleteAsync();

                return(new PhoneBookResponse(existingPhonebook));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new PhoneBookResponse($"An error occurred when updating the phonebook: {ex.Message}"));
            }
        }