Пример #1
0
		private static void BlogMenu(DataContext dataContext, Blog blog)
		{
			Console.Clear();
			Console.WriteLine("{0}", blog.Name);
			Console.WriteLine("n: Create new post");
			Console.WriteLine("v: View posts");
			Console.WriteLine("------------------------");
			var selection = Console.ReadLine();

			if(selection == "n")
				CreatePost(dataContext, blog);
			else if(selection == "v")
				DisplayBlog(dataContext, blog);
		}q
Пример #2
0
		private static void DisplayBlog(DataContext dataContext, Blog blog)
		{
			Console.Clear();
			var color = Console.ForegroundColor;
			Console.ForegroundColor = ConsoleColor.White;
			Console.WriteLine(blog.Name);

			Console.ForegroundColor = color;
			Console.WriteLine("    By {0}", blog.Author);
			Console.WriteLine(new String('-', 80));

			foreach(var post in blog.Posts)
			{
				Console.WriteLine("==== {0} ====", post.Title);
				Console.WriteLine(post.Content);
				Console.WriteLine("  - {0}, {1}. My life is just a {2}", blog.Author, post.Posted, post.AngstLevel);
				Console.WriteLine();
			}

			Console.WriteLine("Press enter to return to the menu");
			Console.ReadLine();
		}
Пример #3
0
		private static void CreatePost(DataContext dataContext, Blog blog)
		{
			Console.Write("Title: ");
			var title = Console.ReadLine();

			Console.Write("Content: ");
			var content = Console.ReadLine();

			Console.Write("Angst Level: ");
			var angst = Console.ReadLine();

			blog.Posts.Add(new Post
			{
				Title = title,
				Content = content,
				AngstLevel = angst,
				Posted = DateTime.Now,
			});

			dataContext.SaveChanges();
		}