public async Task<ActionResult> NewPost(NewPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            // XXX WORK HERE
            // Insert the post into the posts collection

            var post = new Post
            {
                Author = User.Identity.Name,
                Content = model.Content,
                Title = model.Title,
                CreatedAtUtc = DateTime.Now
            };
            if (string.IsNullOrWhiteSpace(model.Tags) == false)
            {
                post.Tags.AddRange(model.Tags.Split(',').Select(x=>x.Trim()));
            }

            await blogContext.Posts.InsertOneAsync(post);

            return RedirectToAction("Post", new {id = post.Id});
        }
        public async Task<ActionResult> NewPost(NewPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            // XXX WORK HERE
            // Insert the post into the posts collection

            var list = new List<String>();
            
            model.Tags.Split(',').ToList().ForEach(data => list.Add(data.Trim()));

            var post = new Post {
                Author = this.User.Identity.Name
                ,Comments = new List<Comment>()
                ,Content = model.Content
                ,CreatedAtUtc = DateTime.Now
                ,Title = model.Title
                ,Tags = list
            };

            await blogContext.Posts.InsertOneAsync(post);

            return RedirectToAction("Post", new { id = post.Id });
        }
        public async Task<ActionResult> NewPost(NewPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            // XXX WORK HERE
            // Insert the post into the posts collection
            var user = Request.GetOwinContext().Authentication.User;
            var post = new Post
            {
                Author = user.Identity.Name,
                CreatedAtUtc = DateTime.Now.ToUniversalTime(),
                Title = model.Title,
                Content = model.Content
            };
            foreach (var tag in model.Tags.Split(','))
            {
                post.Tags.Add(tag);
            }

            await blogContext.Posts.InsertOneAsync(post);

            return RedirectToAction("Post", new { id = post.Id });

            
        }
        public async Task<ActionResult> NewPost(NewPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            
            // XXX WORK HERE
            // Insert the post into the posts collection

            /* Response */
            Post post = new Post
            {
                Tags = model.Tags.Split(',').ToList(),
                Title = model.Title,
                Content = model.Content,
                Author = User.Identity.Name,
                CreatedAtUtc = DateTime.UtcNow,
                Comments = new List<Comment>()
            };

            await blogContext.Posts.InsertOneAsync(post);
            /* ---- */

            return RedirectToAction("Post", new { id = post.Id });
        }
Beispiel #5
0
        public async Task<ActionResult> NewPost(NewPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            var post = new Post
            {
                Author = User.Identity.Name,
                Title = model.Title,
                Content = model.Content,
                Tags = model.Tags.Split(',').Select(p => p.Trim()).ToArray(),
                CreatedAtUtc = DateTime.UtcNow,
                Comments = new List<Comment>()
            };

            await blogContext.Posts.InsertOneAsync(post);

            return RedirectToAction("Post", new { id = post.Id });
        }
        public async Task<ActionResult> NewPost(NewPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            // XXX WORK HERE
            // Insert the post into the posts collection
            var post = new Post{
                Author = this.User.Identity.Name,
                Title = model.Title,
                Content = model.Content,
                Tags = model.Tags.Split(',').Select(p => p.Trim()).ToList(),
                CreatedAtUtc = DateTime.UtcNow
            };

            await blogContext.Posts.InsertOneAsync(post);

            return RedirectToAction("Post", new { id = post.Id });
        }
Beispiel #7
0
        public async Task<ActionResult> NewPost(NewPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var blogContext = new BlogContext();
            // XXX WORK HERE
            // Insert the post into the posts collection
            Post post = new Post();
            post.Title = model.Title;
            post.Content = model.Content;
            post.Author = this.User.Identity.Name;
            //post.CreatedAtUtc = DateTime.Now;

            post.Tags= model.Tags.Split(',').ToList();

            IMongoCollection<Post> postsCollection = getPostsCollection();
            await postsCollection.InsertOneAsync(post);

            return RedirectToAction("Post", new { id = post.Id });
        }