public ActionResult Create(int id, ThreadPostBindingModel model) { Thread thread = this.GetThread(id); if (thread == default(Thread) || thread.IsDeleted || id != model.Thread.Id) { return(this.RedirectToAction("BadRequest", "Error")); } if (!this.ModelState.IsValid) { model.Thread = new IdentifiableThreadBindingModel() { Id = thread.ThreadId, Title = thread.Title }; return(this.View(model)); } User user = this.GetUser(); Post newPost = new Post() { Creator = user, PostDate = DateTime.Now, Text = new PostText() { Text = model.Text }, Thread = thread }; newPost = this.UnitOfWork .PostRepository .Add(newPost); this.UnitOfWork.SaveChanges(); // to do return(this.RedirectToAction("View", "Post", new { Id = newPost.PostId })); }
/// <summary> /// Empty create for post /// </summary> /// <param name="id">Thread id</param> /// <returns>View of ThreadPostBindingModel</returns> public ActionResult Create(int id) { Thread thread = this.GetThread(id); if (thread == default(Thread) || thread.IsDeleted) { return(this.RedirectToAction("BadRequest", "Error")); } ThreadPostBindingModel post = new ThreadPostBindingModel() { Thread = new IdentifiableThreadBindingModel() { Id = thread.ThreadId, Title = thread.Title } }; return(this.View(post)); }