Example #1
0
		public async Task<ActionResult> Index(UserSortOrder sortOrder = UserSortOrder.UserNameAscending,
		                                      int page = 1)
		{
			var users     = await mUserService.GetAllUsers(sortOrder, page, usersPerPage: 50);
			var viewModel = UsersIndexViewModelMapper.FromUsers(users, sortOrder);

			ViewBag.Message = TempData["Message"];
			return View(viewModel);
		}
Example #2
0
 /// <summary>
 /// Finds a collection of users with the given values.
 /// </summary>
 /// <param name="name">The name for the item to be found.</param>
 /// <param name="orderBy">The order in which items are returned in a result set.</param>
 /// <param name="pageIndex">The index of the page of results to return. Use 1 to indicate the first page.</param>
 /// <param name="pageSize">The size of the page of results to return. <paramref name="pageIndex" /> is non-zero-based.</param>
 /// <param name="fields">The related fields to include in the query results.</param>
 /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
 /// <returns>
 /// A task that represents the asynchronous operation.
 /// </returns>
 public virtual Task <ListResult <UserItem> > FindAllAsync(string name, UserSortOrder orderBy, int pageIndex, int pageSize, UserField fields, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     return(Users
            .AsNoTracking()
            .Where(name)
            .OrderBy(orderBy)
            .Select(fields)
            .ToListResultAsync(pageIndex, pageSize, cancellationToken));
 }
Example #3
0
        private void cboSortBy_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cboSortBy.SelectedValue.ToString() == UserSortOrder.UserName.ToString())
            {
                sortBy = UserSortOrder.UserName;
            }
            else if (cboSortBy.SelectedValue.ToString() == UserSortOrder.FirstName.ToString())
            {
                sortBy = UserSortOrder.FirstName;
            }
            else if (cboSortBy.SelectedValue.ToString() == UserSortOrder.LastName.ToString())
            {
                sortBy = UserSortOrder.LastName;
            }

            showList();
        }
		public static UsersIndexViewModel FromUsers(IPagedList<User> users, UserSortOrder currentSortOrder)
		{
			Contract.Requires(users != null);

			var items = users.Select(x => new UsersIndexViewModel.Item
			{
				Id            = x.Id,
				UserName      = x.UserName,
				RealName      = x.FullName,
				IsBanned      = x.IsBanned,
				BanExpiryTime = x.LockoutEndDateUtc.HasValue ? x.LockoutEndDateUtc.Value.ToLocalTime() : (DateTime?)null
			});

			return new UsersIndexViewModel
			{
				Users            = new StaticPagedList<UsersIndexViewModel.Item>(items, users),
				CurrentSortOrder = currentSortOrder
			};
		}
Example #5
0
 private void cboSortby_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     //code para lumabas ang Username,Lastname,Firstname sa ComboBox
     MessageBox.Show(cboSortby.SelectedValue.ToString());
     if (cboSortby.SelectedValue.ToString() == UserSortOrder.UserName.ToString())
     {
         sortby = UserSortOrder.UserName;
     }
     else if
     (cboSortby.SelectedValue.ToString() == UserSortOrder.FirstName.ToString())
     {
         sortby = UserSortOrder.FirstName;
     }
     else if
     (cboSortby.SelectedValue.ToString() == UserSortOrder.LastName.ToString())
     {
         sortby = UserSortOrder.LastName;
     }
     showList();
 }
