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; }
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); }