Esempio n. 1
0
        public List <Drive> SortingUser([FromBody] UserSort k)
        {
            string ss = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Drivers.xml");

            List <Driver> listaDrivers = xml.ReadDrivers(ss);
            List <Drive>  listaDrives  = k.Driv;//xml.ReadDrives(ss);
            List <Drive>  listaDrives1 = new List <Drive>();

            if (k.PoCemu == 0)
            {
                listaDrives1 = listaDrives.OrderByDescending(o => o.Comment.Rating).ToList();
            }
            else if (k.PoCemu == 1)
            {
                listaDrives1 = listaDrives.OrderByDescending(o => DateTime.Parse(o.DataAndTime)).ToList();
            }
            else if (k.PoCemu == 2)
            {
                Point po = new Point();
                foreach (Driver driv in listaDrivers)
                {
                    if (driv.UserName == k.Username)
                    {
                        po.X = Double.Parse(driv.Location.X);
                        po.Y = Double.Parse(driv.Location.Y);
                    }
                }

                ClosestDistance cd = new ClosestDistance();
                listaDrives1 = cd.OrderByDistanceForDrivers(listaDrives, po);
            }

            return(listaDrives1);
        }
        public List<User> qryTester(UserSort sortby)
        {

            Builder b = new Builder();

            //Test searching users
            List<User> users = b.queryUsers(minAge: 20, maxAge: 50, gender: false, InterestedIn: true, address:"", SearcherID: "1", sortBy: 0);
            return users;

        }
Esempio n. 3
0
        public FilterResult <User> Query(FilterState filterState)
        {
            var result = new FilterResult <User>();
            IQueryable <User> query = Context.Users;

            if (filterState != null)
            {
                // Filtering
                if (filterState.Filter?.Filters != null)
                {
                    var filter = new UserFilter();
                    if (filterState.Filter.Logic.ToLower() == "and")
                    {
                        filter.CompositeFilter(filterState.Filter, ref query);
                    }
                    else
                    {
                        throw new NotImplementedException("Logic not handled");
                    }
                }

                // Sorting
                if (filterState.Sort != null)
                {
                    foreach (var sort in filterState.Sort)
                    {
                        var purchaseOrderSort = new UserSort();
                        purchaseOrderSort.Sort(sort, ref query);
                    }
                }

                if (filterState.Take > 0)
                {
                    // Pagination
                    var x = query
                            .Skip(filterState.Skip)
                            .Take(filterState.Take)
                            .ToList();
                    result.Data = x;
                }
                else
                {
                    result.Data = query.ToList();
                }
            }
            else
            {
                result.Data = query.ToList();
            }

            // Get total records count
            result.Total = query.Count();

            return(result);
        }