Example #6
0
        public static Page <Users> Search(long pageSize = 3, long pageIndex = 1, UserSortOrder orderBy = UserSortOrder.UserName, SortOrder sortOrder = SortOrder.Ascending, Role?role = null, string keyword = "")
        {
            Page <Users> result = new Page <Users>();


            if (pageSize < 1)
            {
                pageSize = 1;
            }

            IQueryable <Users> userQuery = (IQueryable <Users>)db.User;

            if (role != null)
            {
                userQuery = userQuery.Where(u => u.Role == role.Value);
            }

            if (string.IsNullOrEmpty(keyword) == false)
            {
                userQuery = userQuery.Where(u => u.FirstName.Contains(keyword) ||
                                            u.LastName.Contains(keyword) ||
                                            u.UserName.Contains(keyword));
            }

            long queryCount = userQuery.Count();

            int  pageCount = (int)Math.Ceiling((decimal)(queryCount / pageSize));
            long mod       = (queryCount % pageSize);

            if (mod > 0)
            {
                pageCount = pageCount + 1;
            }

            int          skip = (int)(pageSize * (pageIndex - 1));
            List <Users> user = new List <Users>();

            if (sortOrder == SortOrder.Ascending && orderBy == UserSortOrder.UserName)
            {
                user = userQuery.OrderBy(u => u.UserName).ToList();
            }
            else if (sortOrder == SortOrder.Descending && orderBy == UserSortOrder.UserName)
            {
                user = userQuery.OrderByDescending(u => u.UserName).ToList();
            }
            else if (sortOrder == SortOrder.Ascending && orderBy == UserSortOrder.FirstName)
            {
                user = userQuery.OrderBy(u => u.FirstName).ToList();
            }
            else if (sortOrder == SortOrder.Descending && orderBy == UserSortOrder.FirstName)
            {
                user = userQuery.OrderByDescending(u => u.FirstName).ToList();
            }
            else if (sortOrder == SortOrder.Ascending && orderBy == UserSortOrder.LastName)
            {
                user = userQuery.OrderBy(u => u.LastName).ToList();
            }
            else if (sortOrder == SortOrder.Descending && orderBy == UserSortOrder.LastName)
            {
                user = userQuery.OrderByDescending(u => u.LastName).ToList();
            }

            result.Items      = user.Skip(skip).Take((int)pageSize).ToList();
            result.PageCount  = pageCount;
            result.PageSize   = pageSize;
            result.QueryCount = queryCount;

            return(result);
        }
Example #7
0
 public UserInfoComparer(UserSortOrder sortOrder)
     : this(sortOrder, false)
 {
 }
 Task<IPagedList<User>> IUserService.GetAllUsers(UserSortOrder sortOrder, int page, int usersPerPage)
 {
     throw new NotImplementedException();
 }
Example #9
0
 public EntityList<User> GetSync(
     int? userId = null, int? listId = null, UserFields fields = UserFields.Anything, UserSortOrder order = UserSortOrder.ById,  NameCase nameCase = NameCase.Nom, int? offset = null, int? count = 100
 ) {
     var task = _parent.Executor.ExecAsync(
             _parent._reqapi.Friends.Get(
                 userId,listId,fields,order,nameCase,offset, count
             )
         );
     task.Wait();
     return task.Result.Response;
 }
Example #10
0
 public async Task <EntityList<User>> Get(
     int? userId = null, int? listId = null, UserFields fields = UserFields.Anything, UserSortOrder order = UserSortOrder.ById,  NameCase nameCase = NameCase.Nom, int? offset = null, int? count = 100
 ) {
     return (
         await _parent.Executor.ExecAsync(
             _parent._reqapi.Friends.Get(
                 userId,listId,fields,order,nameCase,offset, count
             )
         ).ConfigureAwait(false)
     ).Response;
 }
Example #11
0
            public Request<int[]> GetOnline(
                int? userId = null, int? listId = null,  UserSortOrder? order = null, int? offset = null, int? count = 100
            ) {
                var req = new Request<int[]>{
                    MethodName = "friends.getOnline",
                    Parameters = new Dictionary<string, string> {

                        { "user_id", MiscTools.NullableString(userId)},
                        { "list_id", MiscTools.NullableString(listId)},
                        { "order", order?.ToNCString()?.ToSnake()??""},
                        { "offset", offset.NullableString() },
                        { "count", count.NullableString() },

                    }
                };
                if (_parent.IsLogged)
                    req.Token = _parent.CurrentToken;
                return req;
            }
Example #12
0
            public Request<EntityList<User>> Get(
                int? userId = null, int? listId = null, UserFields fields = UserFields.Anything, UserSortOrder order = UserSortOrder.ById,  NameCase nameCase = NameCase.Nom, int? offset = null, int? count = 100
            ) {
                var req = new Request<EntityList<User>>{
                    MethodName = "friends.get",
                    Parameters = new Dictionary<string, string> {

                        { "user_id", MiscTools.NullableString(userId)},
                        { "list_id", MiscTools.NullableString(listId)},
                        { "fields", String.Join( ",", MiscTools.GetUserFields( fields ) )},
                        { "order", order.ToNCString().ToSnake()},
                        { "name_case", nameCase.ToNCString().ToSnake()},
                        { "offset", offset.NullableString() },
                        { "count", count.NullableString() },

                    }
                };
                if (_parent.IsLogged)
                    req.Token = _parent.CurrentToken;
                return req;
            }
