Exemplo n.º 1
0
        public ActionResult GetComments(int id, int forumid)
        {
            ForumContainer     forumContainer     = new ForumContainer(connectionstring);
            PostContainer      postContainer      = new PostContainer();
            ForumPostViewModel forumPostViewModel = new ForumPostViewModel(forumContainer.GetForumById(forumid), postContainer.GetPostById(id));

            return(View(forumPostViewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post(string postId)
        {
            var dbModel = await this.service.GetForumPostAsync(postId);

            var model = new ForumPostViewModel {
                CreationDate = dbModel.CreatedOn.ToString("d"), PictureUrl = dbModel.PictureUrl, Title = dbModel.Title, Content = dbModel.Content
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public async Task Create(ForumPostViewModel model)
        {
            var newPost = new ForumPost()
            {
                CreationTime = model.CreationTime,
                Description  = model.Description,
                Title        = model.Title,
                Image        = model.Image,
            };

            await _forumPost.InsertAsync(newPost);
        }
Exemplo n.º 4
0
        public async Task Delete(ForumPostViewModel model)
        {
            var deletePost = new ForumPost()
            {
                CreationTime = model.CreationTime,
                Description  = model.Description,
                Image        = model.Description,
                Title        = model.Title,
                UserId       = model.Title,
            };

            await _forumPost.DeleteAsync(deletePost);
        }
Exemplo n.º 5
0
        public async Task Update(ForumPostViewModel model)
        {
            var updatePost = new ForumPost()
            {
                CreationTime = model.CreationTime,
                Description  = model.Description,
                Image        = model.Image,
                Title        = model.Title,
                UserId       = model.UserId
            };

            await _forumPost.UpdateAsync(updatePost);
        }
Exemplo n.º 6
0
        public ActionResult AddPost(Guid contentKey, Guid?parentKey = null, bool showTitle = false)
        {
            var member = Members.GetCurrentMember();

            var model = new ForumPostViewModel
            {
                ContentKey = contentKey,
                AuthorKey  = member.GetKey(),
                ShowTitle  = showTitle,
            };

            if (parentKey != null)
            {
                model.ParentKey = parentKey.Value;
            }

            return(PartialView("newpost", model));
        }
Exemplo n.º 7
0
        public ActionResult AddPost(ForumPostViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }

            var member = Members.GetCurrentMember();

            LogHelper.Debug <ForumsController>("Body: {0}", () => model.Body);

            var post = new ForumPost
            {
                NodeKey         = model.ContentKey,
                Body            = model.Body.SanitizeHtml(),
                Name            = model.Name ?? "",
                Status          = UserContentStatus.Approved,
                UserContentType = Forums.UserContentTypeAlias,
                Level           = 1,
                AuthorId        = member.GetKey().ToString(),
                Author          = member.Name,
                Answer          = false,
                UpVotes         = 0,
                DownVotes       = 0
            };

            if (model.ParentKey != null)
            {
                post.ParentKey = model.ParentKey;
            }

            var attempt = userContentService.Save(post);

            if (!attempt.Success)
            {
                ModelState.AddModelError("", "Can't add post");
            }

            return(RedirectToCurrentUmbracoUrl());
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Create(ForumPostViewModel model)
        {
            WebImage file             = new WebImage(model.Upload.InputStream);
            string   fileExtention    = file.ImageFormat;
            string   curretnDirectory = Path.GetFullPath(Server.MapPath(imagePath));
            //creating filename to avoid file name conflicts.
            string fileName = Guid.NewGuid().ToString();

            saveMediumImageLocation = curretnDirectory;

            string fileNameWithExtension = fileName + "." + fileExtention;
            //saving file in savedImage folder.
            string saveFile = saveMediumImageLocation + "/" + fileNameWithExtension;

            file.Save(saveFile, fileExtention);
            model.Image = fileNameWithExtension;
            //model.UserId = this.UserProfile.Id;
            model.CreationTime = DateTime.Now;
            await _manageBlogPostService.Create(model);

            return(Redirect("/"));
        }
Exemplo n.º 9
0
 /// <inheritdoc />
 /// <summary>
 /// Posts the message.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 public void PostMessage(ForumPostViewModel viewModel)
 {
 }
Exemplo n.º 10
0
        public ActionResult GetPosts(string id)
        {
            int result;

            int.TryParse(id, out result);

            using (var _db = new ApplicationDbContext())
            {
                var forumThread = _db.ForumThreads.FirstOrDefault(f => f.Id == result);
                var _dbPosts    = _db.ForumPosts.Include("User");
                List <ForumPostViewModel> posts = new List <ForumPostViewModel>();

                if (forumThread != null)
                {
                    foreach (var post in _dbPosts)
                    {
                        if (post.Thread != null)
                        {
                            if (post.Thread.Id == result)
                            {
                                // using viewmodels so that no secret stuff about user gets sent
                                var pvm  = new ForumPostViewModel();
                                var user = new UserViewModel();
                                pvm.Body      = post.Body;
                                pvm.Id        = post.Id;
                                pvm.PostTime  = post.PostTime;
                                pvm.ThreadId  = post.Thread.Id;
                                user.Email    = post.User.Email;
                                user.UserName = post.User.UserName;
                                pvm.User      = user;

                                if (post.ReplyPostId != 0)
                                {
                                    pvm.ReplyPostId = post.ReplyPostId;
                                }

                                posts.Add(pvm);
                            }
                        }
                    }
                    if (posts.Count > 0)
                    {   // sort list by posts and replys
                        for (int i = 0; i < posts.Count; i++)
                        {
                            if (posts[i].ReplyPostId != 0)
                            {   // get parent post
                                var parentPost = posts.FirstOrDefault(p => p.Id == posts[i].ReplyPostId);
                                // if parentPost has been removed,
                                // remove reference and leave at current index
                                if (parentPost == null)
                                {
                                    posts[i].ReplyPostId = 0;
                                }
                                else
                                {
                                    // get index of parent post
                                    var index = posts.IndexOf(parentPost);
                                    // save reply
                                    var temp = posts[i];
                                    // remove reply from postsList
                                    posts.Remove(posts[i]);
                                    // add reply to list again
                                    if (index + 1 > posts.Count)
                                    {
                                        posts.Add(temp);
                                    }
                                    else
                                    {
                                        posts.Insert(index + 1, temp);
                                    }
                                }
                            }
                        }
                        return(Json(JsonConvert.SerializeObject(posts)));
                    }
                }
            }
            return(Json("no posts or no thread"));
        }
Exemplo n.º 11
0
 /// <summary>
 /// Posts the message.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 public void PostMessage(ForumPostViewModel viewModel)
 {
     forumManager.PostMessage(viewModel);
 }
Exemplo n.º 12
0
        public async Task <ActionResult> Delete(ForumPostViewModel model)
        {
            await _manageBlogPostService.Delete(model);

            return(View());
        }