Exemple #1
0
        public IActionResult AllRequests(AllRequestsViewModel viewModel, int page = 1)
        {
            var userId = this.userManager.GetUserId(this.User);

            viewModel.Requests =
                this.requestsService
                .AllRequests <RequestInfoViewModel>(userId, take, (int)(page - 1) * take);

            var count = this.requestsService.AllRequests <RequestInfoViewModel>(userId).Count();

            if (!string.IsNullOrEmpty(viewModel.SearchTerm))
            {
                viewModel.Requests = this.requestsService
                                     .AllRequests <RequestInfoViewModel>(userId, take, (int)(page - 1) * take)
                                     .Where(r => r.EmergencyStatus.ToString().Contains(viewModel.SearchTerm) ||
                                            r.BloodGroup.ToString().Contains(viewModel.SearchTerm) ||
                                            r.RhesusFactor.ToString().Contains(viewModel.SearchTerm) ||
                                            r.HospitalName.Contains(viewModel.SearchTerm) ||
                                            r.Location.Country.Contains(viewModel.SearchTerm) ||
                                            r.Location.City.Contains(viewModel.SearchTerm) ||
                                            r.Location.AdressDescription.Contains(viewModel.SearchTerm));

                count = viewModel.Requests.Count();
            }

            viewModel.PagesCount = (int)Math.Ceiling((double)count / take);
            if (viewModel.PagesCount == 0)
            {
                viewModel.PagesCount = 1;
            }

            viewModel.CurrentPage = page;

            return(this.View(viewModel));
        }
        public IActionResult Index(int?requestState, int?offer)
        {
            AllRequestsViewModel allRequestsVM = new AllRequestsViewModel();

            allRequestsVM.CurrentOfferId        = offer ?? 0;
            allRequestsVM.CurrentRequestStateId = requestState ?? 0;

            List <Offer> offers = _context.Offers.ToList();

            offers.Insert(0, new Offer {
                Id = 0, Title = "Все"
            });
            allRequestsVM.Offers = new SelectList(offers, "Id", "Title");

            List <ClientRequest> clientRequests = _context.ClientRequests.Include(cr => cr.Client).ToList();

            if (requestState != 0 && requestState != null)
            {
                clientRequests = clientRequests.Where(cr => cr.ClientRequestStateId == requestState).ToList();
            }

            if (offer != 0 && offer != null)
            {
                clientRequests = clientRequests.Where(cr => cr.OfferId == offer).ToList();
            }

            allRequestsVM.ClientRequests = clientRequests;

            List <ClientRequestState> requestStates = _context.ClientRequestStates.ToList();

            requestStates.Insert(0, new ClientRequestState {
                Id = 0, Title = "Все"
            });
            allRequestsVM.ClientRequestStates = new SelectList(requestStates, "Id", "Title");

            return(View(allRequestsVM));
        }