public JsonResult CreateLab(LabCreate newLabData, int Lab_ID)
 {
     var a = ModelState.IsValid;
     JsonResult result = new JsonResult();
     ApplicationDbContext db = new ApplicationDbContext();
     if (newLabData.Name != null)
     {
         Lab newLab = new Lab();
         if (Lab_ID != 0)
         {
             newLab = db.Labs.Where(l => l.ID == Lab_ID).FirstOrDefault();
         }
         newLab.ApplicationUserID = User.Identity.GetUserId();
         newLab.Name = newLabData.Name;
         newLab.Status = "Scheduled";
         newLab.Time_Zone = newLabData.Time_Zone;
         TimeZoneInfo hwZone = TimeZoneInfo.FindSystemTimeZoneById(newLabData.Time_Zone);
         newLab.Start_Time = TimeZoneInfo.ConvertTime(newLabData.Start_Time, hwZone, TimeZoneInfo.Local);
         newLab.End_Time = TimeZoneInfo.ConvertTime(newLabData.End_Time, hwZone, TimeZoneInfo.Local);
         if (Lab_ID == 0)
         {
             db.Labs.Add(newLab);
         }
         db.SaveChanges();
         Lab_ID = newLab.ID;
     }
     try
     {
         if (Lab_ID != 0)
         {
             if (newLabData.OS != null)
             {
                 ConfigureLab(newLabData, Lab_ID);
             }
             EditParticipants(newLabData.LabParticipants, Lab_ID);
         }
     }
     catch (Exception ex)
     {
         string message = ex.ToString();
     }
     result = Json(new { Status = 0, ModelState = a, Lab = "lab-" + Lab_ID });
     return result;
 }
 public JsonResult EditLab(LabCreate newLabData, int Lab_ID)
 {
     ApplicationDbContext db = new ApplicationDbContext();
     var lab = db.Labs.Where(l => l.ID == Lab_ID).FirstOrDefault();
     lab.Name = newLabData.Name;
     lab.Start_Time = newLabData.Start_Time;
     lab.End_Time = newLabData.End_Time;
     try
     {
         EditParticipants(newLabData.LabParticipants, Lab_ID);
         ConfigureLab(newLabData, Lab_ID);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         string msg = ex.ToString();
     }
     return Json(new { Status = 0 });
 }
 protected int ConfigureLab(LabCreate newLabData, int Lab_ID)
 {
     ApplicationDbContext db = new ApplicationDbContext();
     LabConfiguration newLabConfig = new LabConfiguration();
     LabConfiguration config = db.LabConfiguration.Where(c => c.LabID == Lab_ID).FirstOrDefault();
     if (config != null)
     {
         newLabConfig = config;
     }
     else
     {
         newLabConfig.LabID = Lab_ID;
     }
     newLabConfig.Networked = newLabData.Networked;
     newLabConfig.OS = newLabData.OS;
     newLabConfig.VM_Count = newLabData.VM_Count;
     newLabConfig.Machine_Size = newLabData.Machine_Size;
    // newLabConfig.Hard_Disk = newLabData.;
     if (config == null)
     {
         db.LabConfiguration.Add(newLabConfig);
     }
     db.SaveChanges();
     return 0;
 }