Ejemplo n.º 1
0
        public PageView <AccountView> Render(PageRendererArgs <AccountModel> source, int?libraryId = null)
        {
            var page = new PageView <AccountView>(source.Page.TotalCount, source.Page.PageSize, source.Page.PageNumber)
            {
                Data = source.Page.Data?.Select(x => Render(x, libraryId))
            };

            var links = new List <LinkView>
            {
                _linkRenderer.Render(new Link {
                    ActionName  = nameof(AccountsController.GetAll),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Self,
                    QueryString = new Dictionary <string, string>()
                    {
                        { "pageNumber", page.CurrentPageIndex.ToString() },
                        { "pageSize", page.PageSize.ToString() },
                        { "query", source.RouteArguments.Query }
                    }
                })
            };

            if (_userHelper.IsAdmin && libraryId.HasValue)
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName = nameof(AccountsController.InviteUser),
                    Method     = HttpMethod.Post,
                    Rel        = RelTypes.Create,
                    Parameters = new { libraryId = libraryId.Value }
                }));
            }

            if (page.CurrentPageIndex < page.PageCount)
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(AccountsController.GetAll),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Next,
                    QueryString = new Dictionary <string, string>()
                    {
                        { "pageNumber", (page.CurrentPageIndex + 1).ToString() },
                        { "pageSize", page.PageSize.ToString() },
                        { "query", source.RouteArguments.Query }
                    }
                }));
            }

            if (page.PageCount > 1 && page.CurrentPageIndex > 1 && page.CurrentPageIndex <= page.PageCount)
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(AccountsController.GetAll),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Previous,
                    QueryString = new Dictionary <string, string>()
                    {
                        { "pageNumber", (page.CurrentPageIndex - 1).ToString() },
                        { "pageSize", page.PageSize.ToString() },
                        { "query", source.RouteArguments.Query }
                    }
                }));
            }

            page.Links = links;
            return(page);
        }
Ejemplo n.º 2
0
        public PageView <BookPageView> Render(PageRendererArgs <BookPageModel, BookPageFilter> source, int libraryId, int bookId)
        {
            var page = new PageView <BookPageView>(source.Page.TotalCount, source.Page.PageSize, source.Page.PageNumber)
            {
                Data = source.Page.Data?.Select(x => Render(x, libraryId))
            };

            Dictionary <string, string> query = CreateQueryString(source, page);

            query.Add("pageNumber", (page.CurrentPageIndex).ToString());

            var links = new List <LinkView>();

            links.Add(_linkRenderer.Render(new Link
            {
                ActionName  = nameof(BookPageController.GetPagesByBook),
                Method      = HttpMethod.Get,
                Rel         = RelTypes.Self,
                Parameters  = new { libraryId = libraryId, bookId = bookId },
                QueryString = query
            }));

            if (_userHelper.IsWriter(libraryId) || _userHelper.IsAdmin || _userHelper.IsLibraryAdmin(libraryId))
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName = nameof(BookPageController.CreatePage),
                    Method     = HttpMethod.Post,
                    Rel        = RelTypes.Create,
                    Parameters = new { libraryId = libraryId, bookId = bookId }
                }));

                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName = nameof(BookPageController.UploadPages),
                    Method     = HttpMethod.Post,
                    Rel        = RelTypes.MultiCreate,
                    Parameters = new { libraryId = libraryId, bookId = bookId }
                }));
            }

            if (page.CurrentPageIndex < page.PageCount)
            {
                var pageQuery = CreateQueryString(source, page);
                pageQuery.Add("pageNumber", (page.CurrentPageIndex + 1).ToString());

                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(BookPageController.GetPagesByBook),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Next,
                    Parameters  = new { libraryId = libraryId, bookId = bookId },
                    QueryString = pageQuery
                }));
            }

            if (page.PageCount > 1 && page.CurrentPageIndex > 1 && page.CurrentPageIndex <= page.PageCount)
            {
                var pageQuery = CreateQueryString(source, page);
                pageQuery.Add("pageNumber", (page.CurrentPageIndex - 1).ToString());
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(BookPageController.GetPagesByBook),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Previous,
                    Parameters  = new { libraryId = libraryId, bookId = bookId },
                    QueryString = pageQuery
                }));
            }

            page.Links = links;
            return(page);
        }
Ejemplo n.º 3
0
        public PageView <LibraryView> Render(PageRendererArgs <LibraryModel> source)
        {
            var page = new PageView <LibraryView>(source.Page.TotalCount, source.Page.PageSize, source.Page.PageNumber)
            {
                Data = source.Page.Data?.Select(x => Render(x))
            };

            var queryString = new Dictionary <string, string>()
            {
                { "pageNumber", page.CurrentPageIndex.ToString() },
                { "pageSize", page.PageSize.ToString() },
                { "query", source.RouteArguments.Query }
            };

            if (source.RouteArguments.AccountId.HasValue)
            {
                queryString.Add("accountId", source.RouteArguments.AccountId.Value.ToString());
            }

            var links = new List <LinkView>
            {
                _linkRenderer.Render(new Link {
                    ActionName  = nameof(LibraryController.GetLibraries),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Self,
                    Parameters  = new object(),
                    QueryString = queryString
                })
            };

            if (_userHelper.IsAdmin)
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName = nameof(LibraryController.CreateLibrary),
                    Method     = HttpMethod.Post,
                    Rel        = RelTypes.Create
                }));
            }

            if (page.CurrentPageIndex < page.PageCount)
            {
                var queryStringNext = new Dictionary <string, string>()
                {
                    { "pageNumber", (page.CurrentPageIndex + 1).ToString() },
                    { "pageSize", page.PageSize.ToString() },
                    { "query", source.RouteArguments.Query }
                };

                if (source.RouteArguments.AccountId.HasValue)
                {
                    queryStringNext.Add("accountId", source.RouteArguments.AccountId.Value.ToString());
                }

                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(LibraryController.GetLibraries),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Next,
                    Parameters  = new object(),
                    QueryString = queryStringNext
                }));
            }

            if (page.PageCount > 1 && page.CurrentPageIndex > 1 && page.CurrentPageIndex <= page.PageCount)
            {
                var queryStringPrev = new Dictionary <string, string>()
                {
                    { "pageNumber", (page.CurrentPageIndex - 1).ToString() },
                    { "pageSize", page.PageSize.ToString() },
                    { "query", source.RouteArguments.Query }
                };

                if (source.RouteArguments.AccountId.HasValue)
                {
                    queryStringPrev.Add("accountId", source.RouteArguments.AccountId.Value.ToString());
                }

                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(LibraryController.GetLibraries),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Previous,
                    QueryString = queryStringPrev
                }));
            }

            page.Links = links;
            return(page);
        }
