Exemplo n.º 1
0
        private DatabaseRequestPage GetRequestPage(DatabaseRequestFilter filter)
        {
            DatabaseRequestPage result = new DatabaseRequestPage();

            using (ApplicationDbContext context = ApplicationDbContext.Create())
            {
                List <DatabaseRequest> requests = (from req in context.Requests
                                                   where (filter.RequestType == 0 || filter.RequestType == req.RequestType) &&
                                                   ((filter.SubmittedBy == null || filter.SubmittedBy.Length == 0) || req.Submitter.UserName.Contains(filter.SubmittedBy)) &&
                                                   (!filter.LowerBoundDate.HasValue || filter.LowerBoundDate.Value.CompareTo(req.SubmissionDate) <= 0) &&
                                                   (!filter.UpperBoundDate.HasValue || filter.UpperBoundDate.Value.CompareTo(req.SubmissionDate) >= 0)
                                                   orderby req.SubmissionDate
                                                   select req
                                                   ).ToList();
                List <DatabaseRequestViewModel> resultRequests = null;
                int offset = (filter.PageNumber - 1) * filter.ResultsPerPage;
                // If there are enough results to make a page
                if (requests.Count - offset >= filter.ResultsPerPage)
                {
                    resultRequests = requests.Select(y => DatabaseRequestViewModel.FromModel(y)).Where(x => ((filter.NodeName == null || filter.NodeName == "") || x.NodeData.CommonName.Contains(filter.NodeName)))
                                     .Skip(offset).Take(filter.ResultsPerPage).ToList();
                }
                else
                {
                    resultRequests = requests.Select(y => DatabaseRequestViewModel.FromModel(y)).Where(x => ((filter.NodeName == null || filter.NodeName == "") || x.NodeData.CommonName.Contains(filter.NodeName)))
                                     .Skip(offset).ToList();
                }

                result = new DatabaseRequestPage
                {
                    TotalPages  = (int)Math.Ceiling(requests.Count / (double)filter.ResultsPerPage),
                    CurrentPage = filter.PageNumber,
                    Requests    = resultRequests
                };
            }

            return(result);
        }
Exemplo n.º 2
0
 public ActionResult RequestPage(DatabaseRequestFilter filter)
 {
     return(Json(GetRequestPage(filter)));
 }