public static string TypeOfAdmin(tblAdministrator a)
 {
     try
     {
         using (dbFirmEntities context = new dbFirmEntities())
         {
             tblAdminType result = (from x in context.tblAdminTypes where x.adminTypeId == a.adminTypeId select x).FirstOrDefault();
             return(result.name);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception " + ex.Message.ToString());
         return(null);
     }
 }
 public static tblAdministrator GetAdminById(int id)
 {
     try
     {
         using (dbFirmEntities context = new dbFirmEntities())
         {
             tblAdministrator result = (from x in context.tblAdministrators where x.administratorId == id select x).FirstOrDefault();
             return(result);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception " + ex.Message.ToString());
         return(null);
     }
 }
 public static tblAdministrator AddAdministrator(tblAdministrator admin)
 {
     try
     {
         using (dbFirmEntities context = new dbFirmEntities())
         {
             if (admin.administratorId == 0)
             {
                 //add
                 tblAdministrator newAdmin = new tblAdministrator();
                 newAdmin.adminTypeId = admin.adminTypeId;
                 //exipry date +7days
                 DateTime d = DateTime.Now;
                 d = d.AddDays(7);
                 newAdmin.expiryDate = d.Date;
                 newAdmin.userId     = admin.userId;
                 context.tblAdministrators.Add(newAdmin);
                 context.SaveChanges();
                 admin.administratorId = newAdmin.administratorId;
                 return(admin);
             }
             else
             {
                 tblAdministrator adminToEdit = (from x in context.tblAdministrators where x.administratorId == admin.administratorId select x).FirstOrDefault();
                 adminToEdit.expiryDate  = admin.expiryDate;
                 adminToEdit.adminTypeId = admin.adminTypeId;
                 adminToEdit.userId      = admin.userId;
                 context.SaveChanges();
                 return(admin);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
         return(null);
     }
 }