Exemplo n.º 1
0
// ReSharper restore UnusedMember.Local

        private IQueryable <User> AddOrder(IQueryable <User> criteria, UserSortRule sortRule)
        {
            switch (sortRule)
            {
            case UserSortRule.Name:
                return(criteria.OrderBy(u => u.Name));

            case UserSortRule.RegisterDate:
                return(criteria.OrderBy(u => u.CreateDate));

            case UserSortRule.Group:
                return(criteria
                       .OrderBy(u => u.GroupId)
                       .ThenBy(u => u.Name));
            }

            return(criteria);
        }
Exemplo n.º 2
0
        public ActionResult UsersPaged(UserGroupId groupId   = UserGroupId.Nothing, string name          = "", bool disabled = false, bool verifiedArtists = false,
                                       UserSortRule sortRule = UserSortRule.RegisterDate, int totalCount = 0, int page       = 1)
        {
            var pageIndex = page - 1;
            var result    = Data.GetUsers(groupId, name, disabled, verifiedArtists, sortRule, PagingProperties.CreateFromPage(pageIndex, usersPerPage, false));
            var data      = new PagingData <UserContract>(result.Items.ToPagedList(pageIndex, usersPerPage, totalCount), null, "Index", "usersList", addTotalCount: true);

            data.RouteValues = new RouteValueDictionary(new { groupId, sortRule });

            if (Request.IsAjaxRequest())
            {
                return(PartialView("PagedUsers", data));
            }
            else
            {
                return(View("PagedUsers", data));
            }
        }
Exemplo n.º 3
0
        public ActionResult UsersPaged(UserGroupId groupId = UserGroupId.Nothing, string name = "", UserSortRule sortRule = UserSortRule.RegisterDate, int totalCount = 0, int page = 1)
        {
            var pageIndex = page - 1;
            var result = Service.GetUsers(groupId, name, sortRule, PagingProperties.CreateFromPage(pageIndex, usersPerPage, false));
            var data = new PagingData<UserContract>(result.Items.ToPagedList(pageIndex, usersPerPage, totalCount), null, "Index", "usersList");
            data.RouteValues = new RouteValueDictionary(new { groupId, sortRule, totalCount, action = "Index" });

            if (Request.IsAjaxRequest())
                return PartialView("PagedUsers", data);
            else
                return View("PagedUsers", data);
        }
Exemplo n.º 4
0
        //
        // GET: /User/
        public ActionResult Index(Index model, UserSortRule? sort = null, int totalCount = 0, int page = 1)
        {
            if (Request.IsAjaxRequest())
                return UsersPaged(model.GroupId, model.Name, sort ?? UserSortRule.RegisterDate, totalCount, page);

            var pageIndex = page - 1;
            var groupId = model.GroupId;
            var sortRule = sort ?? UserSortRule.RegisterDate;

            var result = Service.GetUsers(groupId, model.Name, sortRule, PagingProperties.CreateFromPage(pageIndex, usersPerPage, true));
            var data = new PagingData<UserContract>(result.Items.ToPagedList(pageIndex, usersPerPage, result.TotalCount), null, "Index", "usersList");
            data.RouteValues = new RouteValueDictionary(new { groupId, name = model.Name, sortRule, totalCount = result.TotalCount, action = "Index" });

            return View(new Index(data, groupId, model.Name));
        }
Exemplo n.º 5
0
        private PartialFindResult <UserContract> CallGetUsers(UserGroupId groupId = UserGroupId.Nothing, string name = null, bool disabled = false, bool verifiedArtists = false, UserSortRule sortRule = UserSortRule.Name, PagingProperties paging = null)
        {
            var queryParams = new UserQueryParams {
                Common              = new CommonSearchParams(SearchTextQuery.Create(name), false, false),
                Group               = groupId,
                IncludeDisabled     = disabled,
                OnlyVerifiedArtists = verifiedArtists,
                Sort   = sortRule,
                Paging = paging ?? new PagingProperties(0, 10, true)
            };

            return(data.GetUsers(queryParams, u => new UserContract(u)));
        }