Esempio n. 4
0
        public async Task <UsersResponseResult> ListByPhoneNumber([FromQuery] UserSort userSort,
                                                                  [FromQuery][Required] string phoneNumber)
        {
            try
            {
                int pageSize2 = 20;
                if (userSort.PageSize.HasValue)
                {
                    pageSize2 = userSort.PageSize.Value;
                }

                IQueryable <ApplicationUser> users = this._userManager.Users.Where(
                    m => !string.IsNullOrEmpty(m.PhoneNumber) &&
                    m.PhoneNumber.Contains(phoneNumber, StringComparison.InvariantCultureIgnoreCase));

                if (userSort != null && !string.IsNullOrEmpty(userSort.SortBy) &&
                    userSort.SortBy.Equals(UserSort.SORT_BY_EMAIL, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (userSort != null && (userSort.OrderType.HasValue && userSort.OrderType.Value != 0))
                    {
                        users = users.OrderByDescending(m => m.Email);
                    }
                    else
                    {
                        users = users.OrderBy(m => m.Email);
                    }
                }
                else
                {
                    if (userSort != null && (userSort.OrderType.HasValue && userSort.OrderType.Value != 0))
                    {
                        users = users.OrderByDescending(m => m.UserName);
                    }
                    else
                    {
                        users = users.OrderBy(m => m.UserName);
                    }
                }

                return(new UsersResponseResult()
                {
                    Code = 200,
                    Data = users.Skip((userSort.PageIndex - 1) * pageSize2).Take(pageSize2)
                           .ToArray()
                });
            }
            catch (Exception ex)
            {
                return(new UsersResponseResult()
                {
                    Code = 500,
                    Message = ex.Message,
                });
            }
        }
Esempio n. 5
0
 public virtual void GetUsers(Action<IPagedList<User>> onSuccess, Action<ApiException> onError = null, UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, int? page = null, int? pageSize = null, string filter = null)
 {
     MakeRequest<UserResponse>("users", null, new
     {
         key = apiKey,
         page = page ?? null,
         pagesize = pageSize ?? null,
         filter = filter,
         sort = sortBy.ToString().ToLower(),
         order = GetSortDirection(sortDirection)
     }, (items) => onSuccess(new PagedList<User>(items.Users, items)), onError);
 }
Esempio n. 6
0
        /// <summary>
        /// Retrieves a list of user objects
        /// </summary>
        /// <param name="page">
        /// The requested page from the server. This is an optional argument
        /// and if omitted the server will default to returning the first page
        /// with a maximum of <c>100</c> items.
        /// </param>
        /// <param name="filter">
        /// A filter object to filter the user objects on the server. If
        /// omitted, the server will return all objects as a paginated response.
        /// </param>
        /// <param name="sort">
        /// A sort definition object to sort the user objects on supported
        /// properties. If omitted objects are returned in the order as they
        /// were created in.
        /// </param>
        /// <returns>A paginated list of users</returns>
        public UserList GetUsers(
            PageInput page    = null,
            UserFilter filter = null,
            UserSort sort     = null)
        {
            // setup parameters
            GraphQLParameters parameters = new GraphQLParameters();

            parameters.Add("page", page, true);
            parameters.Add("filter", filter, true);
            parameters.Add("sort", sort, true);

            return(RunQuery <UserList>(@"getUsers", parameters));
        }
        public static void qryTester(UserSort sortby)
        {

            Builder b = new Builder();

            //Test searching users
    
            List<User> users = b.queryUsers(minAge: 20, maxAge: 30, gender: true, InterestedIn: false, address: "", SearcherID: "1", sortBy: 0);
            foreach (User user in users)
            {
                Console.WriteLine(user.FirstName + " " + user.LastName);
            }

        }
Esempio n. 8
0
 public virtual IPagedList<User> GetModerators(int? page = null, int? pageSize = null, UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, string filter = null, DateTime? fromDate = null, DateTime? toDate = null)
 {
     var response = MakeRequest<UserResponse>("users", new string[] { "moderators" }, new
     {
         key = apiKey,
         page = page ?? null,
         pagesize = pageSize ?? null,
         filter = filter,
         sort = sortBy.ToString().ToLower(),
         order = GetSortDirection(sortDirection),
         fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
         todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null
     });
     return new PagedList<User>(response.Users, response);
 }
Esempio n. 9
0
        public virtual IPagedList <User> GetUsers(UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, int?page = null, int?pageSize = null, string filter = null, DateTime?fromDate = null, DateTime?toDate = null, int?min = null, int?max = null)
        {
            var response = MakeRequest <UserResponse>("users", null, new
            {
                key      = apiKey,
                page     = page ?? null,
                pagesize = pageSize ?? null,
                filter   = filter,
                sort     = sortBy.ToString().ToLower(),
                order    = GetSortDirection(sortDirection),
                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
                todate   = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
                min      = min ?? null,
                max      = max ?? null
            });

            return(new PagedList <User>(response.Users, response));
        }
Esempio n. 10
0
        public async Task <ActionResult> Index(UserSort sortOrder = UserSort.NameAsc)
        {
            IQueryable <User> users = _userManager.Users;

            ViewData["NameSort"]   = sortOrder == UserSort.NameAsc ? UserSort.NameDesc : UserSort.NameAsc;
            ViewData["StatusSort"] = sortOrder == UserSort.StatusAsc ? UserSort.StatusDesc : UserSort.StatusAsc;
            ViewData["RoleSort"]   = sortOrder == UserSort.RoleAsc ? UserSort.RoleDesc : UserSort.RoleAsc;
            ViewData["BlockSort"]  = sortOrder == UserSort.BlockAsc ? UserSort.BlockDesc : UserSort.BlockAsc;

            users = sortOrder switch
            {
                UserSort.NameDesc => users.OrderByDescending(s => s.UserName),
                UserSort.StatusAsc => users.OrderBy(s => s.Status),
                UserSort.StatusDesc => users.OrderByDescending(s => s.Status),
                UserSort.RoleAsc => users.OrderBy(s => s.Role),
                UserSort.RoleDesc => users.OrderByDescending(s => s.Role),
                UserSort.BlockAsc => users.OrderBy(s => s.Block),
                UserSort.BlockDesc => users.OrderByDescending(s => s.Block),
                _ => users.OrderBy(s => s.UserName),
            };
            string role = null;

            if (User.Identity.Name != null)
            {
                User user = await _userManager.FindByNameAsync(User.Identity.Name);

                role = user.Role;
            }
            UsersViewModel model = new UsersViewModel
            {
                Users = await users.AsNoTracking().ToListAsync(),
                Role  = role,
            };

            return(View(model));
        }
Esempio n. 11
0
 public virtual void GetModerators(Action <IPagedList <User> > onSuccess, Action <ApiException> onError, int?page = null, int?pageSize = null, UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, string filter = null, DateTime?fromDate = null, DateTime?toDate = null)
 {
     MakeRequest <UserResponse>("users", new string[] { "moderators" }, new
     {
         key      = apiKey,
         page     = page ?? null,
         pagesize = pageSize ?? null,
         filter   = filter,
         sort     = sortBy.ToString().ToLower(),
         order    = GetSortDirection(sortDirection),
         fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
         todate   = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null
     }, (response) => onSuccess(new PagedList <User>(response.Users, response)), onError);
 }
Esempio n. 12
0
 public virtual void GetUsers(Action <IPagedList <User> > onSuccess, Action <ApiException> onError, UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, int?page = null, int?pageSize = null, string filter = null)
 {
     MakeRequest <UserResponse>("users", null, new
     {
         key      = apiKey,
         page     = page ?? null,
         pagesize = pageSize ?? null,
         filter   = filter,
         sort     = sortBy.ToString().ToLower(),
         order    = GetSortDirection(sortDirection)
     }, (items) => onSuccess(new PagedList <User>(items.Users, items)), onError);
 }
Esempio n. 13
0
 public virtual void GetModerators(Action<IPagedList<User>> onSuccess, Action<ApiException> onError, int? page = null, int? pageSize = null, UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, string filter = null, DateTime? fromDate = null, DateTime? toDate = null)
 {
     MakeRequest<UserResponse>("users", new string[] { "moderators" }, new
     {
         key = apiKey,
         page = page ?? null,
         pagesize = pageSize ?? null,
         filter = filter,
         sort = sortBy.ToString().ToLower(),
         order = GetSortDirection(sortDirection),
         fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
         todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null
     }, (response) => onSuccess(new PagedList<User>(response.Users, response)), onError);
 }
        public List<User> queryUsers(int minAge, int maxAge, bool gender, bool InterestedIn, string address, string SearcherID, UserSort sortBy)
        {
            string qryStr;
            string excludeQry = "select ToID from dbo.Connections where FromID ='" + SearcherID + "' and (isRemoved=1 or isBlocked=1)";
            string filteredUsers =
                "SELECT u.ID from dbo.Users as u where u.Deleted=0 " +
                 " and u.ID!='" + SearcherID + "' and u.Age >=" + minAge + " and u.Age<=" + maxAge +
              " and u.Gender = " + Convert.ToInt32(gender) + " and u.InterestedIn= " + Convert.ToInt32(InterestedIn) +" and u.ID not in (" + excludeQry +")";

            if (address!="") filteredUsers = filteredUsers+ " and u.Address = '" + address + "'";



                 string  defaultStr = "Select * from dbo.Users WHERE dbo.Users.ID in (" + filteredUsers + ")";
            //get the user's likes list, count the likes match for every result, and sort by top match
            using (var dbContext = new YATContext())
            {
                switch (sortBy) // Sort according to criterion
                {
                   case UserSort.Match: //sort by most mutual likes
                        qryStr = "Select * from dbo.Users inner join " +
                                "(select filteredUsers.ID,count(filteredUsers.ID) as score from " +
                             " ( " + filteredUsers + ")" +
                              " as filteredUsers " +
                                      "left join" +
                             "(SELECT dbo.LikesUsers.user_ID, dbo.LikesUsers.Likes_Id from   dbo.LikesUsers where " +
                                    "dbo.LikesUsers.Likes_Id in " +
                                    "(SELECT dbo.LikesUsers.Likes_ID from   dbo.LikesUsers where " +
                                                                  " dbo.LikesUsers.User_ID='" + SearcherID  + "')) as movies " +
                                                                        " on filteredUsers.ID = movies.User_Id " +
                                                                              "GROUP by filteredUsers.ID) as results on results.ID=dbo.Users.ID order by score";
                    break;
                    case UserSort.LastLog:
                    qryStr = defaultStr + 
                              " order by LastLoginDate desc";
                    break;
                    case UserSort.LastJoin:  
                    qryStr = defaultStr + 
                              " order by RegistrationDate desc";
                    break;
                    default:
                    qryStr = defaultStr; 
                    break;
                }
            
           List<User> users = dbContext.User.SqlQuery(qryStr).ToList();
           return users;
            }
        }