Ejemplo n.º 1
0
        public bool CreatePostAndReplyJoin(PostAndReplyJoinCreate model)
        {
            int postID  = _dbContext.Posts.Single(x => x.PostID == model.PostID).PostID;
            int replyID = _dbContext.Replies.Single(x => x.ReplyID == model.ReplyID).ReplyID;
            var entity  = new PostAndReplyJoin()
            {
                PostID  = postID,
                ReplyID = replyID
            };

            _dbContext.PostAndReplyJoins.Add(entity);
            return(_dbContext.SaveChanges() == 1);
        }
        public ActionResult Create(PostAndReplyJoinCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreatePostAndReplyJoinService();

            if (service.CreatePostAndReplyJoin(model))
            {
                // TempData removes information after it's accessed
                TempData["SaveResult"] = "Your join was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Join could not be created.");
            return(View(model));
        }