JSON trash object
예제 #1
0
        /// <summary>
        /// Paged list of deleted objects
        /// </summary>
        /// <param name="trashType">Type of delted object</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="page">Page number</param>
        /// <returns></returns>
        public static List <JsonTrash> GetTrash(TrashType trashType)
        {
            var comments = new List <Comment>();
            var posts    = new List <Post>();
            var pages    = new List <Page>();

            var trashList = new List <JsonTrash>();

            // comments
            if (trashType == TrashType.All || trashType == TrashType.Comment)
            {
                foreach (var p in Post.Posts)
                {
                    comments.AddRange(p.DeletedComments);
                }
            }

            if (comments.Count > 0)
            {
                foreach (var c in comments)
                {
                    JsonTrash t1 = new JsonTrash {
                        Id         = c.Id,
                        Title      = c.Title,
                        ObjectType = "Comment",
                        Date       = c.DateCreated.ToString("dd MMM yyyy"),
                        Time       = c.DateCreated.ToString("t")
                    };

                    trashList.Add(t1);
                }
            }

            // posts
            if (trashType == TrashType.All || trashType == TrashType.Post)
            {
                posts = (from x in Post.DeletedPosts orderby x.DateCreated descending select x).ToList();
            }

            if (posts.Count > 0)
            {
                foreach (var p in posts)
                {
                    JsonTrash t2 = new JsonTrash
                    {
                        Id         = p.Id,
                        Title      = p.Title,
                        ObjectType = "Post",
                        Date       = p.DateCreated.ToString("dd MMM yyyy"),
                        Time       = p.DateCreated.ToString("t")
                    };

                    trashList.Add(t2);
                }
            }

            // pages
            if (trashType == TrashType.All || trashType == TrashType.Page)
            {
                pages = (from x in Page.DeletedPages orderby x.DateCreated descending select x).ToList();
            }

            if (pages.Count > 0)
            {
                foreach (var p in pages)
                {
                    JsonTrash t3 = new JsonTrash
                    {
                        Id         = p.Id,
                        Title      = p.Title,
                        ObjectType = "Page",
                        Date       = p.DateCreated.ToString("dd MMM yyyy"),
                        Time       = p.DateCreated.ToString("t")
                    };

                    trashList.Add(t3);
                }
            }

            return(trashList);
        }
