public static PostBO PostPOToBO(PostPO from) { PostBO to = new PostBO(); to.PostId = from.PostId; to.UserId = from.UserId; to.Username = from.Username; to.ThreadId = from.ThreadId; to.CreationDate = from.CreationDate; to.EditDate = from.EditDate; to.Title = from.Title; to.Content = from.Content; return(to); }
public ActionResult UpdatePost(int postId) { ActionResult response = null; try { PostDO dataObject = _dataAccess.ViewPostById(postId); PostPO displayObject = PostMapper.PostDOToPO(dataObject); response = View(displayObject); } catch (Exception ex) { Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } return(response); }
public ActionResult AddPost(int threadId) { int sessionId = 0; if (Session["UserID"] != null) { int.TryParse(Session["UserID"].ToString(), out sessionId); } //pulls currently logged in user's ID and sends it to the add post view PostPO newPost = new PostPO(); newPost.UserId = sessionId; newPost.ThreadId = threadId; return(View(newPost)); }
public ActionResult UpdatePost(PostPO form) { ActionResult response = null; int userId = 0; int userRole = 0; if (Session["RoleID"] != null) { //get the role ID and user ID from session int.TryParse(Session["UserID"].ToString(), out userId); int.TryParse(Session["RoleID"].ToString(), out userRole); } if (userId == form.UserId || userRole == 1 || userRole == 2) { if (ModelState.IsValid) { try { PostDO dataObject = PostMapper.PostPOToDO(form); _dataAccess.UpdatePost(dataObject); response = RedirectToAction("ViewPostsByThreadId", "Post", new { ThreadId = form.ThreadId }); } catch (Exception ex) { Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } } else { response = View(); } } else { response = View(form); } return(response); }
public ActionResult AddPost(PostPO form) { ActionResult response = null; if (ModelState.IsValid) { try { PostDO dataObject = PostMapper.PostPOToDO(form); _dataAccess.AddPost(dataObject); response = RedirectToAction("ViewPostsByThreadId", "Post", new { ThreadId = form.ThreadId }); } catch (Exception ex) { Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } } else { response = View(form); } return(response); }