Ejemplo n.º 1
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="index"></param>
        /// <param name="rows"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public async Task <Resp> GetListAsync(int index, int rows, string search, Post.PostState state)
        {
            Expression <Func <DB.Tables.Post, bool> > whereSQL = p => p.Title.Contains(search);

            if (state != Post.PostState.NotSelected)
            {
                whereSQL = whereSQL.And(p => p.State == (int)state);
            }

            using var db = new MyForContext();

            Paginator pager = new Paginator
            {
                Index = index,
                Rows  = rows
            };

            pager.TotalRows = await db.Posts.CountAsync(whereSQL);

            pager.List = await db.Posts.AsNoTracking()
                         .Where(whereSQL)
                         .Include(p => p.Theme)
                         .Skip(pager.GetSkip())
                         .Take(pager.Rows)
                         .Select(p => new Results.PostItem
            {
                Id    = p.Id,
                Title = p.Title,
                Theme = p.Theme.Name,
                State = new Share.KeyValue
                {
                    Key   = p.State,
                    Value = ((Post.PostState)p.State).GetDescription()
                },
                Creator    = Clients.Client.GetName(p.CreateById),
                CreateDate = p.CreateDate.ToStandardString()
            })
                         .ToListAsync();

            return(Resp.Success(pager, ""));
        }
Ejemplo n.º 2
0
        private static OperationResult PublishUnpublish(string id, Post.PostState initialState, Post.PostState newState)
        {
            var posts = InternalBlog.Posts.ToList();
            var post  = posts.SingleOrDefault(_ => _.Id == id && _.State == initialState);

            if (post is null)
            {
                return(OperationResult.Failed());
            }

            posts.Remove(post);

            posts.Add(post with {
                State = newState
            });

            InternalBlog = InternalBlog with {
                Posts = posts
            };

            return(OperationResult.Succeed());
        }
    }