Example #1
0
        public int Add(PostCommentModel model)
        {
            try
            {
                var postComment = new PostComment()
                {
                    PostId      = model.PostId,
                    CommentedBy = model.CommentedBy,
                    Text        = model.Text,
                    TypeId      = model.TypeId,
                    Url         = model.Url,
                    CommentedOn = UnixTimeBaseClass.UnixTimeNow,
                };

                _db.PostComments.Add(postComment);
                _db.SaveChanges();

                return(postComment.PostCommentId);
            }
            catch (Exception ex)
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                string json             = js.Serialize(model);
                Log.Error("Post Comment - Add- " + json, ex);
                throw;
            }
        }
Example #2
0
        public async Task <string> PostComment(PostCommentModel comment)
        {
            try
            {
                var comm = new PostComment
                {
                    Active      = true,
                    Content     = comment.Content,
                    CreatedAt   = DateTime.Now,
                    ParentId    = comment.ParentId,
                    Published   = comment.Published,
                    Title       = comment.Title,
                    PostId      = comment.PostId,
                    PublishedAt = (comment.Published == null || comment.Published == false) ? null : (DateTime?)DateTime.Now
                };

                _context.PostComments.Add(comm);
                var res = await _context.SaveChangesAsync();

                if (res > 0)
                {
                    return("Success");
                }
                else
                {
                    return("Failed to Save Post");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Example #3
0
        // GET: SiteHome

        public ActionResult Home()
        {
            PostCommentModel model = new PostCommentModel();

            model.Posts = _uow.GetRepo <Post>().GetList();
            return(View(model));
        }
Example #4
0
        public CommentModel PostComment(PostCommentModel model, string posterId)
        {
            var comment = new Comment()
            {
                CommenterId    = posterId,
                CommentText    = model.CommentText,
                FilmId         = model.FilmId,
                CreateDateTime = DateTime.Now
            };

            var entity = _dbContext.Add(comment);

            _dbContext.SaveChanges();

            var entry = _dbContext.Comments.Include(x => x.User).First(x => x.CommentId == entity.Entity.CommentId);

            return(new CommentModel()
            {
                CommentId = entry.CommentId,
                CommentText = entry.CommentText,
                CommenterEmail = entry.User.Email,
                CommenterId = entry.User.Id,
                CreateDateTime = entry.CreateDateTime
            });
        }
Example #5
0
        // GET: Users
        public ActionResult Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                var user = User.Identity;
                ViewBag.Name = user.Name;

                PostCommentModel pc = new PostCommentModel();
                if (IsAdminUser())
                {
                    ViewBag.displayMenu = "Yes";

                    pc.commentList = cdb.Comments.ToList();
                    pc.postList    = pdb.Posts.ToList();
                }
                else
                {
                    pc.commentList      = cdb.Comments.Where(c => c.Author == User.Identity.Name).ToList();
                    pc.postList         = pdb.Posts.Where(c => c.Producer == User.Identity.Name).ToList();
                    ViewBag.displayMenu = "No";
                }
                return(View(pc));
            }
            else
            {
                ViewBag.Name = "Not Logged IN";
            }
            return(View());
        }
Example #6
0
        public ActionResult PostComment(PostCommentModel postCommentModel)
        {
            if (ModelState.IsValid)
            {
                var username = this.User.Identity.GetUserName();
                var userId   = this.User.Identity.GetUserId();

                var newComment = new Comment()
                {
                    AuthorId = userId,
                    Content  = postCommentModel.Comment,
                    LaptopId = postCommentModel.LaptopId
                };

                this.data.Comments.Add(newComment);
                this.data.SaveChanges();

                var viewModel = new CommentViewModel()
                {
                    AuthorName = username,
                    Content    = postCommentModel.Comment
                };

                return(PartialView("_CommentPartial", viewModel));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ModelState.Values.First().ToString()));
        }
        public ActionResult Comment(int postId)
        {
            var model = new PostCommentModel();

            model.PostId        = postId;
            model.CreatorUserId = AbpSession.UserId;
            return(PartialView(model));
        }
Example #8
0
        public ActionResult UserPost()
        {
            PostCommentModel Model = new PostCommentModel();

            Model.UserPostList  = UserPostBL.GetUserPost();
            Model.SucessMessage = (TempData["Success"] != null ? TempData["Success"].ToString() : string.Empty).ToString();
            Model.ErrorMessage  = (TempData["Error"] != null ? TempData["Error"].ToString() : string.Empty).ToString();
            return(View(Model));
        }
