private static void Seed()
        {
            CategoriesService categories = new CategoriesService();

            categories.Add("Programming");
            categories.Add("CSharp");
            categories.Add("JavaScript");
            categories.Add("Hobbies");

            var all = categories.All().ToList();

            foreach (var cat in all)
            {

                Console.WriteLine(cat.CategoryName);
            }

            PostsService posts = new PostsService();

            posts.Add("Zopfli Optimization: Literally Free Bandwidth",
                "In 2007 I wrote about using PNGout to produce amazingly small PNG images. I still refer to this topic frequently, as seven years later, the average PNG I encounter on the Internet is very unlikely to be optimized. ",
                "*****@*****.**",
                new List<int>() { 1 });

            posts.Add("The Hugging Will Continue Until Morale Improves",
                "I saw in today's news that Apple open sourced their Swift language. One of the most influential companies in the world explicitly adopting an open source model – that's great! I'm a believer. One of the big reasons we founded Discourse was to build an open source solution that anyone, anywhere could use and safely build upon.",
                "*****@*****.**",
                new List<int>() { 2 });

            posts.Add("The 2016 HTPC Build",
                "I saw in today's news that Apple open sourced their Swift language. One of the most influential companies in the world explicitly adopting an open source model – that's great! I'm a believer. One of the big reasons we founded Discourse was to build an open source solution that anyone, anywhere could use and safely build upon.",
                "*****@*****.**",
                new List<int>() { 1 });
            posts.Add("10 Years of CodeMash",
                @"I spent this past week at the 10th annual CodeMash conference in Sandusky OH. Every single event has been enjoyable, envigorating, and a great way to kick-start the year.

The event has changed dramatically over the past decade, but it still has the same core values from when it was started. It’s a group of people passionate about technology in many incarnations, and willing to share and learn from each other. Looking back at 10 years of CodeMash, several larger trends appear.

Early on, the languages discussed most were Java, C#, VB.NET, and Python. Over time, more and more interest in Ruby grew. Java waned for a time. Functional languages like F#, Haskell, and Erlang became more popular. There were a few Scala sessions.",
                "*****@*****.**",
                new List<int>() { 2 });
            posts.Add("Milk + Soap + Food Coloring = Awesome Reaction",
                @" Food coloring will allow you to see what is actually happening and create beautiful swirls and patterns. Any kind, color or amount will work. Have fun experimenting!
To hold the milk, use a shallow bowl or a plate with raised edges.
Regular old dish soap is the way to go.
Finally some Q-tips to apply the soap with.",
                "*****@*****.**",
                new List<int>() { 4 });

        }
        public void Add(int id, string name, string type)
        {
            Post post = new Post()
            {
                Id   = id,
                Name = name,
                Type = type
            };

            _val.Validate(post);
            _service.Add(post);
        }
Exemplo n.º 3
0
        public ActionResult AddPost(BlogPost post)
        {
            if (ModelState.IsValid)
            {
                post.PublishedAt = DateTime.Now;
                postsService.Add(post);
                return(RedirectToAction("Index", "Home"));
            }

            var model = new AddPostPageModel();

            return(View("AddPost", model));
        }
Exemplo n.º 4
0
 public IActionResult Create([Bind("ID,BlogID,Published,Modified,Title,Content")] Post post)
 {
     if (ModelState.IsValid)
     {
         post.ID        = Guid.NewGuid();
         post.BlogID    = blogsService.GetAll().First().ID;
         post.AuthorID  = User.FindFirst(ClaimTypes.NameIdentifier).Value;
         post.Published = DateTime.UtcNow;
         postsService.Add(post);
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["BlogID"] = blogsService.GetAll()
                          .Select(c => new SelectListItem()
     {
         Text = c.Url, Value = c.ID.ToString()
     })
                          .ToList();
     //ViewData["BlogID"] = new SelectList(_context.Blogs, "ID", "ID", post.BlogID);
     return(View(post));
 }