public ActionResult BlogPost(BlogPostModel model) { var IsExistData = _context.Blog.ToList().Where(b => b.Name.Trim() == model.Name.Trim()).FirstOrDefault(); if (IsExistData != null) { ModelState.AddModelError(string.Empty, "Blog name is already exist"); ViewBag.success = false; return(View(model)); } BlogPost.Core.BlogPost post = new BlogPost.Core.BlogPost() { Description = model.Description, IsPrivate = model.IsPrivate, Name = model.Name, UserId = Convert.ToInt32(Session["UserId"]) }; _context.Blog.Add(post); _context.SaveChanges(); ViewBag.success = true; return(View(model)); }
public virtual ActionResult AllBlogsAdd(BlogPostModel model) { var blog = new BlogPost.Core.BlogPost() { Description = model.Description, Name = model.Name, IsPrivate = false, UserId = model.UserId }; _context.Blog.Add(blog); _context.SaveChanges(); return(Json(model, JsonRequestBehavior.AllowGet)); }