public RequestWindow(DatabaseContext context)
        {
            InitializeComponent();

            _viewModel       = new DatabaseRequestViewModel(this, context, new DefaultDialogService());
            this.DataContext = _viewModel;
        }
示例#2
0
        public ActionResult ViewRequest(Guid id)
        {
            ActionResult result = View("Error");

            using (ApplicationDbContext context = ApplicationDbContext.Create())
            {
                DatabaseRequest request = context.Requests.SingleOrDefault(x => x.Id == id);
                if (request != null)
                {
                    result = View(model: DatabaseRequestViewModel.FromModel(request));
                }
            }

            return(result);
        }
示例#3
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);
        }