public async Task <IActionResult> PutContactInfoDAO(long id, ContactInfoRequest contactInfoRequest) { if (!ModelState.IsValid) { return(BadRequest()); } if (!ContactInfoDAOExists(id)) { return(NotFound()); } ContactInfoDAO contactInfoDAO = await _context.ContactInfoDAO.FindAsync(id); ContactInfoConverter.RequestToExistingDAO(contactInfoRequest, contactInfoDAO); _context.Entry(contactInfoDAO).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(StatusCode(500)); } return(NoContent()); }
public async Task <ActionResult <ContactInfoResponse> > GetContactInfoDAO(long id) { var contactInfoDAO = await _context.ContactInfoDAO.FindAsync(id); if (contactInfoDAO == null) { return(NotFound()); } return(Ok(ContactInfoConverter.DAOToResponse(contactInfoDAO))); }
public async Task <ActionResult <IEnumerable <ContactInfoResponse> > > GetContactInfoDAO() { List <ContactInfoDAO> contactInfos = await _context.ContactInfoDAO.ToListAsync(); List <ContactInfoResponse> responseContacts = new List <ContactInfoResponse>(); foreach (ContactInfoDAO contact in contactInfos) { responseContacts.Add(ContactInfoConverter.DAOToResponse(contact)); } return(Ok(responseContacts)); }
public async Task <ActionResult <ContactInfoDAO> > PostContactInfoDAO(ContactInfoRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } ContactInfoDAO contactInfoDAO = ContactInfoConverter.RequestToDAO(request); _context.ContactInfoDAO.Add(contactInfoDAO); await _context.SaveChangesAsync(); return(CreatedAtAction("GetContactInfoDAO", new { id = contactInfoDAO.ContactInfoId }, contactInfoDAO)); }