public ActionResult Create([Bind(Include = "ThreadId,Title,Content,UserName,Date,Views,Upvotes")] Thread thread, IEnumerable <int> tagsPicked) { if (ModelState.IsValid) { if (tagsPicked != null) { //insert to Tagthread table foreach (int tagid in tagsPicked) { TagThread link = new TagThread(); link.ThreadId = thread.ThreadId; link.TagId = tagid; thread.TagThreads.Add(link); } } db.Threads.Add(thread); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(thread)); }
public ActionResult Create([Bind(Include = "ThreadId,Title,Content,UserName,Date,Views,Upvotes")] Thread thread, IEnumerable <int> tagsId) { if (ModelState.IsValid) { DateTime localDate = DateTime.Now; thread.UserName = System.Web.HttpContext.Current.User.Identity.Name; thread.Date = localDate; db.Threads.Add(thread); TagThread tagthread; if (tagsId != null) { foreach (var t in tagsId) { tagthread = new TagThread(); tagthread.TagId = t; tagthread.ThreadId = thread.ThreadId; db.TagThreads.Add(tagthread); } } db.SaveChanges(); return(RedirectToAction("Details", "Home", new { id = thread.ThreadId })); } ViewBag.UserName = new SelectList(db.Users, "UserName", "Password", thread.UserName); return(View(thread)); }
public TagThreadView <TUserView> ToTagThreadDto(TagThread <TUser> tagThread) { return(new TagThreadView <TUserView> { Id = tagThread.Id, Tag = ToTagDto(tagThread.Tag), Thread = forumsDataMapping.ToThreadView(tagThread.Thread, null) }); }