예제 #1
0
        public ActionResult Add(PostDetailsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect(Request.UrlReferrer.ToString()));
                //return RedirectToRoute("PostDetails", new { id = model.PostId, name = model.Post.GetTitleAsUrl() });
            }

            Comment comment = model.Comment;

            comment.DateAdded = DateTime.Now;
            comment.UserId    = User.Identity.GetUserId();
            try
            {
                _commentRepo.AddComment(comment);
                _commentRepo.SaveChanges();
                string commentClass = "comment-" + comment.Id;
                TempData["scrollId"] = commentClass;
                return(Redirect(Request.UrlReferrer.ToString()));
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }
예제 #2
0
        public IActionResult Post(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Post post = postsRepository.Get(id.Value);

            if (post == null)
            {
                return(NotFound());
            }

            PostDetailsViewModel view = new PostDetailsViewModel()
            {
                Post     = post,
                Comments = commentRepository.GetByPost(post.Id)
            };

            if (!User.IsInRole(Roles.Administrator) && !User.IsInRole(Roles.Editor))
            {
                ++post.Views;
                postsRepository.SaveAsync();
            }
            return(View(view));
        }
        public ActionResult PostDetails(string slug, PostDetailsViewModel formData)
        {
            if (!String.IsNullOrEmpty(slug))
            {
                var post = DbContext.Posts.FirstOrDefault(p => p.Slug == slug);

                if (post != null)
                {
                    if (!ModelState.IsValid)
                    {
                        return(GetPost(post));
                    }

                    Comment comment;
                    var     userId = User.Identity.GetUserId();

                    comment        = new Comment();
                    comment.UserId = userId;
                    comment.Body   = formData.CommentBody;
                    DbContext.Comments.Add(comment);
                    post.Comments.Add(comment);

                    DbContext.SaveChanges();

                    return(RedirectToAction(nameof(BlogController.PostDetails)));
                }
            }

            return(RedirectToAction(nameof(BlogController.Index)));
        }
예제 #4
0
        // GET: CropPostDetail
        public ActionResult Index(int?id)
        {
            PostDetailsViewModel vm = new PostDetailsViewModel();

            vm.CropPostId = id;
            if (id == null)
            {
                vm.CropPost = db.CropPostModels.First();
                var cropPostDetailModels = db.CropPostDetailModels.Include(c => c.Crop).Include(c => c.CropPost);
                //ICollection<PostImageModel> cropPostImages = new ICollection<PostImageModel>();
                vm.CropPostDetails = (ICollection <CropPostDetailModel>)cropPostDetailModels.ToList();
                //vm.PostImages = cropPostImages;
                //return View(cropPostDetailModels.ToList());
                return(View(vm));
            }
            else
            {
                vm.CropPost = db.CropPostModels.Find(id);
                var cropPostDetailModels = db.CropPostDetailModels.Where(c => c.CropPostId == id).Include(c => c.Crop).Include(c => c.CropPost);
                ICollection <CropPostImageModel> cropPostImages = db.CropPostImageModels.Where(p => p.CropPostId == id).Include(c => c.CropPost).ToList();
                vm.PostImages      = cropPostImages;
                vm.CropPostDetails = (ICollection <CropPostDetailModel>)cropPostDetailModels.ToList();
                return(View(vm));
            }
        }
예제 #5
0
        public PostDetailsViewModel GetPostDetailById(int id)
        {
            var post = this.postRepo.All().SingleOrDefault(p => p.Id == id);

            if (post == null || post.IsDeleted == true)
            {
                throw new InvalidOperationException("Post not found.");
            }

            var postDetail = new PostDetailsViewModel
            {
                Author      = post.Author.UserName,
                Title       = this.sanitizer.Sanitize(post.Title),
                FullContent = this.sanitizer.Sanitize(post.FullContent),
                CreatedOn   = post.CreatedOn.ToString("dd-MM-yyyy HH:mm"),
                Tags        = string.Join(", ", post.Tags.Select(t => t.Tag.Name)),
                Id          = post.Id,
                IsDeleted   = post.IsDeleted,
                Comments    = post.Comments.Where(c => c.IsDeleted == false).Select(c => new CommentViewModel
                {
                    AuthorName = c.Author.UserName,
                    Content    = this.sanitizer.Sanitize(c.Content),
                    CreatedOn  = c.CreatedOn.ToString("dd-MM-yyyy HH:mm"),
                    Id         = c.Id,
                    IsDeleted  = c.IsDeleted
                }).OrderByDescending(c => c.CreatedOn).ToList()
            };

            return(postDetail);
        }
