Exemple #1
0
        public void AddNewComment(EntitiesViewModels model)
        {
            Comment comment = new Comment();

            comment.UserName = model.UserName;
            comment.Text     = model.Text;
            comment.Article  = articleRepository.GetByID(model.Article.Id);
            commentRepository.Insert(comment);
            commentRepository.Save();
        }
Exemple #2
0
        /// <summary>
        /// Handles the item command
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void rptComments_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "DeleteComment":

                repository.Delete(new Guid(e.CommandArgument.ToString()));
                break;

            case "ApproveComment":

                Comment c = repository.Fetch(new Guid(e.CommandArgument.ToString()));
                if (c != null)
                {
                    c.ModerationStatus = Comment.ModerationApproved;
                    repository.Save(c);
                }

                break;
            }


            if (updateContainerControl != null)
            {
                int commentCount = repository.GetCount(ContentGuid, Comment.ModerationApproved);
                updateContainerControl.UpdateCommentStats(
                    ContentGuid,
                    commentCount);
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);
        }
Exemple #3
0
 static public void addComment(Comment comment)
 {
     using (CommentRepository commentrepo = new CommentRepository())
     {
         commentrepo.context.Entry(comment.user).State = EntityState.Unchanged;
         commentrepo.context.Entry(comment.zone).State = EntityState.Unchanged;
         commentrepo.Add(comment);
         commentrepo.Save();
     }
 }
Exemple #4
0
        public IActionResult Create([FromBody] CommentViewModel request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Parametros invalidos"));
            }

            request.Id = _repository.Save(request);

            return(CreatedAtAction(nameof(GetById), new { Id = request.Id }, request));
        }
Exemple #5
0
        public JsonResult Reply(int commentId, int replyId, string content)
        {
            CommentRepository commentRepository = new CommentRepository();
            Comment           comment           = new Comment();
            Comment           replyComment      = new Comment();

            if (replyId == 0)
            {
                comment = commentRepository.GetById(commentId);
                replyComment.Article       = comment.Article;
                replyComment.ArticleID     = comment.ArticleID;
                replyComment.DateCreated   = DateTime.Now;
                replyComment.UserID        = AuthenticationManager.LoggedUser.Id;
                replyComment.Content       = content;
                replyComment.ParentComment = comment;
                string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
                int    start     = type.LastIndexOf(".") + 1;
                int    positions = type.Length - start;
                type = type.Substring(start, positions);
                replyComment.UserType = type;
                commentRepository.Save(replyComment);
            }
            if (commentId == 0)
            {
                comment             = commentRepository.GetById(replyId);
                comment.Content     = content;
                comment.DateCreated = DateTime.Now;
                string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
                int    start     = type.LastIndexOf(".") + 1;
                int    positions = type.Length - start;
                type             = type.Substring(start, positions);
                comment.UserType = type;
                commentRepository.Save(comment);
            }
            SelectListItem item = new SelectListItem()
            {
                Text = commentId.ToString(), Value = comment.Article.Id.ToString()
            };

            return(Json(item, JsonRequestBehavior.AllowGet));
        }
        public void ExpectDataValidationException()
        {
            CommentRepository repo = new CommentRepository(new BlogContext());

            var comment = new Comment();
            comment.PostID = -1;
            comment.Text = "This shouldn't be saveable";

            Action save = () => repo.Save(comment);

            save.ShouldThrow<DataValidationException>();
        }
        public void SaveTest()
        {
            var comment = new Comment
            {
                Body = "Jahirul Islam"
            };

            var data = repository.Save(comment);

            //Xunit.Assert.NotNull(data);
            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(data);
        }
Exemple #8
0
        /// <summary>
        ///发布一篇评论和能够回复别人评论
        /// </summary>
        /// <param name="model"></param>
        /// <param name="articleId"></param>
        /// <returns></returns>
        public CommentModel Save(CommentModel model)
        {
            Comment comment = mapper.Map <Comment>(model);

            comment.Publish();
            comment.Author  = GetCurrentUser();
            comment.Reply   = commentRepository.Find(model.CommentId);             //当前被评论的Id
            comment.Article = articleRepository.Find(model.ArticleSingleModel.Id); //评论文章的Id
            CommentModel commentModel = GetById(commentRepository.Save(comment));

            return(commentModel);
        }
