示例#1
0
        public async Task <IActionResult> List(FilterGridDTO values)
        {
            User user = await userManager.GetUserAsync(User);

            var gridBuilder = new CoverageGridBuilder(HttpContext.Session, values, nameof(AbsenceRequest.StartDate));

            var options = new CoverageQueryOptions
            {
                Include          = "DurationType, AbsenceRequestPeriods, AbsenceStatus, User, SubJob, SubJob.SubJobStatus",
                Where            = ar => ar.User.CampusId == user.CampusId && ar.AbsenceStatus.Name == "Approved" && ar.NeedCoverage == true,
                OrderByDirection = gridBuilder.CurrentGrid.SortDirection,
            };

            options.Search(gridBuilder);
            options.FromDateRange(gridBuilder);
            options.Filter(gridBuilder);
            options.Sort(gridBuilder);


            CoverageListViewModel model = new CoverageListViewModel
            {
                Grid            = gridBuilder.CurrentGrid,
                AbsenceRequests = data.AbsenceRequests.List(options),
                DurationTypes   = data.DurationTypes.List(),
                SubJobStatuses  = data.SubJobStatuses.List()
            };

            model.TotalPages      = gridBuilder.GetTotalPages(model.AbsenceRequests.Count());
            model.AbsenceRequests = model.AbsenceRequests.Skip((gridBuilder.CurrentGrid.PageNumber - 1) * gridBuilder.CurrentGrid.PageSize).Take(gridBuilder.CurrentGrid.PageSize);

            return(View(model));
        }
        public void Sort(CoverageGridBuilder gridBuilder)
        {
            //SortBy
            switch (gridBuilder.CurrentGrid.SortBy)
            {
            case nameof(AbsenceRequest.StartDate):
                OrderBy = ar => ar.StartDate;
                break;

            case nameof(AbsenceRequest.User.LastName):
                OrderBy = ar => ar.User.LastName;
                break;

            case nameof(AbsenceRequest.DurationType):
                OrderBy = ar => ar.DurationType.Name;
                break;

            case nameof(FilterGridDTO.SubJobStatus):
                OrderBy = ar => ar.SubJob.SubJobStatus;
                break;

            default:
                OrderBy = ar => ar.StartDate;
                break;
            }
        }
 public void Search(CoverageGridBuilder gridBuilder)
 {
     if (gridBuilder.CurrentGrid.Search != null)
     {
         string searchTerm = gridBuilder.CurrentGrid.Search.ToLower();
         Where = ar => ar.User.FirstName.ToLower().Contains(searchTerm) || ar.User.LastName.ToLower().Contains(searchTerm);
     }
 }
        public void FromDateRange(CoverageGridBuilder gridBuilder)
        {
            if (gridBuilder.CurrentGrid.FromDate != null && gridBuilder.CurrentGrid.ToDate != null)
            {
                DateTime fromDate = gridBuilder.ConvertToDateTime(gridBuilder.CurrentGrid.FromDate);
                DateTime toDate   = gridBuilder.ConvertToDateTime(gridBuilder.CurrentGrid.ToDate);

                Where = ar => ar.StartDate >= fromDate && ar.StartDate <= toDate;
            }
        }
        public void Filter(CoverageGridBuilder gridBuilder)
        {
            if (gridBuilder.CurrentGrid.Duration != "all")
            {
                Where = ar => ar.DurationTypeId == gridBuilder.CurrentGrid.Duration;
            }


            if (gridBuilder.CurrentGrid.SubJobStatus != "all" && gridBuilder.CurrentGrid.SubJobStatus != "none")
            {
                Where = ar => ar.SubJob.SubJobStatusId == gridBuilder.CurrentGrid.SubJobStatus;
            }
        }
示例#6
0
        public RedirectToActionResult SearchOptions(string[] filters, string fromdate, string todate, string searchTerm, bool clear = false)
        {
            //Initialize with the GET constructor (Desirializes Grid dictionary)
            var gridBuilder = new CoverageGridBuilder(HttpContext.Session);

            if (clear)
            {
                gridBuilder.ClearSearchOptions();
            }
            else
            {
                //Set new filter value to current grid and serialize.
                gridBuilder.SetSearchOptions(filters, fromdate, todate, searchTerm);
                gridBuilder.SerializeRoutes();
            }

            //Redirect to the List Action Method with updated grid dictionary
            return(RedirectToAction("List", gridBuilder.CurrentGrid));
        }