Example #13
0
 public async Task<string> Get(
     int? userId = null, int? listId = null,  UserSortOrder order = UserSortOrder.ById, int? offset = null, int? count = 100
 ){
     return await _parent.Executor.ExecRawAsync(
         _parent._reqapi.Friends.Get(
                userId,listId,order,offset, count
         )
     ).ConfigureAwait(false);
 }
Example #14
0
		public async Task<string> FriendsGetAsync(
			 uint? userId = null,
			 uint? listId = null,
			 UserFields fields = UserFields.None,
			 UserSortOrder order = UserSortOrder.ById,
			 NameCase nameCase = NameCase.Nom,
			 uint offset = 0,
			 uint count = 100
			){
			return await Executor.ExecRawAsync(
				_reqapi.FriendsGet(
											userId,
											listId,
											fields,
											order,
											nameCase,
											offset,
											count
									)
			);
		}
Example #15
0
 /// <summary>
 /// Finds a collection of users with the given values.
 /// </summary>
 /// <param name="name">The name for the item to be found.</param>
 /// <param name="orderBy">The order in which items are returned in a result set.</param>
 /// <param name="pageIndex">The index of the page of results to return. Use 1 to indicate the first page.</param>
 /// <param name="pageSize">The size of the page of results to return. <paramref name="pageIndex" /> is non-zero-based.</param>
 /// <param name="fields">The related fields to include in the query results.</param>
 /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
 /// <returns>
 /// A task that represents the asynchronous operation.
 /// </returns>
 public virtual Task <ListResult <UserItem> > FindAllAsync(string name, UserSortOrder orderBy, int pageIndex, int pageSize, UserField fields, CancellationToken cancellationToken)
 {
     ThrowIfDisposed();
     return(Store.FindAllAsync(name, orderBy, pageIndex, pageSize, fields, cancellationToken));
 }
Example #16
0
        /// <summary>
        /// Sorts the items of a sequence according to a key.
        /// </summary>
        public static IQueryable <IdentityUser> OrderBy(this IQueryable <IdentityUser> query, UserSortOrder orderBy)
        {
            if (orderBy == UserSortOrder.Recent)
            {
                return(query.OrderByDescending(user => user.LastLoginDate));
            }

            if (orderBy == UserSortOrder.Name)
            {
                return(query.OrderBy(user => user.Email.Name));
            }

            return(query.OrderBy(user => user.Id));
        }
Example #17
0
		public VKRequest<EntityList<User>> FriendsGet(
			 uint? userId = null,
			 uint? listId = null,
			 UserFields fields = UserFields.None,
			 UserSortOrder order = UserSortOrder.ById,
			 NameCase nameCase = NameCase.Nom,
			 uint offset = 0,
			 uint count = 100
			){
			var req = new VKRequest<EntityList<User>>{
				MethodName = "friends.get",
				Parameters = new Dictionary<string, string> {
					{ "user_id", MiscTools.NullableString(userId) },
			{ "list_id", MiscTools.NullableString(listId) },
			{ "fields", String.Join( ",", MiscTools.GetUserFields( fields ) ) },
			{ "order", order.ToNClString() },
			{ "name_case", nameCase.ToNClString() },
			{ "offset", offset.ToNCString() },
			{ "count", count.ToNCString() }
				}
			};
			if (IsLogged){
				req.Token = CurrentToken;
			}
			return req;
		}
Example #18
0
 public async Task <EntityList<int>> Get(
     int? userId = null, int? listId = null,  UserSortOrder order = UserSortOrder.ById, int? offset = null, int? count = 100
 ) {
     return (
         await _parent.Executor.ExecAsync(
             _parent._reqapi.Friends.Get(
                 userId,listId,order,offset, count
             )
         ).ConfigureAwait(false)
     ).Response;
 }
Example #19
0
		public async Task<EntityList<User>> FriendsGetAsync(
			 uint? userId = null,
			 uint? listId = null,
			 UserFields fields = UserFields.None,
			 UserSortOrder order = UserSortOrder.ById,
			 NameCase nameCase = NameCase.Nom,
			 uint offset = 0,
			 uint count = 100
			){
			return (await Executor.ExecAsync(
				_reqapi.FriendsGet(
											userId,
											listId,
											fields,
											order,
											nameCase,
											offset,
											count
									)
			)).Data.FirstOrDefault();
		}
