public static tblClinicMaintenance AddMaintenance(tblClinicMaintenance m)
 {
     try
     {
         using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
         {
             if (m.maintenanceId == 0)
             {
                 //add
                 tblClinicMaintenance newM = new tblClinicMaintenance();
                 newM.name = m.name;
                 newM.permissionToExpand      = m.permissionToExpand;
                 newM.accessibilityOfInvalids = m.accessibilityOfInvalids;
                 context.tblClinicMaintenances.Add(newM);
                 context.SaveChanges();
                 m.maintenanceId = newM.maintenanceId;
                 return(m);
             }
             else
             {
                 tblClinicMaintenance mToEdit = (from x in context.tblClinicMaintenances where x.maintenanceId == m.maintenanceId select x).FirstOrDefault();
                 mToEdit.name = m.name;
                 mToEdit.accessibilityOfInvalids = m.accessibilityOfInvalids;
                 mToEdit.permissionToExpand      = m.permissionToExpand;
                 context.SaveChanges();
                 return(m);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
         return(null);
     }
 }
 public static void DeleteMaintenance(tblClinicMaintenance maintenance)
 {
     try
     {
         using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4())
         {
             tblClinicMaintenance toDelete = (from u in context.tblClinicMaintenances where u.maintenanceId == maintenance.maintenanceId select u).First();
             context.tblClinicMaintenances.Remove(toDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }