Exemple #1
0
    public ActionResult ApplyFilter(DvsUserFilter filter)
		{
			filter.IsApply = true;
      filter.CurrentPage = Constants.Paging.DefaultPageNumber;

			TempData["DvsUserFilter"] = filter;
			return RedirectToAction(NameHelper.DvsPipeline.Administrators);
		}
Exemple #2
0
		public ActionResult Administrators(DvsUserFilter filter = null)
		{
			DvsUserFilter applyfilter = TempData["DvsUserFilter"] as DvsUserFilter;
			if (filter == null)
			{
				filter = GetEmptyFilter();
			}
      MergeFilters(filter, applyfilter);
			return View(_dvsUserManagementService.GetDvsUsersListViewModel(filter));
		}
Exemple #3
0
		public IPagedList<DvsUser> GetDvsUsersListByFilter(DvsUserFilter filter)
		{
			if (filter == null)
				throw new ArgumentNullException();

			Expression<Func<DvsUser, bool>> where = PredicateBuilder.True<DvsUser>();

			if (!string.IsNullOrEmpty(filter.UserName))
			{
				var userName = filter.UserName.Trim();
				where = where.AndAlso<DvsUser>(x => (x.User.FirstName + " " + x.User.LastName).Contains(userName) ||
					(x.User.LastName + " " + x.User.FirstName).Contains(userName));
			}

			if (!string.IsNullOrEmpty(filter.Email))
				where = where.AndAlso<DvsUser>(x => x.User.Email.Contains(filter.Email.Trim()));


			if (filter.Statuses != null)
			{
				var statuses = filter.Statuses.Select(s => s.ToString());
				where = where.AndAlso<DvsUser>(x => statuses.Contains(x.StatusId));
			}

			if (filter.Roles != null)
			{
				where = where.AndAlso<DvsUser>(x => filter.Roles.Any(r => x.User.Roles.Any(e => e.Id == r)));
			}

			Func<IQueryable<DvsUser>, IOrderedQueryable<DvsUser>> orderBy = null;

			if (!string.IsNullOrEmpty(filter.NameOfSortColumn))
			{
				if (filter.IsAscending)
				{
					switch (filter.NameOfSortColumn)
					{
						case "Role":
							orderBy = i => i.OrderBy(x => x.User.Roles.FirstOrDefault().DisplayName);
							break;
						case "FirstName":
							orderBy = i => i.OrderBy(x => x.User.FirstName);
							break;
						case "LastName":
							orderBy = i => i.OrderBy(x => x.User.LastName);
							break;
						case "FullName":
							orderBy = i => i.OrderBy(x => x.User.FirstName).ThenBy(x => x.User.LastName);
							break;
						case "Status":
							orderBy = i => i.OrderBy(x => x.StatusId);
							break;
						default:
							throw new NotSupportedException("Unknow Column Name");
					}
				}
				else
				{
					switch (filter.NameOfSortColumn)
					{
						case "Role":
							orderBy = i => i.OrderByDescending(x => x.User.Roles.FirstOrDefault().DisplayName);
							break;
						case "FirstName":
							orderBy = i => i.OrderByDescending(x => x.User.FirstName);
							break;
						case "LastName":
							orderBy = i => i.OrderByDescending(x => x.User.LastName);
							break;
						case "FullName":
							orderBy = i => i.OrderByDescending(x => x.User.FirstName).ThenByDescending(x => x.User.LastName);
							break;
						case "Status":
							orderBy = i => i.OrderByDescending(x => x.StatusId);
							break;
						default:
							throw new NotSupportedException("Unknow Column Name");
					}
				}
			}

			var results = _repository.GetPaged(where, orderBy, filter.ItemsOnPage ?? 10, filter.CurrentPage ?? 1);
			filter.PagesTotal = results.PageCount;

			return results;
		}
Exemple #4
0
    private DvsUserFilter GetEmptyFilter(int itemsOnPage = Constants.Paging.DefaultPageSize)
		{
			var filter = new DvsUserFilter()
			{
        CurrentPage = Constants.Paging.DefaultPageSize,
				ItemsOnPage = itemsOnPage,
			};
			return filter;
		}
Exemple #5
0
    private void MergeFilters(DvsUserFilter filter, DvsUserFilter applyfilter)
    {
      if (filter == null) throw new ArgumentNullException("filter");
      if (applyfilter == null) return;

      filter.IsApply = applyfilter.IsApply;
      filter.UserName = applyfilter.UserName;
      filter.Email = applyfilter.Email;
      filter.Roles = applyfilter.Roles;
      filter.Statuses = applyfilter.Statuses;
    }
		private void ApplyDefaultValues(DvsUserFilter filter)
		{
			filter.CurrentPage = filter.CurrentPage ?? 1;
			filter.Email = filter.Email ?? string.Empty;
			filter.ItemsOnPage = filter.ItemsOnPage ?? 10;
			filter.NameOfSortColumn = filter.NameOfSortColumn ?? Constants.DvsUsersSortColumns.FullName;
			filter.UserName = filter.UserName ?? string.Empty;
		}
		public DvsUsersListViewModel GetDvsUsersListViewModel(DvsUserFilter filter)
		{
			var result = new DvsUsersListViewModel();
			ApplyDefaultValues(filter);
			//Add here additional filter options if needed
			IPagedList<DvsUser> results = _dvsUserManager.GetDvsUsersListByFilter(filter);

			result.PagedUsers = results;
			result.Users = results;
			result.Filter = filter;

			return result;
		}
		public void GetDvsUsersListViewModel_should_get_list()
		{
			var filter = new DvsUserFilter();
			var result = _target.GetDvsUsersListViewModel(filter);
		}