예제 #6
0
        public async Task <PostDetailsViewModel> GetAllCommentsPerPost(int postId)
        {
            var post = await this.postRepo.GetByIdAsync(postId);

            if (post == null && post.IsDeleted == true)
            {
                return(null);
            }

            var postDetail = new PostDetailsViewModel
            {
                Author      = post.Author.UserName,
                Title       = this.sanitizer.Sanitize(post.Title),
                FullContent = this.sanitizer.Sanitize(post.FullContent),
                CreatedOn   = post.CreatedOn.ToString("dd-MM-yyyy HH:mm"),
                Tags        = string.Join(", ", post.Tags.Select(t => t.Tag.Name)),
                Id          = post.Id,
                IsDeleted   = post.IsDeleted,
                Comments    = post.Comments.Where(c => c.IsDeleted == false).Select(c => new CommentViewModel
                {
                    AuthorName = c.Author.UserName,
                    Content    = this.sanitizer.Sanitize(c.Content),
                    CreatedOn  = c.CreatedOn.ToString("dd-MM-yyyy HH:mm"),
                    Id         = c.Id,
                    IsDeleted  = c.IsDeleted
                }).OrderByDescending(c => c.CreatedOn).ToList()
            };

            return(postDetail);
        }
예제 #7
0
        ActionResult GetAtomPost(int id)
        {
            var vm = new PostDetailsViewModel(db, id, Request.Url);

            if (vm.Post == null)
            {
                return(new SimpleActionResult()
                {
                    StatusCode = 404, StatusDescription = "Resource Not Found"
                });
            }

            var entry = GetEntry(vm.Post);
            var sb    = new StringBuilder();

            // OMG! WLW crashes if it gets back an XML declaration!
            using (var writer = XmlWriter.Create(sb, new XmlWriterSettings()
            {
                OmitXmlDeclaration = true
            })) { entry.SaveAsAtom10(writer); }
            return(new SimpleActionResult()
            {
                ResponseOut = sb.ToString(), ContentType = "application/xml"
            });
        }
예제 #8
0
        public async Task <IActionResult> CreateComment(int id, PostDetailsViewModel command)
        {
            if (string.IsNullOrWhiteSpace(command.NewComment.Content))
            {
                TempData["CommentFlag"]    = true;
                TempData["CommentMessage"] = "Comment can't be empty!";
                return(RedirectToAction("Post", "Home", id));
            }

            try
            {
                var userId = int.Parse(HttpContext.Session.GetString("Id"));
                var user   = await _userService.GetUserAsync(userId);

                var post = await _postService.GetPostAsync(id);

                await _commentService.CreateCommentAsync(command.NewComment, user, post);

                return(RedirectToAction("Post", "Home", id));
            }
            catch (InternalSystemException ex)
            {
                TempData["CommentFlag"]    = true;
                TempData["CommentMessage"] = ex.Message;
                return(RedirectToAction("Post", "Home", id));
            }
            catch (Exception)
            {
                TempData["CommentFlag"]    = true;
                TempData["CommentMessage"] = "Something went wrong!";
                return(RedirectToAction("Post", "Home", id));
            }
        }
예제 #9
0
 public PostDetails(PostDetailsViewModel model, IInternetConnectionChecker internetConnectionChecker)
 {
     InitializeComponent();
     BindingContext             = model;
     _model                     = model;
     _internetConnectionChecker = internetConnectionChecker;
 }
예제 #10
0
        public async Task <HttpResponseMessage> Get(int postId)
        {
            DAL objData = new DAL();

            PostDetailsModel     objPostDetails   = new PostDetailsModel();
            PostDetailsViewModel objPostViewModel = new PostDetailsViewModel();

            try
            {
                objPostDetails = objData.GetPostDetailsById(postId);

                //Mapper.CreateMap<PostDetailsModel, PostDetailsViewModel>();

                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <PostDetailsModel, PostDetailsViewModel>();
                    cfg.CreateMap <tg, tgView>();
                });

                IMapper mapper = config.CreateMapper();
                var     source = new PostDetailsModel();
                var     dest   = mapper.Map <PostDetailsModel, PostDetailsViewModel>(objPostDetails);

                //PostDetailsViewModel objPostViewModel = Mapper.Map<PostDetailsModel, PostDetailsViewModel>(objPostDetails);

                return(await Task.Run(() => Request.CreateResponse(HttpStatusCode.OK, dest)));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
