Ejemplo n.º 1
0
        public IEnumerable <UsersByRoutes> GetOwnPaged(PagingParameters param)
        {
            if (_context.Routes == null || _context.Routes.Count() == 0)
            {
                return(null);
            }

            var routesByUser = (from r in _context.Routes.Include("RouteVisit").Include("RelRouteUser")
                                join rr in _context.RelRouteUser on r.Id equals rr.IdRoute
                                where rr.IdUser == param.user
                                select r).Skip(param.pageIndex * param.pageSize).Take(param.pageSize).ToList();

            List <UsersByRoutes> usersByRoutes = new List <UsersByRoutes>();

            foreach (var item in routesByUser)
            {
                var flagUser     = false;
                var usersByRoute = (from rr in _context.RelRouteUser
                                    join u in _context.AspNetUsers on rr.IdUser equals u.Id
                                    where rr.IdRoute == item.Id
                                    select new User {
                    Id = rr.IdUser, UserName = u.UserName
                }).ToList();
                var favoritesUserFlag = _context.Favorites.Where(x => x.IdUser == param.user && item.Id == x.IdRoute).FirstOrDefault();

                if (favoritesUserFlag != null)
                {
                    flagUser = favoritesUserFlag.isFavorite;
                }
                var usersByRoutesModel = new UsersByRoutes {
                    Id = item.Id, PageTitle = item.PageTitle, isFavorite = flagUser, Users = usersByRoute, RedirectUrl = item.RedirectUrl, Route = item.Route, RelRouteUser = item.RelRouteUser, RouteVisit = item.RouteVisit, Status = item.Status
                };
                usersByRoutesModel.Exists = true;
                usersByRoutes.Add(usersByRoutesModel);
            }
            var usersByRoutesQuery = usersByRoutes.AsQueryable();

            if (!string.IsNullOrEmpty(param.sortOrder))
            {
                if (param.sortOrder == "VisitCount")
                {
                    if (param.sortAsc)
                    {
                        usersByRoutesQuery = usersByRoutesQuery.OrderBy(x => x.RouteVisit.Count);
                    }
                    else
                    {
                        usersByRoutesQuery = usersByRoutesQuery.OrderByDescending(x => x.RouteVisit.Count);
                    }
                }
            }

            return(usersByRoutes);
        }
Ejemplo n.º 2
0
        public IEnumerable <UsersByRoutes> GetRoutes()
        {
            List <UsersByRoutes> usersByRoutes = new List <UsersByRoutes>();
            var routes = _context.Routes.ToList();

            foreach (var item in routes)
            {
                var usersByRoutesQuery = (from rr in _context.RelRouteUser
                                          join u in _context.AspNetUsers on rr.IdUser equals u.Id
                                          where rr.IdRoute == item.Id
                                          select new User {
                    Id = rr.IdUser, UserName = u.UserName
                }).ToList();
                var usersByRoutesModel = new UsersByRoutes {
                    Id = item.Id, Users = usersByRoutesQuery, RedirectUrl = item.RedirectUrl, Route = item.Route, RelRouteUser = item.RelRouteUser, RouteVisit = item.RouteVisit, Status = item.Status
                };
                usersByRoutes.Add(usersByRoutesModel);
            }
            return(usersByRoutes);
        }
Ejemplo n.º 3
0
        public IEnumerable <UsersByRoutes> GetPaged(PagingParameters param)
        {
            if (_context.Routes == null || _context.Routes.Count() == 0)
            {
                return(null);
            }

            IQueryable <Routes>  routes        = _context.Routes.Include("RouteVisit").Where(o => !string.IsNullOrEmpty(param.filter) ? o.Route.StartsWith(param.filter) : true).Skip(param.pageIndex * param.pageSize).Take(param.pageSize);
            List <UsersByRoutes> usersByRoutes = new List <UsersByRoutes>();

            try
            {
                foreach (var item in routes)
                {
                    var usersByRoute = (from rr in _context.RelRouteUser
                                        join u in _context.AspNetUsers on rr.IdUser equals u.Id
                                        where rr.IdRoute == item.Id
                                        select new User {
                        Id = rr.IdUser, UserName = u.UserName
                    }).ToList();

                    var usersByRoutesModel = new UsersByRoutes {
                        Id = item.Id, PageTitle = item.PageTitle, isFavorite = null, Users = usersByRoute, RedirectUrl = item.RedirectUrl, Route = item.Route, RelRouteUser = item.RelRouteUser, RouteVisit = item.RouteVisit, Status = item.Status
                    };

                    if (param.role == "Admin")
                    {
                        usersByRoutesModel.Exists = true;
                        usersByRoutes.Add(usersByRoutesModel);
                    }
                    else
                    {
                        if (usersByRoutesModel.Users.Exists(x => x.Id == param.user))
                        {
                            usersByRoutesModel.Exists = true;
                        }
                        else
                        {
                            usersByRoutesModel.Exists = false;
                        }
                        usersByRoutes.Add(usersByRoutesModel);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            var usersByRoutesQuery = usersByRoutes.AsQueryable();

            if (!string.IsNullOrEmpty(param.sortOrder))
            {
                if (param.sortOrder == "VisitCount")
                {
                    if (param.sortAsc)
                    {
                        usersByRoutesQuery = usersByRoutesQuery.OrderBy(x => x.RouteVisit.Count);
                    }
                    else
                    {
                        usersByRoutesQuery = usersByRoutesQuery.OrderByDescending(x => x.RouteVisit.Count);
                    }
                }
            }

            return(usersByRoutesQuery);
        }