public async Task <IPagedList <PlanDTO> > GetPlansPage(PlanQueryDTO query, int pageNumber, int pageSize = 10) { // AsExpandable used becouse of LinqKit var plans = Context.Plans.AsExpandable(); plans = FilterPlans(plans, query); plans = SorPlans(plans); return(await GetPlansPage(plans, pageNumber, pageSize)); }
public IHttpActionResult Query([FromUri] PlanQueryDTO planQuery) { using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var planResult = _plan.GetForUser( uow, _security.GetCurrentAccount(uow), planQuery, _security.IsCurrentUserHasRole(Roles.Admin) ); return(Ok(planResult)); } }
public async Task <ActionResult> Index(PlanQueryViewModel viewModel) { if (viewModel.PageNumber < 1) { viewModel.PageNumber = 1; } if (viewModel.PageSize < 1) { viewModel.PageSize = 10; } PlanQueryDTO filter = new PlanQueryDTO { Keyword = viewModel.Keyword, CpvCode = viewModel.CpvCode, ScgsCode = viewModel.GsinCode, PlanNumbers = viewModel.PlanNumbers, Procurer = viewModel.Procurer, Region = viewModel.Region, ProcedurePeriod = viewModel.ProcedurePeriod?.ToDTO(), ProcedureType = viewModel.ProcedureType }; IPagedList <PlanDTO> plansPagedList = await PlanProvider.Value.GetPlansPage(filter, viewModel.PageNumber, viewModel.PageSize); var plansViewModel = new PlansViewModel(plansPagedList, viewModel); if (Request.IsAjaxRequest()) { return(PartialView("Searches/Plans/PlanTable", plansViewModel)); } else { return(View("Plans", plansViewModel)); } }
private IQueryable <Plan> FilterPlans(IQueryable <Plan> plans, PlanQueryDTO filter) { return(plans); }
public PlanResultDTO GetForUser(IUnitOfWork uow, Fr8AccountDO account, PlanQueryDTO planQueryDTO, bool isAdmin) { return(_target.GetForUser(uow, account, planQueryDTO, isAdmin)); }
public PlanResultDTO GetForUser(IUnitOfWork unitOfWork, Fr8AccountDO account, PlanQueryDTO planQueryDTO, bool isAdmin = false) { //lets make sure our inputs are correct planQueryDTO = planQueryDTO ?? new PlanQueryDTO(); planQueryDTO.Page = planQueryDTO.Page ?? 1; planQueryDTO.Page = planQueryDTO.Page < 1 ? 1 : planQueryDTO.Page; planQueryDTO.PlanPerPage = planQueryDTO.PlanPerPage ?? DefaultPlanPageSize; planQueryDTO.PlanPerPage = planQueryDTO.PlanPerPage < MinPlanPageSize ? MinPlanPageSize : planQueryDTO.PlanPerPage; planQueryDTO.IsDescending = planQueryDTO.IsDescending ?? planQueryDTO.OrderBy?.StartsWith("-") ?? true; if (planQueryDTO.OrderBy?.StartsWith("-") == true) { planQueryDTO.OrderBy = planQueryDTO.OrderBy.Substring(1); } var planQuery = unitOfWork.PlanRepository.GetPlanQueryUncached() .Where(x => x.Visibility == PlanVisibility.Standard); if (planQueryDTO.AppsOnly) { planQuery = planQueryDTO.Id == null ? planQuery.Where(pt => pt.IsApp == true) : planQuery.Where(pt => pt.Id == planQueryDTO.Id && pt.IsApp == true); if (account.OrganizationId.HasValue) { // If the current user belongs to some organization, // display all apps for that organization planQuery = planQuery.Where(pt => pt.Fr8Account.OrganizationId == account.OrganizationId); } else { // If user does not belong to an org, just display his/her own apps. planQuery = planQuery.Where(pt => pt.Fr8Account.Id == account.Id); } } else { planQuery = planQueryDTO.Id == null ? planQuery.Where(pt => pt.Fr8Account.Id == account.Id) : planQuery.Where(pt => pt.Id == planQueryDTO.Id && pt.Fr8Account.Id == account.Id); } planQuery = !string.IsNullOrEmpty(planQueryDTO.Category) ? planQuery.Where(c => c.Category == planQueryDTO.Category) : planQuery.Where(c => string.IsNullOrEmpty(c.Category)); if (!string.IsNullOrEmpty(planQueryDTO.Filter)) { planQuery = planQuery.Where(c => c.Name.Contains(planQueryDTO.Filter) || c.Description.Contains(planQueryDTO.Filter)); } if (planQueryDTO.AppsOnly) { planQuery = planQuery.Where(c => c.IsApp == true); } int?planState = null; if (planQueryDTO.Status != null) { planState = PlanState.StringToInt(planQueryDTO.Status); } planQuery = planState == null ? planQuery.Where(pt => pt.PlanState != PlanState.Deleted) : planQuery.Where(pt => pt.PlanState == planState); // Lets allow ordering with just name for now if (planQueryDTO.OrderBy == "name") { planQuery = planQueryDTO.IsDescending.Value ? planQuery.OrderByDescending(p => p.Name) : planQuery.OrderBy(p => p.Name); } else { planQuery = planQueryDTO.IsDescending.Value ? planQuery.OrderByDescending(p => p.LastUpdated) : planQuery.OrderBy(p => p.LastUpdated); } var totalPlanCountForCurrentCriterias = planQuery.Count(); planQuery = planQuery.Skip(planQueryDTO.PlanPerPage.Value * (planQueryDTO.Page.Value - 1)) .Take(planQueryDTO.PlanPerPage.Value); return(new PlanResultDTO { Plans = planQuery.ToList().Select(Mapper.Map <PlanNoChildrenDTO>).ToList(), CurrentPage = planQueryDTO.Page.Value, TotalPlanCount = totalPlanCountForCurrentCriterias }); }