예제 #11
0
        public async Task <IActionResult> Comment(PostDetailsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var errors = this.ModelState.Values.SelectMany(p => p.Errors).Select(e => e.ErrorMessage).ToList();

                var errorModel = this.errorService.GetErrorModel(errors);

                return(View("Error", errorModel));
            }

            var comment = model.CreateComment;

            try
            {
                await this.forumService.CreateComment(comment);
            }
            catch (Exception e)
            {
                ViewData["Errors"] = e.Message;

                return(this.View("Error"));
            }

            return(RedirectToAction("PostDetails", new { id = comment.PostId }));
        }
예제 #12
0
        public ActionResult Details(int id)
        {
            Post           post    = _dbContext.Posts.Find(id);
            StudentProfile student = _dbContext.StudentProfiles.Find(post.StudentId);

            if (post == null || student == null)
            {
                return(HttpNotFound());
            }

            PostDetailsViewModel model = new PostDetailsViewModel();
            ApplicationUser      user  = UserManager.FindById(student.UserId);

            model.Id             = post.Id;
            model.UserName       = user.UserName;
            model.Class          = student.Class;
            model.DaysPerWeek    = post.DaysPerWeek;
            model.InstituteName  = student.InstituteName;
            model.IsNegotiable   = post.IsNegotiable;
            model.Name           = student.Name;
            model.PresentAddress = student.PresentAddress;
            model.Salary         = post.Salary;
            model.Subjects       = post.Subjects;
            model.Version        = student.Version;
            model.IsCompleted    = post.IsCompleted;

            return(View(model));
        }
        public void LoadPostSussessTest()
        {
            postServiceClientMock.Setup(x => x.Get(It.IsAny <string>())).Returns(() =>
            {
                var task = new Task <Post>(() => post);
                task.Start();
                task.Wait();
                return(task);
            });

            var viewModel = new PostDetailsViewModel(null,
                                                     postServiceClientMock.Object,
                                                     commentServiceClientMock.Object,
                                                     windowManagerMock.Object,
                                                     progressBarMock.Object,
                                                     null);

            viewModel.LoadPost();

            Assert.AreNotEqual(null, viewModel.Post);
            Assert.AreEqual(post.Id, viewModel.Post.Id);
            Assert.AreEqual(post.Title, viewModel.Post.Title);
            Assert.AreEqual(post.Body, viewModel.Post.Body);
            Assert.AreEqual(post.User.UserId, viewModel.Post.User.UserId);
        }
예제 #14
0
        public ActionResult PostDetails(string id)
        {
            var image  = this.uploadedImageService.GetImageById(int.Parse(id));
            var userId = this.userProvider.GetUserId();

            var user = this.userService.GetRegularUserById(userId);

            var model = new PostDetailsViewModel()
            {
                Id                = image.Id,
                ImgDescription    = image.Description,
                UploaderId        = image.UploaderId,
                UploaderUsername  = image.Uploader.Username,
                UploaderAvatarUrl = image.Uploader.AvatarUrl,
                ImgUrl            = image.OriginalSrc,
                LikesCount        = image.LikesCount,
                HasBeenLiked      = user.LikedImages.Contains(image),
                Comments          = image.Comments.ToList().Select(c => new ImageCommentViewModel
                {
                    Content = c.Content,
                    Author  = c.Author.Username
                }).ToList()
            };

            return(View(model));
        }