Example #9
0
        public Guid AddPostComment(Guid authorId, Guid postId, string commentText, DateTime creationTime)
        {
            var postComment = new PostCommentModel(Guid.NewGuid(), authorId, postId, commentText, creationTime);

            // postComment.Likes = new List<PostCommentLikeModel>();

            _uniwikiContext.PostComments.Add(postComment);

            return(postComment.Id);
        }
Example #10
0
        public ActionResult PostView(int id)
        {
            PostCommentModel model = new PostCommentModel();
            var gonderi            = _uow.GetRepo <Post>().Where(x => x.Id == id);

            model.Posts    = gonderi;
            model.Gonderi  = gonderi.FirstOrDefault();
            model.Yorumlar = _uow.GetRepo <Comments>().Where(x => x.PostId == id);
            return(View(model));
        }
 public PostCommentEntity ToEntity(PostCommentModel model)
 {
     return(new PostCommentEntity
     {
         Id = model.Id,
         PostId = model.PostId,
         Comment = model.Comment,
         CommentDate = model.CommentDate,
         UserId = model.UserId
     });
 }
        public ActionResult Comment(PostCommentModel model)
        {
            if (model.PostId <= 0)
            {
                return(AbpJson(null));
            }

            var entity = model.MapTo <PostComment>();

            _commentService.InsertComment(entity);
            return(AbpJson("success"));
        }
        public void AddComment(PostCommentModel comment, string Id)
        {
            PostModel post = _posts.Find(p => p.Id == Id).First();

            if (post == null)
            {
                return;
            }
            comment.DateOfPost = DateTime.Now;
            post.PostComments  = post.PostComments.Append(comment);
            Update(Id, post);
        }
Example #14
0
        public IActionResult AddComment(string id, PostCommentModel comment)
        {
            var profile = _postService.Get(id);

            if (profile == null)
            {
                return(NotFound());
            }
            _postService.AddComment(comment, id);

            return(NoContent());
        }
        public HttpResponseMessage PostComment(PostCommentModel model)
        {
            var studioId = int.Parse(model.Id);
            context.Comments.Add(new Comment()
            {
                Author = model.Author,
                Content = model.Comment,
                StudioId = studioId,
            });
            context.SaveChanges();

            return new HttpResponseMessage(HttpStatusCode.Created);
        }
Example #16
0
        public async Task <ActionResult <string> > PostComment(PostCommentModel obj)
        {
            var res = await _blogService.PostComment(obj);

            if (res.Equals("Success"))
            {
                return(Ok("Comment Posted Successfully"));
            }
            else
            {
                return(BadRequest(res));
            }
        }
Example #17
0
        public ActionResult Create([Bind(Include = "Id,PostId,ParentCommentId,AuthorId,AuthorEmail,Content,AddedOn,Visible")] PostCommentModel postComment)
        {
            if (ModelState.IsValid)
            {
                db.PostComments.Add(PostCommentModel.ToEntity(postComment));
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewData["PostId"]          = new SelectList(db.Posts, "Id", "Title", postComment.PostId);
            ViewData["ParentCommentId"] = new SelectList(db.PostComments, "Id", "AuthorEmail", postComment.ParentCommentId);
            ViewData["AuthorId"]        = new SelectList(db.Users, "Id", "Email", postComment.AuthorId);
            return(View(postComment));
        }
        public HttpResponseMessage PostComment(PostCommentModel model)
        {
            var studioId = int.Parse(model.Id);

            context.Comments.Add(new Comment()
            {
                Author   = model.Author,
                Content  = model.Comment,
                StudioId = studioId,
            });
            context.SaveChanges();

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
Example #19
0
        // GET: Management/PostComments/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PostComment postComment = db.PostComments.Find(id);

            if (postComment == null)
            {
                return(HttpNotFound());
            }
            return(View(PostCommentModel.FromEntity(postComment)));
        }
Example #20
0
        public async Task <ActionResult> Edit(CommentCardViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Details", new { viewModel.Comment.Id }));
            }

            // messy, should be a PostCommentModel on the viewModel
            PostCommentModel updateModel = new PostCommentModel
            {
                Text = viewModel.Comment.Text
            };
            await Mediator.Send(new UpdateCommentCommand(viewModel.Comment.Id, updateModel));

            return(RedirectToAction("Details", new { id = viewModel.Comment.Id }));
        }
