Beispiel #1
0
 public void SavePieceContent(PieceContent piece)
 {
     using (var context = new MyContext())
     {
         if (piece.PieceContentId == 0)
         {
             context.Posts.Attach(piece.Post);
             context.Pieces.Add(piece);
         }
         else
         {
             context.Pieces.Attach(piece);
             context.Entry(piece).State = EntityState.Modified;
         }
         context.SaveChanges();
     }
 }
Beispiel #2
0
        public ActionResult CreatePiece(PieceInfo postInfo)
        {
            if (ModelState.IsValid)
            {

                var post = postRepository.GetPost(postInfo.PostId);
                var piece = new PieceContent
                {
                    Post = post,
                    Content = postInfo.Content,
                    Header = postInfo.Header
                };
                
                postRepository.SavePieceContent(piece);
                return RedirectToAction("ShowPost", new {postId = post.PostId});

            }

            return View(postInfo);
        }