예제 #15
0
        public void _Returns_Correct_Model(
            string cloud, string apiKey, string apiSecret, int postId)
        {
            //Arrange
            var post  = new Models.Post();
            var model = new PostDetailsViewModel();

            var mockedAuthProvider = new Mock <IAuthenticationProvider>();

            var mockedPostService = new Mock <IPostService>();

            mockedPostService.Setup(s => s.GetPostById(It.IsAny <int>())).Returns(post);

            var mockedViewModelFactory = new Mock <IViewModelFactory>();

            mockedViewModelFactory.Setup(v => v.CreatePostDetailsViewModel(It.IsAny <Models.Post>())).Returns(model);

            var mockedAcc        = new CloudinaryDotNet.Account(cloud, apiKey, apiSecret);
            var mockedCloudinary = new Mock <Cloudinary>(mockedAcc);

            var postController = new PostController(mockedAuthProvider.Object, mockedPostService.Object,
                                                    mockedViewModelFactory.Object, mockedCloudinary.Object);

            //Act
            var res = postController.Details(postId) as ViewResult;

            //Assert
            Assert.AreEqual(model, res.Model);
        }
        public async Task <IActionResult> Details(int id)
        {
            await this.posts.AddView(id);

            var post = posts.GetPostById(id);

            var postDetails = new PostDetailsViewModel
            {
                Id             = id,
                Title          = post.Result.Title,
                Description    = post.Result.Description,
                Price          = post.Result.Price,
                Images         = await posts.GetAllPostImages(id),
                Owner          = await this.users.GetUserById(posts.GetPostOwnerId(id)),
                Category       = post.Result.Category,
                SubmissionDate = post.Result.SubmissionDate,
                ViewsCount     = post.Result.Views
            };

            if (User.Identity.IsAuthenticated)
            {
                var currentUser = this.users.GetUserByUserName(User.Identity.Name);
                await this.userActivities.AddUserActivity(string.Format(SawPost, post.Result.Id), currentUser.Result);
            }

            return(View(postDetails));
        }
예제 #17
0
        public async Task <IActionResult> Details([Bind("PostId, CommentValue")] PostDetailsViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = await GetCurrentUserAsync();

                Post post = await _context.Post
                            .Include(p => p.Owner)
                            .FirstOrDefaultAsync(m => m.Id == viewModel.PostId);

                if (post == null)
                {
                    return(NotFound());
                }

                Comment comment = new Comment
                {
                    CommentValue  = viewModel.CommentValue,
                    Owner         = user,
                    CreationDate  = DateTime.Now,
                    BelongingPost = post
                                    //String.format"{0:g}"
                };

                _context.Comments.Add(comment);
                await _context.SaveChangesAsync();

                viewModel = await GetPostDetailsViewModel(post);
            }

            return(View(viewModel));
        }
예제 #18
0
        public async Task <IActionResult> Details([Bind("PostID, CommentContent, CommentAuthor, CommentDate")] PostDetailsViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Comment comment = new Comment();

                comment.CommentContent = viewModel.CommentContent;
                comment.CommentAuthor  = viewModel.CommentAuthor;
                comment.CommentDate    = viewModel.CommentDate;

                Post post = await _context.Post
                            .FirstOrDefaultAsync(m => m.Id == viewModel.PostID);

                if (post == null)
                {
                    return(NotFound());
                }

                comment.ThePost = post;
                _context.Comment.Add(comment);
                await _context.SaveChangesAsync();

                viewModel = await GetPostDetailsViewModelFromPost(post);
            }

            return(View(viewModel));
        }
        public ActionResult AddComment([Bind(Include = "NewCommentContent,PostId,CommentAuthorId")] PostDetailsViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var     author     = db.Users.Find(viewModel.CommentAuthorId);
                Comment newComment = new Comment
                {
                    PostId   = viewModel.PostId,
                    Author   = author,
                    Content  = viewModel.NewCommentContent,
                    AuthorId = viewModel.CommentAuthorId
                };

                author.Comments.Add(newComment);
                db.Comments.Add(newComment);
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = viewModel.PostId }));
            }

            viewModel.Post = db.Posts
                             .Include(p => p.Author)
                             .Include(p => p.Comments.Select(c => c.Author))
                             .First(p => p.Id == viewModel.PostId);

            this.AddNotification("Error while adding the comment.", NotificationType.ERROR);
            return(View("Details", viewModel));
        }
