/// <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> /// Handler for SelectPicturesForPostQuery query /// </summary> /// <param name="query">the SelectPicturesForPost Query</param> /// <returns>a collection of inages associated with a post</returns> public List <Picture> Handle(SelectPicturesForPostQuery query) { return(postRepository.SelectPicturesForPost(query.PostId)); }