Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }