public ActionResult Create(int id, Post post) { try { postManager.Create(id, post); return(RedirectToAction("MyPosts", "Post", new { Id = id })); } catch { return(View()); } }
public ActionResult Create([Bind(Include = "PostID,Title,ShortDescription,Description,Meta,UrlSlug,Published,PostedOn,Modified,Category_id")] Post newPost) { if (ModelState.IsValid) { var tags = Request.Form["tags"].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); PostManager.Create(newPost, tags.ToList(), User.Identity.Name); return(RedirectToAction("Index")); } ViewBag.Category_id = new SelectList(db.Category, "CategoryID", "Name", newPost.Category_id); return(View(newPost)); }
public ActionResult Create() { if (Request.HttpMethod == "POST") { // Post request method var title = Request.Form["title"].ToString(); var tags = Request.Form["tags"].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var content = Request.Form["content"].ToString(); // Save content var post = new BlogPostModel { Title = title, CreateTime = DateTime.Now, Content = content, Tags = tags.ToList() }; PostManager.Create(JsonConvert.SerializeObject(post)); // Redirect Response.Redirect("~/blog"); } return View(); }
public ActionResult Create(string filter) { ViewBag.User = filter; if (Request.HttpMethod == "POST") { // Post request method var title = Request.Form["title"].ToString(); var tags = Request.Form["tags"].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var content = Request.Form["content"].ToString(); var User = filter; // Save content var post = new UserPostModel { Title = title, CreateTime = DateTime.Now, Content = content, Tags = tags.ToList(), User = User }; PostManager.Create(JsonConvert.SerializeObject(post)); // Redirect return(RedirectToAction("Index", "Blog", new { filter = filter })); // return RedirectToAction("Index"); } return(View()); }
public async Task <IActionResult> Create(string blogname, [Bind("Id,Title,Published,content,Author,RowVersion,BlogId,engine,CategoriesToString")] ViewPost post) { //if (ModelState.IsValid) { post.Author = await PostManager.db.Users.FirstAsync(x => x.UserName == User.Identity.Name); var mpost = post.ToModel(User.Identity.Name); MarkUpManager markDownManager = new MarkUpManager(); mpost.content = markDownManager.ConvertFromHtmlToMarkUp(post.content); var blog = await blmngr.GetBlogByIdAsync(mpost.BlogId); await postManager.Create(mpost, this.User.Identity.Name); if (post.CategoriesToString != null) { var catgories = post.CategoriesToString.Split(",").ToList(); if (catgories != null) { await CategoryManager.AttachCategoryRangetoPost(catgories, blog.Name, mpost.Id); } } if (post.TagsToString != null) { var tags = post.TagsToString.Split(",").ToList(); if (tags != null) { await TagManager.AttachTagRangetoPost(tags, blog.Name, mpost.Id); } } //blmngr.GetBlogAsync() return(RedirectToAction(nameof(Index), "Posts", new { id = blog.Name })); } // return View(post); }