/// <summary> /// Method that grabs the post and shows all the relevant details on the post details page. /// </summary> /// <param name="postId">the id of the post to get the details of.</param> /// <returns>The Post Details View</returns> public ActionResult PostDetails(int postId) { PostModel model = new PostModel(); GetPostByPostIdQuery query = new GetPostByPostIdQuery(postId); model.Post = commandBus.ProcessQuery(query); model.UserLoginName = claimsHelper.GetUserNameFromClaim((ClaimsIdentity)User.Identity); if (model.Post.PostStatus == 1) { model.Post.SetPostPictures(new List <string>()); SelectPicturesForPostQuery pictureQuery = new SelectPicturesForPostQuery(postId); List <Picture> pictures = commandBus.ProcessQuery(pictureQuery); foreach (Picture picture in pictures) { model.Post.Pictures.Add(GetBaseImage(picture.PictureImagePath)); } return(View(ViewNames.PostDetails, model)); } return(RedirectToAction("Index", "Post")); }
/// <summary> /// Method for the edit post page. /// </summary> /// <param name="postId">the id of the post to edit.</param> /// <returns>The Create Post View</returns> public ActionResult EditPost(int postId) { CreatePostModel model = new CreatePostModel(); Post itemPost = new Post(); GetPostByPostIdQuery query = new GetPostByPostIdQuery(postId); itemPost = commandBus.ProcessQuery(query); model.PostId = itemPost.PostId; model.PostedBy = itemPost.PostedBy; model.PostPurpose = itemPost.PostPurpose; model.PostTitle = itemPost.PostTitle; model.PostDescription = itemPost.PostDescription; model.DatePosted = itemPost.DatePosted; model.PostStatus = itemPost.PostStatus; model.ExpirationDate = itemPost.ExpirationDate; model.CategoryId = itemPost.CategoryId; model.SubCategoryId = itemPost.SubCategoryId; model.Pictures = itemPost.Pictures; model.PostedByEmailAddress = itemPost.PostedByEmailAddress; model.TestPicturePaths = itemPost.TestPicturePaths; IEnumerable <SubCategoryEnum> subcategoryEnum = Enumeration.GetAll <SubCategoryEnum>().ToList(); List <SubCategoryEnum> subCategoriesList = new List <SubCategoryEnum>(); foreach (SubCategoryEnum subCat in Enumeration.GetAll <SubCategoryEnum>()) { if (subCat.ParentId == model.CategoryId) { subCategoriesList.Add(subCat); } } IEnumerable <SelectListItem> subcategoryList = subCategoriesList.Select(item => new SelectListItem() { Text = item.DisplayValue, Value = item.Id, }); model.SubcategoryList = subcategoryList; if (claimsHelper.GetUserNameFromClaim((ClaimsIdentity)User.Identity) == model.PostedBy) { SelectPicturesForPostQuery pictureQuery = new SelectPicturesForPostQuery(model.PostId); model.TestPicturePaths = commandBus.ProcessQuery(pictureQuery); model.Pictures = new List <string>(); foreach (Picture picture in model.TestPicturePaths) { model.Pictures.Add(GetBaseImage(picture.PictureImagePath)); } return(View(ViewNames.CreatePost, model)); } return(RedirectToAction("Index", "Post")); }
/// <summary> /// Deletes a post /// </summary> /// <param name="postId">the id of the post to delete</param> /// <returns>true/false, true if successfully deleted, false otherwise</returns> public JsonResult DeletePost(int postId) { //Queries for the current user and their email address. - Chris SelectUserQuery currentUser = new SelectUserQuery(new CurrentUser(claimsHelper.GetUserNameFromClaim((ClaimsIdentity)User.Identity))); CurrentUser user = commandBus.ProcessQuery(currentUser); GetPostByPostIdQuery query = new GetPostByPostIdQuery(postId); Post newPost = commandBus.ProcessQuery(query); if (newPost.PostStatus == Convert.ToInt32(PostStatusEnum.Delivered.Id) || newPost.PostStatus == Convert.ToInt32(PostStatusEnum.PendingDelivery.Id)) { return(Json("false", JsonRequestBehavior.AllowGet)); } RemovePostCommand command = new RemovePostCommand(new Post(postId), user.LoginName); commandBus.Execute(command); return(Json("true", JsonRequestBehavior.AllowGet)); }
/// <summary> /// Changes the status of a post to active. /// </summary> /// <param name="postId">the id of the post to set to active status</param> /// <returns>fase if it is trying to change the status on a post that is not allowed, true if everything works ok</returns> public JsonResult RepostItem(int postId, DateTime expirationDate) { ClaimsIdentity id = (ClaimsIdentity)User.Identity; //Queries for the current user and their email address. - Chris SelectUserQuery currentUser = new SelectUserQuery(new CurrentUser(id.Claims.ElementAt(0).Value)); CurrentUser user = commandBus.ProcessQuery(currentUser); GetPostByPostIdQuery query = new GetPostByPostIdQuery(postId); Post newPost = commandBus.ProcessQuery(query); if (newPost.PostStatus == 1 || newPost.PostStatus == 3 || newPost.PostStatus == 5) { return(Json("false", JsonRequestBehavior.AllowGet)); } UpdatePostToActiveCommand command = new UpdatePostToActiveCommand(postId, expirationDate, user.LoginName); commandBus.Execute(command); return(Json("true", JsonRequestBehavior.AllowGet)); }
/// <summary> /// Marks a post as deliverd by changing its status /// </summary> /// <param name="postId">the id of the post to change the status of</param> /// <returns>true / false, true if the status is successfully changed, false if not.</returns> public JsonResult MarkPostAsDelivered(int postId) { ClaimsIdentity id = (ClaimsIdentity)User.Identity; //Queries for the current user and their email address. - Chris SelectUserQuery currentUser = new SelectUserQuery(new CurrentUser(id.Claims.ElementAt(0).Value)); CurrentUser user = commandBus.ProcessQuery(currentUser); GetPostByPostIdQuery query = new GetPostByPostIdQuery(postId); Post newPost = commandBus.ProcessQuery(query); if (newPost.PostStatus != 2) { return(Json("false", JsonRequestBehavior.AllowGet)); } UpdatePostToDeliveredCommand command = new UpdatePostToDeliveredCommand(new Post(postId), user.LoginName); commandBus.Execute(command); return(Json("true", JsonRequestBehavior.AllowGet)); }
/// <summary> /// Handler for GetPostByPostIdQuery query /// </summary> /// <param name="query">the GetPostByPostId Query</param> /// <returns>the post information associated with a post id</returns> public Post Handle(GetPostByPostIdQuery query) { return(postRepository.GetPostByPostId(query.PostId)); }