コード例 #1
0
 /// <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;
     }
 }
コード例 #2
0
 /// <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;
     }
 }
コード例 #3
0
 /// <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;
     }
 }