Example #21
0
        public ActionResult PostComment(PostCommentModel model)
        {
            if (!ModelState.IsValid)
            {
                var message = string.Join(" | ", ModelState.Values
                                          .SelectMany(v => v.Errors)
                                          .Select(e => e.ErrorMessage));

                ModelState.AddModelError("", message);
                return(View(model));
            }

            model.Email.ToUpper().Replace("1=1", "");
            model.Comment.ToUpper().Replace("1=1", "");

            try
            {
                var ip = GetUserIP();
                using (var conn = new MySqlConnection(myConnectionString))
                {
                    conn.Open();
                    using (var comm = conn.CreateCommand())
                    {
                        comm.CommandText = "insert into webdb.comments(comment, commentbyusername, isaccepted, createdate, articleId, IpAddress, email, memberId) values(@comment, @commentbyusername, @isaccepted, @createdate, @articleId, @IpAddress, @email, @memberId)";
                        comm.Parameters.AddWithValue("?comment", model.Comment);
                        comm.Parameters.AddWithValue("?isaccepted", false);
                        comm.Parameters.AddWithValue("?createdate", DateTime.Now);
                        comm.Parameters.AddWithValue("?articleId", model.ArticleId);
                        comm.Parameters.AddWithValue("?IpAddress", ip);
                        comm.Parameters.AddWithValue("?email", model.Email);
                        comm.Parameters.AddWithValue("?memberId", model.MemberId);
                        comm.Parameters.AddWithValue("?commentbyusername", model.UserName);
                        comm.ExecuteNonQuery();

                        ViewBag.SuccessCreateComment = true;
                        conn.Close();
                        conn.Dispose();
                        //return RedirectToAction("Index");
                        return(View(model));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #22
0
        // GET: Management/PostComments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PostComment postComment = db.PostComments.Find(id);

            if (postComment == null)
            {
                return(HttpNotFound());
            }
            ViewData["PostId"]          = new SelectList(db.Posts, "Id", "Title", postComment.PostId);
            ViewData["ParentCommentId"] = new SelectList(db.PostComments, "Id", "AuthorEmail", postComment.ParentCommentId);
            ViewData["AuthorId"]        = new SelectList(db.Users, "Id", "Email", postComment.AuthorId);
            return(View(PostCommentModel.FromEntity(postComment)));
        }
        public ActionResult Create(PostCommentModel comment)
        {
            Post post = db.Posts.Find(comment.PostId);

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

            comment.AddedOn         = DateTime.Now;
            comment.AuthorId        = (comment.AuthorId == 0 ? null : comment.AuthorId);
            comment.ParentCommentId = (comment.ParentCommentId == 0 ? null : comment.ParentCommentId);

            post.PostComments.Add(PostCommentModel.ToEntity(comment));
            db.SaveChanges();

            return(RedirectToAction("View", "Posts", new { Id = post.Id }));
        }
Example #24
0
        public ActionResult PostComment(int articleId = 0)
        {
            var ip      = GetUserIP();
            var comment = new PostCommentModel();

            comment.ArticleId = articleId;
            //Creating instance of DatabaseContext class
            using (var connection = new MySqlConnection(myConnectionString))
            {
                connection.Open();
                using (MySqlCommand cmd = new MySqlCommand("select * from webdb.member where IpAddress = @ip ", connection))
                {
                    cmd.Parameters.AddWithValue("?ip", ip);
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows == true)
                        {
                            while (reader.Read())
                            {
                                comment.IsBlocked = Convert.ToBoolean(reader["IsBlocked"]);
                                if (comment.IsBlocked)
                                {
                                    ViewBag.IsBlocked = true;
                                    return(View(comment));
                                }
                                comment.UserName = reader["AdSoyad"].ToString();
                                comment.Phone    = reader["Mobil"].ToString();
                                comment.MemberId = Convert.ToInt32(reader["id"]);
                            }
                            ViewBag.HasUser = true;
                        }
                        else
                        {
                            ViewBag.HasUser = false;
                        }
                    }
                    cmd.Dispose();
                }
                connection.Close();
                connection.Dispose();
            }
            return(View(comment));
        }
        public PostCommentModel ToModel(PostCommentEntity entity)
        {
            var model = new PostCommentModel
            {
                Id          = entity.Id,
                PostId      = entity.PostId,
                Comment     = entity.Comment,
                CommentDate = entity.CommentDate,
                UserId      = entity.UserId
            };

            if (entity.User == null)
            {
                return(model);
            }

            model.UserName  = entity.User.UserName;
            model.UserPhoto = entity.User.Image;

            return(model);
        }
Example #26
0
        public ActionResult PostComment(PostCommentModel Model)
        {
            UserBM CurrentUser = (UserBM)Session["User"];

            if (CurrentUser != null)
            {
                UserPostBM UserPostBM = new UserPostBM();
                UserPostBM.Post         = Model.UserPost.Post;
                UserPostBM.Subject      = Model.UserPost.Subject;
                UserPostBM.UserId       = CurrentUser.Id;
                UserPostBM.CreatedBy    = CurrentUser.Id;
                UserPostBM.CreationDate = DateTime.Now;
                UserPostBL.Create(UserPostBM);
                TempData["Success"] = "Record saved Successfully.";
            }
            else
            {
                TempData["Error"] = "Please Login.";
            }
            return(RedirectToAction("UserPost"));
        }
Example #27
0
        public async Task <IActionResult> Details(int id, PostCommentModel model)
        {
            if (id == 0)
            {
                return(NotFound());
            }

            var article = await _context.Articles
                          .FirstOrDefaultAsync(m => m.Id == id);


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

            if (ModelState.IsValid)
            {
                var comment = new ArticleComment();

                comment.Content = model.Message;
                comment.Author  = await _userManager.GetUserAsync(User);

                comment.PublicationDate = DateTime.Now;

                // Instead of:
                //   article.Comments.Add(comment);
                // do:
                //   comment.Article = article;
                comment.Article = article;

                _context.Add(comment);

                await _context.SaveChangesAsync();

                ModelState.Clear();
            }

            return(View(article));
        }
Example #28
0
        public async Task <IActionResult> PostComment(
            [FromRoute] int id,
            [FromForm] PostCommentModel model)
        {
            var todo = await _context.Todos
                       .Include(x => x.Participants)
                       .SingleOrDefaultAsync(x => x.Id == id);

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

            if (ModelState.IsValid)
            {
                ApplicationUser currentUser = await _userManager.GetUserAsync(User);

                // if (todo.PersonInChargeId != currentUser.Id)
                // {
                //     var participantIds = todo.Participants
                //         .Select(x => x.UserId);

                //     if (!User.IsInRole(RoleNameEnum.Boss) &&
                //         !participantIds.Contains(currentUser.Id))
                //     {
                //         return BadRequest("You don't have a permission to comment to this todo");
                //     }
                // }
                await _todoServices.PostCommentToTodo(
                    model.CommentContent,
                    currentUser,
                    todo
                    );

                return(RedirectToAction(nameof(Details), new { id }));
            }

            return(View(model));
        }
Example #29
0
        public ActionResult PostComment(PostCommentModel comment)
        {
            if (comment != null && ModelState.IsValid)
            {
                var dbComment = Mapper.Map <Comment>(comment);
                dbComment.Author = this.UserProfile;
                var article = this.Data.Articles.GetById(comment.ArticleId);
                if (article == null)
                {
                    throw new HttpException(404, "Article was not found!");
                }

                article.Comments.Add(dbComment);
                this.Data.SaveChanges();

                var viewModel = Mapper.Map <CommentViewModel>(dbComment);

                return(PartialView("_CommentPartial", viewModel));
            }

            throw new HttpException(400, "Invalid Comment");
        }
Example #30
0
        // GET: Post/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Post post = pdb.Posts.Find(id);

            if (post == null)
            {
                return(HttpNotFound());
            }
            List <Comment> commentList = cdb.Comments.Where(c => c.RefferedPost == id).ToList();

            PostCommentModel pc = new PostCommentModel()
            {
                postList = new List <Post>(), commentList = commentList
            };

            pc.postList.Add(post);

            return(View(pc));
        }
 public int Add(PostCommentModel model)
 {
     return(_postComment.Add(model));
 }