Ejemplo n.º 1
0
        static void QueryPostForTitle()
        {
            Console.WriteLine("请输入将要查找的帖子标题");
            string            title = Console.ReadLine();
            PostBusinessLayer pbl   = new BusinessLayer.PostBusinessLayer();
            var query = pbl.QueryForTitle(title);

            foreach (var item in query)
            {
                Console.WriteLine(item.Title + "  " + item.Content);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据ID删除帖子
        /// </summary>
        static void DeletePost()
        {
            Console.WriteLine("请输入将要删除的帖子ID");
            //获取输入并检测输入的帖子ID是否为正整数
            string idStr = PositiveWholeNumberDetection();
            int    id    = int.Parse(idStr);

            //检测帖子ID是否存在
            id = PostIdDetection(idStr, id);
            PostBusinessLayer pbl = new BusinessLayer.PostBusinessLayer();
            Post post             = pbl.QueryPost(id);

            pbl.Delete(post);
        }
Ejemplo n.º 3
0
        //新增帖子
        static void CreatePost(int blogid)
        {
            Console.WriteLine("请输入一个帖子名称");
            string title = Console.ReadLine();

            Console.WriteLine("请输入一个帖子内容");
            string content = Console.ReadLine();
            Post   post    = new Models.Post();

            post.Title   = title;
            post.Content = content;
            post.BlogId  = blogid;
            PostBusinessLayer pbl = new BusinessLayer.PostBusinessLayer();

            pbl.Add(post);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 检测帖子ID是否存在
        /// </summary>
        /// <param name="idStr"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        static int PostIdDetection(string idStr, int id)
        {
            PostBusinessLayer pbl = new BusinessLayer.PostBusinessLayer();
            bool idDetection      = true;

            while (idDetection)
            {
                if (pbl.QueryPost(id) == null)
                {
                    Console.WriteLine("没有该帖子ID,请重新输入!");
                    idStr = PositiveWholeNumberDetection();
                    id    = int.Parse(idStr);
                }
                else
                {
                    idDetection = false;
                }
            }
            return(id);
        }