/// <summary> /// This method is used to update contact in database /// </summary> /// <param name="contactDetail"></param> public void EditContact(ContactDetail contactDetail) { try { using (var context = new ContactInfoContext()) { context.Entry(contactDetail).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } catch (Exception ex) { log.Error("Error in EditContact.", ex); throw; } }
/// <summary> /// This method is used to Add contacts in the database /// </summary> /// <param name="contactDetail">contacts to add</param> public void AddContact(ContactDetail contactDetail) { try { using (var context = new ContactInfoContext()) { context.Contacts.Add(contactDetail); context.SaveChanges(); } } catch (Exception ex) { log.Error("Error in AddContact.", ex); throw; } }
/// <summary> /// This method is used to delete any contact from database /// </summary> /// <param name="contactId">contactid by which you can delete record</param> public void DeleteContact(int contactId) { try { using (var context = new ContactInfoContext()) { ContactDetail contactDetail = context.Contacts.Find(contactId); context.Contacts.Remove(contactDetail); context.SaveChanges(); } } catch (Exception ex) { log.Error("Error in DeleteContact.", ex); throw; } }