Exemple #1
0
        public async Task UpdateContact(ContactDto contactDto)
        {
            var contact = ContactMapper.FromDto(contactDto);

            // check organisation exists
            contact.Organisation = await _unitOfWork.OrganisationRepository.GetByIdAsync(contactDto.OrganisationId)
                                   ?? throw new EntityNotFoundException($"organisation with id <{contactDto.OrganisationId}> not found");;

            _unitOfWork.ContactRepository.Update(contact);
            await _unitOfWork.SaveAsync();
        }
Exemple #2
0
        public async Task <int> CreateContact(ContactDto contactDto)
        {
            var contact = ContactMapper.FromDto(contactDto);

            contact.Organisation = await _unitOfWork.OrganisationRepository.GetByIdAsync(contact.OrganisationId);

            if (contact.Organisation == null)
            {
                throw new EntityNotFoundException($"organisation with id <{contact.OrganisationId}> not found");
            }

            await _unitOfWork.ContactRepository.InsertAsync(contact);

            await _unitOfWork.SaveAsync();

            return(contact.Id);
        }