Exemple #9
0
        public ActionResult EditComment(Comment comment)
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            CommentRepository comrepo = RepositoryFactory.GetCommentRepository();

            comrepo.Save(comment);

            return(RedirectToAction("TaskDetails", "TaskManagement", new { id = comment.CommenterID }));
        }
Exemple #10
0
        public void ExpectDataValidationException()
        {
            CommentRepository repo = new CommentRepository(new BlogContext());

            var comment = new Comment();

            comment.PostID = -1;
            comment.Text   = "This shouldn't be saveable";

            Action save = () => repo.Save(comment);

            save.ShouldThrow <DataValidationException>();
        }
Exemple #11
0
        public ActionResult EditComment(Comment comment)
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            CommentRepository RepoComment = RepositoryFactory.GetCommentRepository();

            RepoComment.Save(comment);

            return(RedirectToAction("Index", "CommentManagement", new { ParentTaskId = comment.ParentTaskId }));
        }
        public IActionResult DeleteCommentById(int id)
        {
            Comment comment = (from c in _commentRepository.Get()
                               where c.Id == id
                               select c)
                              .SingleOrDefault();

            if (null != comment)
            {
                _commentRepository.Delete(comment);
                _commentRepository.Save();
            }
            return(Ok());
        }
Exemple #13
0
 /// <summary>
 ///  创建评论集合
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entitys">评论集合</param>
 /// <returns></returns>
 public bool CreateCollection(ref ValidationErrors validationErrors, IQueryable <Comment> entitys)
 {
     try
     {
         if (entitys != null)
         {
             int count = entitys.Count();
             if (count == 1)
             {
                 return(this.Create(ref validationErrors, entitys.FirstOrDefault()));
             }
             else if (count > 1)
             {
                 using (TransactionScope transactionScope = new TransactionScope())
                 {
                     repository.Create(db, entitys);
                     if (count == repository.Save(db))
                     {
                         transactionScope.Complete();
                         return(true);
                     }
                     else
                     {
                         Transaction.Current.Rollback();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
Exemple #14
0
        public async Task <ActionResult> UserCommentDelete(int id)
        {
            var user = await userMgr.FindByNameAsync(User.Identity.Name);

            var comment = user.Comments.FirstOrDefault(x => x.Id == id);

            if (comment == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            commentRepository.Delete(comment);
            commentRepository.Save();
            return(Json("ok"));
        }
Exemple #15
0
        public JsonResult Comment(int articleId, int commentId, string content)
        {
            ArticleRepository articleRepository = new ArticleRepository();
            CommentRepository commentRepository = new CommentRepository();
            Article           article           = new Article();
            Comment           comment           = new Comment();

            article = articleRepository.GetById(articleId);
            if (commentId == 0)
            {
                comment.ArticleID   = articleId;
                comment.Content     = content;
                comment.DateCreated = DateTime.Now;
                comment.UserID      = AuthenticationManager.LoggedUser.Id;
                string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
                int    start     = type.LastIndexOf(".") + 1;
                int    positions = type.Length - start;
                type             = type.Substring(start, positions);
                comment.UserType = type;
            }
            else
            {
                comment             = commentRepository.GetById(commentId);
                comment.Content     = content;
                comment.DateCreated = DateTime.Now;
                string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
                int    start     = type.LastIndexOf(".") + 1;
                int    positions = type.Length - start;
                type             = type.Substring(start, positions);
                comment.UserType = type;
            }
            commentRepository.Save(comment);
            string         comentator     = AuthenticationManager.LoggedUser.FirstName + " " + AuthenticationManager.LoggedUser.LastName;
            SelectListItem commentContent = new SelectListItem()
            {
                Text = comment.Content, Value = comentator
            };

            return(Json(commentContent, JsonRequestBehavior.AllowGet));
        }
 public JsonResult Comment(int articleId, int commentId, string content)
 {
     ArticleRepository articleRepository = new ArticleRepository();
     CommentRepository commentRepository = new CommentRepository();
     Article article = new Article();
     Comment comment = new Comment();
     article = articleRepository.GetById(articleId);
     if (commentId == 0)
     {
         comment.ArticleID = articleId;
         comment.Content = content;
         comment.DateCreated = DateTime.Now;
         comment.UserID = AuthenticationManager.LoggedUser.Id;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         comment.UserType = type;
     }
     else
     {
         comment = commentRepository.GetById(commentId);
         comment.Content = content;
         comment.DateCreated = DateTime.Now;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         comment.UserType = type;
     }
     commentRepository.Save(comment);
     string comentator = AuthenticationManager.LoggedUser.FirstName + " " + AuthenticationManager.LoggedUser.LastName;
     SelectListItem commentContent = new SelectListItem() { Text = comment.Content, Value = comentator };
     return Json(commentContent, JsonRequestBehavior.AllowGet);
 }
 public JsonResult Reply(int commentId, int replyId, string content)
 {
     CommentRepository commentRepository = new CommentRepository();
     Comment comment = new Comment();
     Comment replyComment = new Comment();
     if (replyId == 0)
     {
         comment = commentRepository.GetById(commentId);
         replyComment.Article = comment.Article;
         replyComment.ArticleID = comment.ArticleID;
         replyComment.DateCreated = DateTime.Now;
         replyComment.UserID = AuthenticationManager.LoggedUser.Id;
         replyComment.Content = content;
         replyComment.ParentComment = comment;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         replyComment.UserType = type;
         commentRepository.Save(replyComment);
     }
     if (commentId == 0)
     {
         comment = commentRepository.GetById(replyId);
         comment.Content = content;
         comment.DateCreated = DateTime.Now;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         comment.UserType = type;
         commentRepository.Save(comment);
     }
     SelectListItem item = new SelectListItem() { Text = commentId.ToString(), Value = comment.Article.Id.ToString() };
     return Json(item, JsonRequestBehavior.AllowGet);
 }
        static void MyMethod()
        {
            FileManagerClass fm          = new FileManagerClass();
            List <Users>     userlist    = new List <Users>();
            List <Comments>  commentList = new List <Comments>();
            Users            user        = new Users();

            UserRepository    userRepo    = new UserRepository();
            CommentRepository commentRepo = new CommentRepository();

            Users newUsers = new Users();

            newUsers.UserID   = 1;
            newUsers.Email    = "*****@*****.**";
            newUsers.Password = "******";
            newUsers.UserName = "******";

            Users newUsers2 = new Users();

            newUsers2.UserID   = 2;
            newUsers2.Email    = "*****@*****.**";
            newUsers2.Password = "******";
            newUsers2.UserName = "******";

            Users newUsers3 = new Users();

            newUsers3.UserID   = 3;
            newUsers3.Email    = "*****@*****.**";
            newUsers3.Password = "******";
            newUsers3.UserName = "******";

            userRepo.Save(newUsers);
            userRepo.Save(newUsers2);
            userRepo.Save(newUsers3);

            var response = "";

            while (response != "8")
            {
                Console.WriteLine("1. Create a User");
                Console.WriteLine("2. Create a Comment");
                Console.WriteLine("3. Print the List of Users");
                Console.WriteLine("4. Print the List of Comments");
                Console.WriteLine("5. Look for a User");
                Console.WriteLine("6. Look for a Comment");
                Console.WriteLine("7. Create a Data File");
                Console.WriteLine("8. Exit");

                Console.WriteLine("");
                Console.WriteLine("Please select an option");
                response = Console.ReadLine();

                switch (response)
                {
                case "1":
                    user = new Users();
                    Console.WriteLine("Enter your email");
                    user.Email = Console.ReadLine();
                    Console.WriteLine("Enter your Username");
                    user.UserName = Console.ReadLine();
                    Console.WriteLine("Enter your password");
                    user.Password = Console.ReadLine();
                    userRepo.Save(user);

                    //Console.WriteLine("You have created a user");
                    break;

                case "2":
                    Comments myComment = new Comments();
                    Console.WriteLine("Enter your comment");
                    myComment.TheComment = Console.ReadLine();


                    commentRepo.Save(myComment);

                    Console.WriteLine("You have created a comment");
                    break;

                case "3":
                    Console.WriteLine("This is the list of users created:");

                    userlist = userRepo.Get();

                    foreach (Users userX in userlist)
                    {
                        Console.WriteLine("The user email is: " + userX.Email);
                        Console.WriteLine("The user password is: " + userX.Password);
                        Console.WriteLine("The user id is: " + userX.UserID);
                        Console.WriteLine("The user name is: " + userX.UserName);
                        Console.WriteLine("");
                    }
                    break;

                case "4":
                    Console.WriteLine("This is the list of comments created:");

                    commentList = commentRepo.Get();

                    foreach (var insideComment in commentList)
                    {
                        Console.WriteLine("The comment id is: " + insideComment.CommentId);
                        Console.WriteLine("The actual comment is: " + insideComment.TheComment);
                    }
                    break;

                case "5":
                    Console.WriteLine("Type username");
                    userlist = userRepo.GetAllUsersByName(Console.ReadLine());
                    foreach (var eachUser in userlist)
                    {
                        Console.WriteLine("The user email is: " + eachUser.Email);
                        Console.WriteLine("The user password is: " + eachUser.Password);
                        Console.WriteLine("The user id is: " + eachUser.UserID);
                        Console.WriteLine("The user name is: " + eachUser.UserName);
                        Console.WriteLine("");
                    }
                    break;

                case "6":
                    Console.WriteLine("Type your Comment");
                    commentList = commentRepo.GetCommentsByComment(Console.ReadLine());
                    foreach (var eachComment in commentList)
                    {
                        Console.WriteLine("The comment id is: " + eachComment.CommentId);
                        Console.WriteLine("The actual comment is: " + eachComment.TheComment);
                        Console.WriteLine("");
                    }
                    break;

                case "7":
                    Console.WriteLine("PLease wait for file");
                    userlist    = userRepo.Get();
                    commentList = commentRepo.Get();

                    fm.AddInfoToFile("File1.txt", userlist, commentList);
                    break;
                }
            }
        }
Exemple #19
0
        private void btnPostComment_Click(object sender, EventArgs e)
        {
            if (commentsClosed)
            {
                WebUtils.SetupRedirect(this, Request.RawUrl);
                return;
            }

            //string title = txtCommentTitle.Text;
            //string commentText = edComment.Text;
            //string userName = txtName.Text;
            //string userEmail = txtEmail.Text;
            //string userUrl = txtURL.Text;


            if (!IsValidComment())
            {
                //PopulateControls();
                if (containerControl != null)
                {
                    containerControl.RefreshAfterPostback();
                }

                //txtCommentTitle.Text = title;
                //edComment.Text = commentText;
                //txtName.Text = userName;
                //txtEmail.Text = userEmail;
                //txtURL.Text = userUrl;

                return;
            }
            //if (blog == null) { return; }

            //if (blog.AllowCommentsForDays < 0)
            //{
            //    WebUtils.SetupRedirect(this, Request.RawUrl);
            //    return;
            //}

            //DateTime endDate = blog.StartDate.AddDays((double)blog.AllowCommentsForDays);

            //if ((endDate < DateTime.UtcNow) && (blog.AllowCommentsForDays > 0)) return;

            if (this.chkRememberMe.Checked)
            {
                SetCookies();
            }

            Comment comment;

            if (userComment != null)
            {
                comment = userComment;
            }
            else
            {
                comment = new Comment();
            }
            comment.SiteGuid    = SiteGuid;
            comment.FeatureGuid = FeatureGuid;
            comment.ModuleGuid  = ModuleGuid;
            comment.ContentGuid = ContentGuid;
            comment.Title       = txtCommentTitle.Text;
            comment.UserComment = edComment.Text;
            comment.UserName    = txtName.Text;
            comment.UserUrl     = txtURL.Text;
            comment.UserEmail   = txtEmail.Text;

            if (currentUser != null)
            {
                comment.UserGuid  = currentUser.UserGuid;
                comment.UserName  = currentUser.Name;
                comment.UserEmail = currentUser.Email;
            }
            comment.UserIp = SiteUtils.GetIP4Address();

            if (requireModeration)
            {
                comment.ModerationStatus = Comment.ModerationPending;
            }
            else
            {
                comment.ModerationStatus = Comment.ModerationApproved;
            }


            repository.Save(comment);

            if (comment.ModerationStatus == Comment.ModerationApproved)
            {
                if (updateContainerControl != null)
                {
                    int commentCount = repository.GetCount(comment.ContentGuid, Comment.ModerationApproved);
                    updateContainerControl.UpdateCommentStats(
                        comment.ContentGuid,
                        commentCount);
                }
            }

            if (notificationAddresses.Count > 0)
            {
                SendCommentNotificationEmail();
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);

            //Response.Redirect(CommentUrl, true);

            //ScriptManager.RegisterStartupScript(this,
            //    this.GetType(),
            //    "blog" + moduleGuid.ToString().Replace("-",string.Empty),
            //    "location.href = '" + Request.RawUrl + "'",
            //    true);
        }