Ejemplo n.º 1
0
        public IHttpActionResult PostStory([FromBody] EnterStory StoryData)
        {
            using (var db = new GroupNewsContext())
            {
                var AllStories = db.Stories.Include(i => i.Author).Include(i => i.Category);

                // If author exists, save them.
                var author = db.Authors.SingleOrDefault(s => s.Name == StoryData.UserName);
                // Otherwise, create them.

                if (author == null)
                {
                    author = new Author
                    {
                        Name = StoryData.UserName
                    };
                    db.Authors.Add(author);
                    db.SaveChanges();
                }

                // Similar deal for category.
                var category = db.Categories.SingleOrDefault(s => s.Name == StoryData.Category);

                if (category == null)
                {
                    category = new Category
                    {
                        Name = StoryData.Category
                    };
                    db.Categories.Add(category);
                    db.SaveChanges();
                }

                // Then, create and save the post.
                var newPost = new Story
                {
                    Headline     = StoryData.Headline,
                    Body         = StoryData.Body,
                    CreationDate = DateTime.Now,
                    Author       = author,
                    Category     = category
                };

                db.Stories.Add(newPost);
                db.SaveChanges();

                return(Ok(newPost));
            }
        }
Ejemplo n.º 2
0
 public void Stop()
 {
     EnterStory.Stop();
 }
Ejemplo n.º 3
0
 public void Start()
 {
     EnterStory.BeginTime = TimeSpan.Zero;
     EnterStory.Begin();
 }