Ejemplo n.º 1
0
        public ActionResult Create(Post post)
        {
            if (ModelState.IsValid)
            {
                post.PostID   = "Test03";
                post.PostedBy = "Test";
                db.Posts.Add(post);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PostedBy = new SelectList(db.Bloggers, "UserName", "FullName", post.PostedBy);
            return(View(post));
        }
Ejemplo n.º 2
0
        public void CreatePost(Post aPost)
        {
            int totalPost = 0;

            try
            {
                totalPost    = _context.Posts.Count();
                aPost.PostID = aPost.Tag + totalPost.ToString();
                if (aPost.PostID != null)
                {
                    _context.Posts.Add(aPost);
                    _context.SaveChanges();
                }
            }
            catch (Exception exp)
            {
                throw new Exception("Error during creating post" + exp);
            }
        }