public JsonResult GetGridTests(string page, string size)
        {
            List <TestDescriptionViewModel> list = new List <TestDescriptionViewModel>();

            using (var context = new Entities())
            {
                var pageSize    = Convert.ToInt32(size);
                var skipSize    = pageSize * (Convert.ToInt32(page) - 1);
                var rangeOfSets = context.TestSets.OrderByDescending(x => x.Id).Skip(skipSize).Take(pageSize);
                var lastTestRun = string.Empty;

                foreach (var set in rangeOfSets)
                {
                    if (context.TestRuns.Where(x => x.TestSetId == set.Id).Count() != 0)
                    {
                        lastTestRun = context.TestRuns.Where(x => x.TestSetId == set.Id).
                                      OrderByDescending(p => p.DateOfRun).Take(1).ToList()
                                      .Last().DateOfRun.ToString();
                    }
                    else
                    {
                        lastTestRun = "never";
                    }

                    var shortDescription = string.Empty;
                    if (set.Description.Length > 25)
                    {
                        shortDescription = set.Description.Substring(0, 12) + "...";
                    }
                    else
                    {
                        shortDescription = set.Description;
                    }

                    var fileSize = string.Empty;
                    fileSize = set.Size == 0 ? "< 1" : set.Size.ToString();

                    var testSet = new TestDescriptionViewModel
                    {
                        CreatedBy   = context.Users.FirstOrDefault <Users>(x => x.Id == set.CreatorId).UserName,
                        DateCreated = set.DateOfCreation.ToString(),
                        Description = shortDescription,
                        FileSize    = fileSize + " kb",
                        LastRun     = lastTestRun,
                        Runs        = context.TestRuns.Count(x => x.TestSetId == set.Id).ToString(),
                        TestName    = set.Name
                    };

                    list.Add(testSet);
                }
            }

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
        public ActionResult TestDetails(string testName)
        {
            var result = new TestDescriptionViewModel();

            using (var context = new Entities())
            {
                var set         = context.TestSets.Where(x => x.Name == testName).ToArray()[0];
                var lastTestRun = string.Empty;
                if (context.TestRuns.Where(x => x.TestSetId == set.Id).Count() != 0)
                {
                    lastTestRun = context.TestRuns.Where(x => x.TestSetId == set.Id).
                                  OrderByDescending(p => p.DateOfRun).Take(1).ToList()
                                  .Last().DateOfRun.ToString();
                }
                else
                {
                    lastTestRun = "never";
                }

                var fileSize = string.Empty;
                fileSize = set.Size == 0 ? "< 1" : set.Size.ToString();

                result = new TestDescriptionViewModel
                {
                    CreatedBy   = context.Users.FirstOrDefault <Users>(x => x.Id == set.CreatorId).UserName,
                    DateCreated = set.DateOfCreation.ToString(),
                    Description = set.Description,
                    FileSize    = fileSize,
                    LastRun     = lastTestRun,
                    Runs        = context.TestRuns.Count(x => x.TestSetId == set.Id).ToString(),
                    TestName    = set.Name
                };
            }

            return(View(result));
        }