コード例 #1
0
 public EditedPostView(Post post) : this()
 {
     this.DoPublish = post.CreatedOn != null;
     this.Title = post.Title;
     this.Extract = post.Content.Extract;
     this.Content = post.Content.Content;
     this.IsDeleted = post.Content.IsDeleted;
     this.UpdateReason = post.Content.UpdateReason;
 }
コード例 #2
0
        public async Task<ActionResult> Create([Bind(Include = "Title,Extract,Content,DoPublish")] PostView postView)
        {
            if (ModelState.IsValid)
            {
                Post post = new Post();
                post.AuthorID = User.Identity.GetUserId();
                post.Title = postView.Title;
                if (postView.DoPublish)
                    post.CreatedOn = new DateTimeOffset(DateTime.Now);
                post = GetDb().Posts.Add(post);
                await GetDb().SaveChangesAsync();

                PostContent postContent = new PostContent();
                postContent.PostID = post.PostID;
                postContent.Extract = postView.Extract;
                postContent.Content = postView.Content;
                GetDb().PostContents.Add(postContent);
                await GetDb().SaveChangesAsync();
                return RedirectToAction("Index");
            }
            return View(postView);
        }