예제 #2
0
        /// <summary>
        /// Paged list of deleted objects
        /// </summary>
        /// <param name="trashType">Type of delted object</param>
        /// <param name="page">Page number</param>
        /// <returns></returns>
        public static List <JsonTrash> GetTrash(TrashType trashType, int page)
        {
            var comments = new List <Comment>();
            var posts    = new List <Post>();
            var pages    = new List <Page>();

            var trashList = new List <JsonTrash>();

            currentPage = page;

            // comments
            if (trashType == TrashType.All || trashType == TrashType.Comment)
            {
                foreach (var p in Post.Posts)
                {
                    comments.AddRange(p.DeletedComments);
                }
            }

            if (comments.Count > 0)
            {
                foreach (var c in comments)
                {
                    JsonTrash t1 = new JsonTrash {
                        Id         = c.Id,
                        Title      = c.Title,
                        ObjectType = "Comment",
                        Date       = c.DateCreated.ToString("dd MMM yyyy"),
                        Time       = c.DateCreated.ToString("t")
                    };

                    trashList.Add(t1);
                }
            }

            // posts
            if (trashType == TrashType.All || trashType == TrashType.Post)
            {
                posts = (from x in Post.DeletedPosts orderby x.DateCreated descending select x).ToList();
            }

            if (posts.Count > 0)
            {
                foreach (var p in posts)
                {
                    JsonTrash t2 = new JsonTrash
                    {
                        Id         = p.Id,
                        Title      = System.Web.HttpContext.Current.Server.HtmlEncode(p.Title),
                        ObjectType = "Post",
                        Date       = p.DateCreated.ToString("dd MMM yyyy"),
                        Time       = p.DateCreated.ToString("t")
                    };

                    trashList.Add(t2);
                }
            }

            // pages
            if (trashType == TrashType.All || trashType == TrashType.Page)
            {
                pages = (from x in Page.DeletedPages orderby x.DateCreated descending select x).ToList();
            }

            if (pages.Count > 0)
            {
                foreach (var p in pages)
                {
                    JsonTrash t3 = new JsonTrash
                    {
                        Id         = p.Id,
                        Title      = System.Web.HttpContext.Current.Server.HtmlEncode(p.Title),
                        ObjectType = "Page",
                        Date       = p.DateCreated.ToString("dd MMM yyyy"),
                        Time       = p.DateCreated.ToString("t")
                    };

                    trashList.Add(t3);
                }
            }

            var pageSize = 20;

            listCount = trashList.Count;

            if (trashList.Count < pageSize)
            {
                return(trashList);
            }

            var skip      = page == 1 ? 0 : page * pageSize - pageSize;
            var trashPage = trashList.Skip(skip).Take(pageSize).ToList();

            return(trashPage);
        }
        /// <summary>
        /// Paged list of deleted objects
        /// </summary>
        /// <param name="trashType">Type of delted object</param>
        /// <param name="page">Page number</param>
        /// <returns></returns>
        public static List<JsonTrash> GetTrash(TrashType trashType, int page)
        {
            var comments = new List<Comment>();
            var posts = new List<Post>();
            var pages = new List<Page>();

            var trashList = new List<JsonTrash>();
            currentPage = page;

            // comments
            if (trashType == TrashType.All || trashType == TrashType.Comment)
            {
                foreach (var p in Post.Posts)
                {
                    comments.AddRange(p.DeletedComments);
                }
            }

            if (comments.Count > 0)
            {
                foreach (var c in comments)
                {
                    JsonTrash t1 = new JsonTrash {
                        Id = c.Id,
                        Title = c.Title,
                        ObjectType = "Comment",
                        Date = c.DateCreated.ToString("dd MMM yyyy"),
                        Time = c.DateCreated.ToString("t") };

                    trashList.Add(t1);
                }
            }

            // posts
            if (trashType == TrashType.All || trashType == TrashType.Post)
            {
                posts = (from x in Post.DeletedPosts orderby x.DateCreated descending select x).ToList();
            }

            if (posts.Count > 0)
            {
                foreach (var p in posts)
                {
                    JsonTrash t2 = new JsonTrash
                    {
                        Id = p.Id,
                        Title = System.Web.HttpContext.Current.Server.HtmlEncode(p.Title),
                        ObjectType = "Post",
                        Date = p.DateCreated.ToString("dd MMM yyyy"),
                        Time = p.DateCreated.ToString("t")
                    };

                    trashList.Add(t2);
                }
            }

            // pages
            if (trashType == TrashType.All || trashType == TrashType.Page)
            {
                pages = (from x in Page.DeletedPages orderby x.DateCreated descending select x).ToList();
            }

            if (pages.Count > 0)
            {
                foreach (var p in pages)
                {
                    JsonTrash t3 = new JsonTrash
                    {
                        Id = p.Id,
                        Title = System.Web.HttpContext.Current.Server.HtmlEncode(p.Title),
                        ObjectType = "Page",
                        Date = p.DateCreated.ToString("dd MMM yyyy"),
                        Time = p.DateCreated.ToString("t")
                    };

                    trashList.Add(t3);
                }
            }

            var pageSize = 20;
            listCount = trashList.Count;

            if (trashList.Count < pageSize)
                return trashList;

            var skip = page == 1 ? 0 : page * pageSize - pageSize;
            var trashPage = trashList.Skip(skip).Take(pageSize).ToList();

            return trashPage;
        }
예제 #4
0
        /// <summary>
        /// Paged list of deleted objects
        /// </summary>
        /// <param name="trashType">Type of delted object</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="page">Page number</param>
        /// <returns></returns>
        public static List<JsonTrash> GetTrash(TrashType trashType)
        {
            var comments = new List<Comment>();
            var posts = new List<Post>();
            var pages = new List<Page>();

            var trashList = new List<JsonTrash>();

            // comments
            if (trashType == TrashType.All || trashType == TrashType.Comment)
            {
                foreach (var p in Post.Posts)
                {
                    comments.AddRange(p.DeletedComments);
                }
            }

            if (comments.Count > 0)
            {
                foreach (var c in comments)
                {
                    JsonTrash t1 = new JsonTrash {
                        Id = c.Id,
                        Title = c.Title,
                        ObjectType = "Comment",
                        Date = c.DateCreated.ToString("dd MMM yyyy"),
                        Time = c.DateCreated.ToString("t") };

                    trashList.Add(t1);
                }
            }

            // posts
            if (trashType == TrashType.All || trashType == TrashType.Post)
            {
                posts = (from x in Post.DeletedPosts orderby x.DateCreated descending select x).ToList();
            }

            if (posts.Count > 0)
            {
                foreach (var p in posts)
                {
                    JsonTrash t2 = new JsonTrash
                    {
                        Id = p.Id,
                        Title = p.Title,
                        ObjectType = "Post",
                        Date = p.DateCreated.ToString("dd MMM yyyy"),
                        Time = p.DateCreated.ToString("t")
                    };

                    trashList.Add(t2);
                }
            }

            // pages
            if (trashType == TrashType.All || trashType == TrashType.Page)
            {
                pages = (from x in Page.DeletedPages orderby x.DateCreated descending select x).ToList();
            }

            if (pages.Count > 0)
            {
                foreach (var p in pages)
                {
                    JsonTrash t3 = new JsonTrash
                    {
                        Id = p.Id,
                        Title = p.Title,
                        ObjectType = "Page",
                        Date = p.DateCreated.ToString("dd MMM yyyy"),
                        Time = p.DateCreated.ToString("t")
                    };

                    trashList.Add(t3);
                }
            }

            return trashList;
        }