public ActionResult Edit(ThreadDTO thread) { if (!ValidateThread(thread.Id)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var threadDb = db.ForumThreadSet.Find(thread.Id); if (threadDb == null) { return(HttpNotFound()); } thread.UpdateModel(threadDb); db.SaveChanges(); return(View("Details", Mapper.MapTo(threadDb))); }
public ActionResult Create(CommentDTO comment) { if (comment.ThreadId < 1) { throw new UnauthorizedAccessException("The threadId is invalid"); } try { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); JavaScriptSerializer serializer = new JavaScriptSerializer(); TableUserDTO serializeModel = serializer.Deserialize <TableUserDTO>(authTicket.UserData); if (serializeModel != null) { if (ModelState.IsValid) { comment.User = serializeModel; db.CommentSet.Add(Mapper.MapTo(comment)); db.SaveChanges(); return(RedirectToAction("Details", "Thread", new { id = comment.ThreadId })); } } } } catch (Exception ex) { throw; } throw new UnauthorizedAccessException("You must be logged to create threads"); }