예제 #20
0
        public IActionResult Post(string slug)
        {
            var post = _repository.GetPostBySlug(slug);

            if (post == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            var model = new PostDetailsViewModel
            {
                Id          = post.Id,
                Author      = post.Author,
                AuthorImage = post.User.ImageUrl,
                Title       = post.Title,
                Slug        = post.Slug,
                Description = post.Description,
                Image       = post.ImageUrl,
                DatePosted  = post.DateCreated,
                Body        = post.Body,
                //I wanted to make the CategoryId
                //Pull all the Categories with the Id that matched this one
                //Unfortunately due to me not yet knowing Linq I Could not
                //Thus I put the category name in place of category Id
                Category = post.CategoryId,
                Comments = post.Comments.OrderBy(c => c.DatePosted).ToList()
            };

            return(View(model));
        }
예제 #21
0
        public IActionResult Details(int id)
        {
            if (id <= 0)
            {
                return(NotFound());
            }

            var post = this.Context.Posts
                       .Include(p => p.Category)
                       .Include(p => p.Comments)
                       .ThenInclude(c => c.Author)
                       .FirstOrDefault(p => p.Id == id);

            if (post == null)
            {
                return(NotFound());
            }

            var comments = post.Comments
                           .Select(CommentViewModel.FromComment)
                           .ToList();

            var postModel = new[] { post }
            .Select(PostsHomeViewModel.FromPost)
            .First();

            var model = new PostDetailsViewModel()
            {
                Comments = comments,
                Post     = postModel
            };

            return(View(model));
        }
예제 #22
0
        public IActionResult MyPosts(int page = 1)
        {
            var posts = this.unitOfWork.PostRepository.GetAll().ToList();

            var model = posts.Select(p => PostDetailsViewModel.CreateFromEntity(p));

            return(View(model));
        }
예제 #23
0
        public ViewResult GetPostDetails(int postId)
        {
            PostDetailsViewModel model = new PostDetailsViewModel();

            model.Post = _browseServcie.getPost(Convert.ToInt32(postId));

            return(View("Details", model));
        }
예제 #24
0
 public static string GetUri(this PostDetailsViewModel postDetailsViewModel, IUrlHelper urlHelper)
 {
     return(urlHelper.Action("Details", "Threads",
                             new
     {
         categoryAlias = postDetailsViewModel.CategoryAlias,
         threadId = postDetailsViewModel.ThreadId,
     }) + "#" + postDetailsViewModel.Id);
 }
예제 #25
0
        public async Task <IActionResult> CreatePost(PostDetailsViewModel model)
        {
            var user = await this.userManager.FindByNameAsync(this.User.Identity.Name);

            this.postsService.Add(model.Name, model.Content, user.Id);
            this.TempData.AddSuccessMessage("Post added");

            return(this.RedirectToAction("Index", "Posts"));
        }
예제 #26
0
        public IActionResult OnGet(int id)
        {
            this.Post = this.posts.Details(id);

            if (Post == null)
            {
                return(NotFound());
            }

            return(Page());
        }
예제 #27
0
        public ActionResult Details(string postId)
        {
            var viewModel = new PostDetailsViewModel
            {
                CurrentPost = _postService.GetDetailedPostInfo(new Guid(postId)),
                Posts       = _postService.GetPostComments(new Guid(postId)),
                PostModel   = new Post()
            };

            return(View(viewModel));
        }
예제 #28
0
        // e.g.
        // GET: /Posts/Details/5
        public ActionResult Details(int id)
        {
            var vm = new PostDetailsViewModel(db, id, Request.Url);

            if (vm.Post == null)
            {
                ViewData["id"] = id;
                return(View("NotFound", vm));
            }

            return(View(vm));
        }
예제 #29
0
        private async Task <PostDetailsViewModel> GetPostDetailsViewModelFromPost(Post post)
        {
            PostDetailsViewModel viewModel = new PostDetailsViewModel();

            viewModel.Post = post;

            List <Comment> comments = await _context.Comment
                                      .Where(m => m.ThePost == post).ToListAsync();

            viewModel.Comments = comments;
            return(viewModel);
        }
        public ActionResult GetTagsFromPostDetails(int id, PostDetailsViewModel viewModel)
        {
            try
            {
                _tagRepository.DeleteTagFromPost(viewModel.Tag.Id);

                return(RedirectToAction(nameof(Details), "Post", new { id = viewModel.Post.Id }));
            }
            catch (Exception ex)
            {
                return(View(viewModel));
            }
        }