Ejemplo n.º 1
0
        private static XmlElement CreatePagingNode(Paging pagingModel, XmlDocument doc)
        {
            XmlElement paging = doc.CreateElement("paging");
            XmlElement current = doc.CreateElement("current");
            current.InnerText = pagingModel.Current.ToString();
            XmlElement total = doc.CreateElement("total");
            total.InnerText = pagingModel.Total.ToString();
            XmlElement baseUrl = doc.CreateElement("baseUrl");
            baseUrl.InnerText = pagingModel.BaseUrl.ToString();
            XmlElement showNext = doc.CreateElement("showNext");
            showNext.InnerText = pagingModel.ShowNext.ToString();
            XmlElement showPrev = doc.CreateElement("showPrev");
            showPrev.InnerText = pagingModel.ShowPrev.ToString();
            XmlElement showFirst = doc.CreateElement("showFirst");
            showFirst.InnerText = pagingModel.ShowFirst.ToString();
            XmlElement showLast = doc.CreateElement("showLast");
            showLast.InnerText = pagingModel.ShowLast.ToString();

            XmlElement nextUrl = doc.CreateElement("nextUrl");
            nextUrl.InnerText = pagingModel.NextUrl.ToString();
            XmlElement prevUrl = doc.CreateElement("prevUrl");
            prevUrl.InnerText = pagingModel.PrevUrl.ToString();
            XmlElement firstUrl = doc.CreateElement("firstUrl");
            firstUrl.InnerText = pagingModel.FirstUrl.ToString();
            XmlElement lastUrl = doc.CreateElement("lastUrl");
            lastUrl.InnerText = pagingModel.LastUrl.ToString();

            paging.AppendChild(current);
            paging.AppendChild(showNext);
            paging.AppendChild(total);
            paging.AppendChild(showLast);
            paging.AppendChild(showFirst);
            paging.AppendChild(showPrev);

            paging.AppendChild(baseUrl);
            paging.AppendChild(nextUrl);
            paging.AppendChild(prevUrl);
            paging.AppendChild(firstUrl);
            paging.AppendChild(lastUrl);
            return paging;
        }
Ejemplo n.º 2
0
        public static Paging GetPagingModel(int page, int totalItems, int itemsPerPage, string baseUrl)
        {
            int totalPages = (totalItems - 1)/ itemsPerPage + 1;

            Paging paging = new Paging()
            {
                BaseUrl = baseUrl + "?page=",
                Current = page,
                Total = totalPages,
                ShowFirst = page != 1,
                FirstUrl = 1,
                ShowLast = page != totalPages,
                LastUrl = totalPages,
                ShowNext = page + 1 < totalPages,
                NextUrl = (page + 1),
                ShowPrev = page - 1 > 1,
                PrevUrl = (page - 1)
            };

            return paging;
        }
Ejemplo n.º 3
0
        public static XmlDocument WriteXML(IEnumerable<User> users, Paging pagingModel, UrlOptions options)
        {
            // Create the xml document container
            XmlDocument doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
            doc.AppendChild(dec);// Create the root element
            XmlElement root = doc.CreateElement("page");
            doc.AppendChild(root);

            XmlElement usersEl = CreateUsersListNode(users, doc);

            root.AppendChild(usersEl);

            XmlElement paging = CreatePagingNode(pagingModel, doc);

            root.AppendChild(paging);

            XmlElement updateUrl = doc.CreateElement("updateAction");
            updateUrl.InnerText = options.UpdateUrl;
            root.AppendChild(updateUrl);

            return doc;
        }