Ejemplo n.º 4
0
        public PageView <PeriodicalView> Render(PageRendererArgs <PeriodicalModel> source, int libraryId)
        {
            var page = new PageView <PeriodicalView>(source.Page.TotalCount, source.Page.PageSize, source.Page.PageNumber)
            {
                Data = source.Page.Data?.Select(x => Render(x, libraryId))
            };

            var links = new List <LinkView>
            {
                _linkRenderer.Render(new Link {
                    ActionName  = nameof(PeriodicalController.GetPeriodicals),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Self,
                    Parameters  = new { libraryId = libraryId },
                    QueryString = new Dictionary <string, string>()
                    {
                        { "pageNumber", page.CurrentPageIndex.ToString() },
                        { "pageSize", page.PageSize.ToString() },
                        { "query", source.RouteArguments.Query }
                    }
                })
            };

            if (_userHelper.IsWriter(libraryId) || _userHelper.IsAdmin || _userHelper.IsLibraryAdmin(libraryId))
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName = nameof(PeriodicalController.CreatePeriodical),
                    Method     = HttpMethod.Post,
                    Rel        = RelTypes.Create,
                    Parameters = new { libraryId = libraryId }
                }));
            }

            if (page.CurrentPageIndex < page.PageCount)
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(PeriodicalController.GetPeriodicals),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Next,
                    Parameters  = new { libraryId = libraryId },
                    QueryString = new Dictionary <string, string>()
                    {
                        { "pageNumber", (page.CurrentPageIndex + 1).ToString() },
                        { "pageSize", page.PageSize.ToString() },
                        { "query", source.RouteArguments.Query }
                    }
                }));
            }

            if (page.PageCount > 1 && page.CurrentPageIndex > 1 && page.CurrentPageIndex <= page.PageCount)
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(PeriodicalController.GetPeriodicals),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Previous,
                    Parameters  = new { libraryId = libraryId },
                    QueryString = new Dictionary <string, string>()
                    {
                        { "pageNumber", (page.CurrentPageIndex - 1).ToString() },
                        { "pageSize", page.PageSize.ToString() },
                        { "query", source.RouteArguments.Query }
                    }
                }));
            }

            page.Links = links;
            return(page);
        }
Ejemplo n.º 5
0
        public PageView <CorrectionView> Render(PageRendererArgs <CorrectionModel> source, string language, string profile)
        {
            var page = new PageView <CorrectionView>(source.Page.TotalCount, source.Page.PageSize, source.Page.PageNumber)
            {
                Data = source.Page.Data?.Select(x => Render(x))
            };

            var links = new List <LinkView>
            {
                _linkRenderer.Render(new Link {
                    ActionName  = nameof(ToolController.GetCorrections),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Self,
                    Parameters  = new { language = language, profile = profile },
                    QueryString = new Dictionary <string, string>()
                    {
                        { "pageNumber", page.CurrentPageIndex.ToString() },
                        { "pageSize", page.PageSize.ToString() },
                        { "query", source.RouteArguments.Query }
                    }
                })
            };

            if (_userHelper.IsAdmin)
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName = nameof(ToolController.AddCorrection),
                    Method     = HttpMethod.Post,
                    Rel        = RelTypes.Create,
                    Parameters = new { language = language, profile = profile }
                }));
            }

            if (page.CurrentPageIndex < page.PageCount)
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(ToolController.GetCorrections),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Next,
                    Parameters  = new { language = language, profile = profile },
                    QueryString = new Dictionary <string, string>()
                    {
                        { "pageNumber", (page.CurrentPageIndex + 1).ToString() },
                        { "pageSize", page.PageSize.ToString() },
                        { "query", source.RouteArguments.Query }
                    }
                }));
            }

            if (page.PageCount > 1 && page.CurrentPageIndex > 1 && page.CurrentPageIndex <= page.PageCount)
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName  = nameof(ToolController.GetCorrections),
                    Method      = HttpMethod.Get,
                    Rel         = RelTypes.Previous,
                    Parameters  = new { language = language, profile = profile },
                    QueryString = new Dictionary <string, string>()
                    {
                        { "pageNumber", (page.CurrentPageIndex - 1).ToString() },
                        { "pageSize", page.PageSize.ToString() },
                        { "query", source.RouteArguments.Query }
                    }
                }));
            }

            page.Links = links;
            return(page);
        }