Example #1
0
        public async Task <ActionResult <ContactDto> > PostContact(ContactEntry contact)
        {
            try
            {
                if (contact == null)
                {
                    return(BadRequest());
                }

                Contact contactFromRepo = _mapper.Map <Contact>(contact);

                _repository.AddContact(contactFromRepo);

                await _repository.SaveAsync();

                Contact postedContact = await _repository.FindAsync(contactFromRepo.ContactPhones.First().ContactId);

                ContactDto contactDto = _mapper.Map <ContactDto>(postedContact);

                return(CreatedAtAction("GetContact", new { id = contactDto.ContactId }, contactDto));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }