public async Task <bool> SaveContact(ContactModel contactModel) { using (ContactDBContext db = new ContactDBContext()) { DataAccessLibrary.EntityModels.Contacts contact = db.Contacts.Where (x => x.ContactId == contactModel.ContactId).FirstOrDefault(); if (contact == null) { contact = new Contacts() { FirstName = contactModel.FirstName, LastName = contactModel.LastName, Email = contactModel.Email, Phone = contactModel.Phone }; db.Contacts.Add(contact); } else { contact.FirstName = contactModel.FirstName; contact.LastName = contactModel.LastName; contact.Email = contactModel.Email; contact.Phone = contactModel.Phone; } return(await db.SaveChangesAsync() >= 1); } }
public async Task <bool> DeleteContact(int contactId) { using (ContactDBContext db = new ContactDBContext()) { DataAccessLibrary.EntityModels.Contacts contact = db.Contacts.Where(x => x.ContactId == contactId).FirstOrDefault(); if (contact != null) { db.Contacts.Remove(contact); } return(await db.SaveChangesAsync() >= 1); } }