Exemplo n.º 6
0
 private PartialFindResult <UserContract> CallGetUsers(UserGroupId groupId = UserGroupId.Nothing, string name = null, bool disabled = false, bool verifiedArtists = false, UserSortRule sortRule = UserSortRule.Name, PagingProperties paging = null)
 {
     return(data.GetUsers(SearchTextQuery.Create(name), groupId, disabled, verifiedArtists, sortRule, paging ?? new PagingProperties(0, 10, true), u => new UserContract(u)));
 }
Exemplo n.º 7
0
        public PartialFindResult <UserContract> GetUsers(UserGroupId groupId, string name, UserSortRule sortRule, PagingProperties paging)
        {
            return(HandleQuery(session => {
                var users = AddOrder(session.Query <User>()
                                     .Where(u => (groupId == UserGroupId.Nothing || u.GroupId == groupId) && string.IsNullOrWhiteSpace(name) || u.Name.Contains(name)), sortRule)
                            .Skip(paging.Start)
                            .Take(paging.MaxEntries)
                            .ToArray()
                            .Select(u => new UserContract(u))
                            .ToArray();

                var count = paging.GetTotalCount ? session.Query <User>()
                            .Count(u => (groupId == UserGroupId.Nothing || u.GroupId == groupId) && string.IsNullOrWhiteSpace(name) || u.Name.Contains(name)) : 0;

                return new PartialFindResult <UserContract>(users, count);
            }));
        }
Exemplo n.º 8
0
        public PartialFindResult <UserContract> GetUsers(UserGroupId groupId, string name, bool disabled, bool verifiedArtists, UserSortRule sortRule, PagingProperties paging)
        {
            return(repository.HandleQuery(ctx => {
                var usersQuery = ctx.Query();

                if (groupId != UserGroupId.Nothing)
                {
                    usersQuery = usersQuery.Where(u => u.GroupId == groupId);
                }

                if (!string.IsNullOrWhiteSpace(name))
                {
                    usersQuery = usersQuery.Where(u => u.Name.Contains(name));
                }

                if (!disabled)
                {
                    usersQuery = usersQuery.Where(u => u.Active);
                }

                if (verifiedArtists)
                {
                    usersQuery = usersQuery.Where(u => u.AllOwnedArtists.Any());
                }

                var users = AddOrder(usersQuery, sortRule)
                            .Skip(paging.Start)
                            .Take(paging.MaxEntries)
                            .ToArray()
                            .Select(u => new UserContract(u))
                            .ToArray();

                var count = paging.GetTotalCount ? usersQuery.Count() : 0;

                return new PartialFindResult <UserContract>(users, count);
            }));
        }
Exemplo n.º 9
0
        //
        // GET: /User/
        public ActionResult Index(Index model, string filter = null, UserSortRule? sort = null, int totalCount = 0, int page = 1)
        {
            if (!string.IsNullOrEmpty(filter) && string.IsNullOrEmpty(model.Name))
                model.Name = filter;

            if (Request.IsAjaxRequest())
                return UsersPaged(model.GroupId, model.Name, model.Disabled, model.VerifiedArtists, sort ?? UserSortRule.RegisterDate, totalCount, page);

            var pageIndex = page - 1;
            var groupId = model.GroupId;
            var sortRule = sort ?? UserSortRule.RegisterDate;

            var result = Data.GetUsers(groupId, model.Name, model.Disabled, model.VerifiedArtists, sortRule, PagingProperties.CreateFromPage(pageIndex, usersPerPage, true));

            if (page == 1 && result.TotalCount == 1 && result.Items.Length == 1) {
                return RedirectToAction("Profile", new { id = result.Items[0].Name });
            }

            var data = new PagingData<UserContract>(result.Items.ToPagedList(pageIndex, usersPerPage, result.TotalCount), null, "Index", "usersList");
            data.RouteValues = new RouteValueDictionary(new { groupId, name = model.Name, disabled = model.Disabled, sortRule, totalCount = result.TotalCount, action = "Index" });

            return View(new Index(data, groupId, model.Name, model.VerifiedArtists));
        }
Exemplo n.º 10
0
		private PartialFindResult<UserContract> CallGetUsers(UserGroupId groupId = UserGroupId.Nothing, string name = null, bool disabled = false, bool verifiedArtists = false, UserSortRule sortRule = UserSortRule.Name, PagingProperties paging = null) {
			return data.GetUsers(groupId, name, disabled, verifiedArtists, sortRule, paging ?? new PagingProperties(0, 10, true));
		}