public IHttpActionResult Delete(int id) { ContactQueries _contactQueries = new ContactQueries(); Contact contact = _contactQueries.GetOneById(id); _contactQueries.Delete(contact); return(Ok()); }
public IHttpActionResult Get(int id) { Contact contact = new Contact(); ContactQueries _contactQueries = new ContactQueries(); contact = _contactQueries.GetOneById(id); ContactModel contactModel = new ContactModel(); contactModel.Id = contact.Id; contactModel.FirstName = contact.FirstName; contactModel.LastName = contact.LastName; contactModel.Email = contact.Email; foreach (var account in contact.Accounts) { AccountDetails accountDetails = new AccountDetails(); accountDetails.Id = account.Id; accountDetails.Name = account.Name; contactModel.Accounts.Add(accountDetails); } return(Ok(contactModel)); }
public IHttpActionResult Put(int id, [FromBody] ContactModel contactModel) { if (ModelState.IsValid) { ContactQueries _contactQueries = new ContactQueries(); Contact contact = _contactQueries.GetOneById(id); contact.FirstName = contactModel.FirstName; contact.LastName = contactModel.LastName; contact.Email = contactModel.Email; contact.DateUpdated = DateTime.Now; foreach (var accountDetails in contactModel.Accounts) { Account account = new Account(); account.Id = accountDetails.Id; account.Name = accountDetails.Name; contact.Accounts.Add(account); } _contactQueries.Save(contact); } return(Ok()); }