Exemple #1
0
 public ActionResult Index()
 {
     List<LabUser> allLabs = db.LabUser.ToList();
     List<LabUserViewModel> allLabsVM = new List<LabUserViewModel>();
     foreach (LabUser user in allLabs)
     {
         if (user.Active)
         {
             LabUserViewModel luvm = new LabUserViewModel();
             luvm.User = user;
             UseInstance laststart = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_1 && (t.Active ?? true));
             UseInstance lastfinish = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_3 && (t.Active ?? true));
             if (laststart == null || lastfinish == null)
             {
                 Module dummy = new Module() { ModuleName = Constants.Null_Instance };
                 luvm.Module = dummy;
                 luvm.LastStart = Constants.Null_Instance;
                 luvm.LastFinish = Constants.Null_Instance;
                 luvm.LabsCompleted = 0;
             }
             else
             {
                 luvm.Module = laststart.Module;
                 luvm.LabsCompleted = user.UseInstances.Count(t => t.Stage.ToLower() == Constants.Stage_3 && (t.Active ?? true));
                 luvm.LastStart = laststart.Time.ToString();
                 luvm.LastFinish = DateTime.Compare(lastfinish.Time, laststart.Time) > 0 ? lastfinish.Time.ToString() : Constants.Null_Instance;
             }
             allLabsVM.Add(luvm);
         }
     }
     return View(allLabsVM);
 }
Exemple #2
0
        public ActionResult ModalUserInfo(int id = 0)
        {
            LabUser user = db.LabUser.Find(id);
            if (user == null)
            {
                return Json(new { success = false });
            }
            LabUserViewModel luvm = new LabUserViewModel();

            luvm.User = user;
            UseInstance laststart = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_1 && (t.Active ?? true));
            UseInstance lastfinish = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_3 && (t.Active ?? true));
            if (laststart == null || lastfinish == null)
            {
                Module dummyMod = new Module() {
                    ModuleName = Constants.Null_Instance
                };
                UseInstance dummyIns = new UseInstance() {
                    Browser = Constants.Null_Instance,
                    OS = Constants.Null_Instance,
                    IP = Constants.Null_Instance
                };
                luvm.Module = dummyMod;
                luvm.LastStart = Constants.Null_Instance;
                luvm.LastFinish = Constants.Null_Instance;
                luvm.LabsCompleted = 0;
                luvm.lastInstance = dummyIns;
            }
            else
            {
                luvm.Module = laststart.Module;
                luvm.LabsCompleted = user.UseInstances.Count(t => t.Stage.ToLower() == Constants.Stage_3 && (t.Active ?? true));
                luvm.LastStart = laststart.Time.ToString();
                luvm.LastFinish = DateTime.Compare(lastfinish.Time, laststart.Time) > 0 ? lastfinish.Time.ToString() : Constants.Null_Instance;
                luvm.lastInstance = laststart;
            }

            return PartialView("_FullInfo", luvm);
        }
Exemple #3
0
        /// <summary>
        /// The same as ModalUserInfo but with additional information about specific sessions available.
        /// </summary>
        /// <param name="id">The user ID to display info for.</param>
        /// <returns>A view</returns>
        public ActionResult FullUserInfo(int id = 0)
        {
            LabUser user = db.LabUser.Find(id);
            LabUserViewModel luvm = new LabUserViewModel();
            if (user == null)
            {
                Exception e = new Exception("Cannot get full information of non-existent user.");
                Elmah.ErrorSignal.FromCurrentContext().Raise(e);
                return RedirectToAction("NotFound", "Error");
            }

            luvm.User = user;
            UseInstance laststart = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_1);
            UseInstance lastfinish = user.UseInstances.LastOrDefault(t => t.Stage.ToLower() == Constants.Stage_3);
            if (laststart == null || lastfinish == null)
            {
                luvm.LastStart = Constants.Null_Instance;
                luvm.LastFinish = Constants.Null_Instance;
            }
            else
            {
                luvm.Module = laststart.Module;
                luvm.LabsCompleted = user.UseInstances.Count(t => t.Stage.ToLower() == Constants.Stage_3);
                luvm.LastStart = laststart.Time.ToString();
                luvm.LastFinish = DateTime.Compare(lastfinish.Time, laststart.Time) > 0 ? lastfinish.Time.ToString() : Constants.Null_Instance;
                luvm.lastInstance = laststart;
            }
            return View(luvm);
        }