static void Querypos() { BlogBusinessLayer bbl = new BusinessLayer.BlogBusinessLayer(); var posts = bbl.QueryPosts(); foreach (var item in posts) { Console.WriteLine(item.Title + " " + item.Content); } }
/// <summary> /// 显示所有博客 /// </summary> static void QueryBlog() { BlogBusinessLayer bbl = new BusinessLayer.BlogBusinessLayer(); var query = bbl.Query(); Console.WriteLine("所有数据库中的博客:"); foreach (var item in query) { Console.WriteLine("ID:" + item.BlogId + " Name:" + item.Name); } }
static void QueryPostForName() { Console.WriteLine("请输入将要查找的博客名称"); string name = Console.ReadLine(); BlogBusinessLayer pbl = new BusinessLayer.BlogBusinessLayer(); var query = pbl.QueryForName(name); foreach (var item in query) { Console.WriteLine(item.BlogId + " " + item.Name); } }
/// <summary> /// 删除一个博客 /// </summary> static void Delete() { Console.WriteLine("请输入将要删除的博客ID"); //获取输入并检测输入的博客ID是否为正整数 string idStr = PositiveWholeNumberDetection(); int id = int.Parse(idStr); //检测博客ID是否存在 id = BlogIdDetection(idStr, id); BlogBusinessLayer bbl = new BusinessLayer.BlogBusinessLayer(); Blog blog = bbl.Query(id); bbl.Delete(blog); }
/// <summary> /// 更改一个博客的名称 /// </summary> static void Update() { Console.WriteLine("请输入将要更改的博客id"); //获取输入并检测输入的博客ID是否为正整数 string idStr = PositiveWholeNumberDetection(); int id = int.Parse(idStr); //检测博客ID是否存在 id = BlogIdDetection(idStr, id); BlogBusinessLayer bbl = new BusinessLayer.BlogBusinessLayer(); Blog blog = bbl.Query(id); Console.WriteLine("请输入新名字"); string name = Console.ReadLine(); blog.Name = name; bbl.Update(blog); }
static void crateposts(int blogID) { Console.WriteLine("请输入一个博客的名称"); int id = int.Parse(Console.ReadLine()); Console.WriteLine("请输入一个名称"); string title = Console.ReadLine(); Console.WriteLine("请输入一篇内容"); string content = Console.ReadLine(); Post post = new Post(); post.Title = title; post.Content = content; post.BlogId = blogID; BlogBusinessLayer bbl = new BusinessLayer.BlogBusinessLayer(); bbl.cratepost(post); }