/// <summary> /// Customowe filtrowanie /// </summary> /// <typeparam name="T">Typ filtru</typeparam> /// <param name="_query">Zbiór encji</param> /// <param name="_filter">filtr</param> /// <returns></returns> protected override T FilterSettingsVirtual <T, Q>(ref IQueryable <Q> _query, T _filter) { if (_query is IQueryable <User> ) { var query = (IQueryable <User>)_query; dynamic filter1 = _filter; UserListViewModelFilter filter = filter1; var doFiltering = filter != null && filter.Filtering; if (doFiltering) { if (!string.IsNullOrEmpty(filter.FilterLogin)) { query = query.Where(q => q.Name.ToLower().Contains(filter.FilterLogin.ToLower())); } if (!string.IsNullOrEmpty(filter.FilterFirstName)) { query = query.Where(q => q.FirstName.ToLower().Contains(filter.FilterFirstName.ToLower())); } if (!string.IsNullOrEmpty(filter.FilterLastName)) { query = query.Where(q => q.LastName.ToLower().Contains(filter.FilterLastName.ToLower())); } if (filter.FilterRolaId.HasValue) { query = query.Where(q => q.Role.Id == filter.FilterRolaId); } if (filter.FilterBlocked.HasValue) { query = query.Where(q => q.IsBlocked == filter.FilterBlocked); } } filter.FilterRole = new SelectList(_roles.Roles.ToList(), "Id", "Name"); filter.YesNo = new SelectList(YesNoDictionary.GetList(), "Value", "Key"); _query = (IQueryable <Q>)query; filter1 = filter; return((T)filter1); } var queryR = (IQueryable <Role>)_query; dynamic filter1R = _filter; RoleListViewModelFilter filterR = filter1R; var doFilteringR = filterR != null && filterR.Filtering; if (doFilteringR) { if (!string.IsNullOrEmpty(filterR.FilterName)) { queryR = queryR.Where(q => q.Name.ToLower().Contains(filterR.FilterName.ToLower())); } if (filterR.Com.HasValue) { queryR = queryR.Where(q => q.Commission == filterR.Com.Value); } } _query = (IQueryable <Q>)queryR; filter1R = filterR; return((T)filter1R); }
/// <summary> /// Customowe filtrowanie /// </summary> /// <typeparam name="T">Typ filtru</typeparam> /// <param name="_query">Zbiór encji</param> /// <param name="_filter">filtr</param> /// <returns></returns> protected override T FilterSettingsVirtual <T, Q>(ref IQueryable <Q> _query, T _filter) { var query = (IQueryable <Campaign>)_query; dynamic filter1 = _filter; CampaignListViewModelFilter filter = filter1; query = query.Where(q => UserRole == "Admin" || UserID == q.UserId); if (filter != null) { if (filter.FilterActive.HasValue) { query = query.Where(q => q.IsActive == filter.FilterActive.Value); } if (filter.FilterStartDateFrom.HasValue) { query = query.Where(q => filter.FilterStartDateFrom.Value <= q.StartDate); } if (filter.FilterStartDateTo.HasValue) { query = query.Where(q => filter.FilterStartDateTo.Value >= q.StartDate); } if (filter.FilterEndDateFrom.HasValue) { query = query.Where(q => filter.FilterEndDateFrom.Value <= q.EndDate); } if (filter.FilterEndDateTo.HasValue) { query = query.Where(q => filter.FilterEndDateTo.Value >= q.EndDate); } if (filter.FilterPriorityId.HasValue && filter.FilterPriorityId.Value != SelectListExt.EmptyOptionValue) { var priorityId = filter.FilterPriorityId.Value; query = query.Where(q => q.PriorityId == priorityId); } if (!string.IsNullOrEmpty(filter.FilterName)) { query = query.Where(q => q.Name.ToLower().Contains(filter.FilterName.ToLower())); } if (!string.IsNullOrEmpty(filter.FilterLogin)) { query = query.Where(q => q.User.Name.ToLower().Contains(filter.FilterLogin.ToLower())); } } filter.Priorities = new SelectList(_priorityRepository.Priorities.ToList(), "Id", "Name"); filter.YesNo = new SelectList(YesNoDictionary.GetList(), "Value", "Key"); _query = (IQueryable <Q>)query; filter1 = filter; return((T)filter1); }
/// <summary> /// Przywrócenie informacji o słownikach potrzebnych do zbudowania modelu /// </summary> /// <param name="model">Obiekt modelu</param> private void RestoreDictionariesState(CampaignListViewModel model) { if (model.Filters == null) { return; } if (model.Filters.Priorities == null) { var selectedId = model.Filters.FilterPriorityId; model.Filters.Priorities = new SelectList(_priorityRepository.Priorities, "Id", "Name"); model.Filters.FilterPriorityId = selectedId; } if (model.Filters.YesNo == null) { var active = model.Filters.FilterActive; model.Filters.YesNo = new SelectList(YesNoDictionary.GetList(), "Value", "Key"); model.Filters.FilterActive = active; } }