Ejemplo n.º 1
0
        public ActionResult List(string logLevel = null, int page = 1)
        {
            IPagination <Log> results;

            if (logLevel == null)
            {
                if (page < 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1 }));
                }

                IQueryable <Log> query = _logService.GetAllLogs().OrderByDescending(l => l.LogDate);

                results = new LazyPagination <Log>(query, page,
                                                   Constants.RecordPerPage);

                if (!results.Any() && page != 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1 }));
                }
            }
            else
            {
                LogLevel level;

                if (!ExtractLogLevel(logLevel, out level))
                {
                    return(NotFoundView());
                }

                if (page < 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1, logLevel = level }));
                }

                IQueryable <Log> query = _logService.GetAllLogsByLevel(new[] { level }).OrderByDescending(l => l.LogDate);

                results =
                    new LazyPagination <Log>(query,
                                             page,
                                             Constants.RecordPerPage);

                if (!results.Any() && page != 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1, logLevel = level }));
                }

                ViewBag.LogLevel = level;
            }

            return(ViewOrPartialView(results));
        }
Ejemplo n.º 2
0
        public ActionResult List(int page = 1)
        {
            if (page < 1)
            {
                return(RedirectToActionPermanent("List", new { page = 1 }));
            }

            var results = new LazyPagination <Role>(_roleService.GetAllRoles().OrderBy(c => c.Id), page,
                                                    Constants.RecordPerPage);

            if (!results.Any() && page != 1)
            {
                return(RedirectToActionPermanent("List", new { page = 1 }));
            }

            return(ViewOrPartialView(results));
        }
Ejemplo n.º 3
0
        public ActionResult List(int?ownerId, int page = 1)
        {
            if (page < 1 || (ownerId.HasValue && ownerId < 1))
            {
                if (ownerId > 0)
                {
                    return(RedirectToActionPermanent("List", new { page = 1, ownerId }));
                }
                return(RedirectToActionPermanent("List", new { page = 1 }));
            }

            IQueryable <Comment> query;

            if (ownerId.HasValue)
            {
                query = _commentService.GetAllCommentsByOwnerId(ownerId.Value).OrderBy(c => c.Id);
            }
            else
            {
                query = _commentService.GetAllComments().OrderBy(c => c.Id);
            }

            ExcludeNotRealatedRecords(ref query);

            var results =
                new LazyPagination <Comment>(query, page, Constants.RecordPerPage);

            if (!results.Any() && page != 1)
            {
                return(RedirectToActionPermanent("List", new { page = 1 }));
            }

            ViewBag.OwnerId = ownerId;

            return(ViewOrPartialView(results));
        }
Ejemplo n.º 4
0
        public ActionResult List(int?parentId = null, int page = 1, int recordPerPage = Constants.RecordPerPage)
        {
            IPagination <File> results;

            if (parentId == null)
            {
                if (page < 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1 }));
                }

                IQueryable <File> query = _fileService.GetAllFiles();

                ExcludeNotRealatedRecords(ref query);

                query = query.OrderBy(c => c.Id).AsQueryable();

                results = new LazyPagination <File>(query, page,
                                                    recordPerPage);

                if (!results.Any() && page != 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1 }));
                }
            }
            else
            {
                File parent = _fileService.GetFileById(parentId.Value);

                if (parent == null)
                {
                    return(NotFoundView());
                }

                if (page < 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1, parentId }));
                }

                IQueryable <File> query = _fileService.GetAllFilesByParentId(parent.Id);

                ExcludeNotRealatedRecords(ref query);

                query = query.OrderBy(c => c.Id).AsQueryable();

                results =
                    new LazyPagination <File>(query,
                                              page,
                                              recordPerPage);

                if (!results.Any() && page != 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1, parentId }));
                }

                ViewBag.Parent = parent;
            }

            ViewBag.RecordPerPage = recordPerPage;

            return(ViewOrPartialView(results));
        }
Ejemplo n.º 5
0
        public ActionResult List(string contentType = null, int page = 1, int recordPerPage = Constants.RecordPerPage)
        {
            IPagination <Content> results;

            if (contentType == null)
            {
                if (page < 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1 }));
                }

                IQueryable <Content> query = _contentService.GetAllContents();

                ExcludeNotRealatedRecords(ref query);

                query = query.OrderBy(c => c.Id).AsQueryable();

                results = new LazyPagination <Content>(query, page,
                                                       recordPerPage);

                if (!results.Any() && page != 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1 }));
                }
            }
            else
            {
                ContentType type;

                if (!ExtractContentType(contentType, out type))
                {
                    return(NotFoundView());
                }

                if (page < 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1, contentType = type }));
                }

                IQueryable <Content> query = _contentService.GetAllContentsByTypes(new[] { type });

                ExcludeNotRealatedRecords(ref query);

                query = query.OrderBy(c => c.Id).AsQueryable();

                results =
                    new LazyPagination <Content>(query,
                                                 page,
                                                 recordPerPage);

                if (!results.Any() && page != 1)
                {
                    return(RedirectToActionPermanent("List", new { page = 1, contentType = type }));
                }

                ViewBag.ContentType = type;
            }

            ViewBag.RecordPerPage = recordPerPage;

            return(ViewOrPartialView(results));
        }