Example #20
0
 public EntityList<int> GetSync(
     int? userId = null, int? listId = null,  UserSortOrder order = UserSortOrder.ById, int? offset = null, int? count = 100
 ) {
     var task = _parent.Executor.ExecAsync(
             _parent._reqapi.Friends.Get(
                 userId,listId,order,offset, count
             )
         );
     task.Wait();
     return task.Result.Response;
 }
Example #21
0
 public async Task <int[]> GetOnline(
     int? userId = null, int? listId = null,  UserSortOrder? order = null, int? offset = null, int? count = 100
 ) {
     return (
         await _parent.Executor.ExecAsync(
             _parent._reqapi.Friends.GetOnline(
                 userId,listId,order,offset, count
             )
         ).ConfigureAwait(false)
     ).Response;
 }
Example #22
0
 public int[] GetOnlineSync(
     int? userId = null, int? listId = null,  UserSortOrder? order = null, int? offset = null, int? count = 100
 ) {
     var task = _parent.Executor.ExecAsync(
             _parent._reqapi.Friends.GetOnline(
                 userId,listId,order,offset, count
             )
         );
     task.Wait();
     return task.Result.Response;
 }
Example #23
0
 public UserInfoComparer(UserSortOrder sortOrder, bool descending)
 {
     SortOrder  = sortOrder;
     Descending = descending;
 }
        public static Page <User> Search(long pageSize = 3, long pageIndex = 1, UserSortOrder orderBy = UserSortOrder.UserName, SortOrder sortOrder = SortOrder.Ascending, Role?role = null, string keyword = "")
        {
            Page <User> result = new Page <User>();

            if (pageSize < 1)
            {
                pageSize = 1;
            }


            //yung db.users ginawa nating userQuiry sa code na to,(List of users) (Filtering)
            IQueryable <User> userQuery = (IQueryable <User>)db.Users;

            //nagtatanong siya kung may role ka bang binigay sa kanyang role.. code sa search(Filtering)
            if (role != null)
            {
                userQuery = userQuery.Where(u => u.Role == role.Value);
            }
            //Filtering
            if (string.IsNullOrEmpty(keyword) == false)
            {
                userQuery = userQuery.Where(u => u.FirstName.Contains(keyword) ||
                                            u.LastName.Contains(keyword) ||
                                            u.UserName.Contains(keyword));
            }

            //code para sa page(Paging)
            long queryCount = userQuery.Count();
            long PageCount  = (long)Math.Ceiling((decimal)(queryCount / pageSize));
            long mod        = (queryCount % pageSize);

            if (mod > 0)
            {
                PageCount = PageCount + 1;
            }


            int         skip  = (int)(pageSize * (pageIndex - 1));
            List <User> users = new List <User>();

            if (sortOrder == SortOrder.Ascending && orderBy == UserSortOrder.UserName)
            {
                users = userQuery.OrderBy(u => u.UserName).ToList();
            }
            else if (sortOrder == SortOrder.Descending && orderBy == UserSortOrder.UserName)
            {
                users = userQuery.OrderByDescending(u => u.UserName).ToList();
            }
            else if (sortOrder == SortOrder.Ascending && orderBy == UserSortOrder.FirstName)
            {
                users = userQuery.OrderBy(u => u.FirstName).ToList();
            }
            else if (sortOrder == SortOrder.Descending && orderBy == UserSortOrder.FirstName)
            {
                users = userQuery.OrderByDescending(u => u.FirstName).ToList();
            }
            else if (sortOrder == SortOrder.Ascending && orderBy == UserSortOrder.LastName)
            {
                users = userQuery.OrderBy(u => u.LastName).ToList();
            }
            else if (sortOrder == SortOrder.Descending && orderBy == UserSortOrder.LastName)
            {
                users = userQuery.OrderByDescending(u => u.LastName).ToList();
            }



            result.Items      = users.Skip(skip).Take((int)pageSize).ToList();
            result.PageCount  = PageCount;
            result.PageSize   = pageSize;
            result.QueryCount = queryCount;
            return(result);
        }