示例#1
0
        public ActionResult CreateComment(string con, int id)
        {
            Comment comment = new Comment()
            {
                Contenu       = con,
                PublicationId = id
            };

            MyCommentService.Add(comment);
            MyCommentService.Commit();



            return(Json(comment, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public void ShouldBeErrorIfNoKeyAdd()
        {
            string encryptionKey = null;
            DBResult <UserProfile> profileDBResult = new DBResult <UserProfile>
            {
                Payload = new UserProfile()
                {
                    EncryptionKey = encryptionKey
                }
            };

            Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>();

            profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(profileDBResult);

            UserComment userComment = new UserComment()
            {
                UserProfileId   = hdid,
                ParentEntryId   = parentEntryId,
                Text            = "Deleted Comment",
                EntryTypeCode   = Database.Constants.CommentEntryType.Medication,
                CreatedDateTime = new DateTime(2020, 1, 1)
            };

            ICommentService service = new CommentService(
                new Mock <ILogger <CommentService> >().Object,
                new Mock <ICommentDelegate>().Object,
                profileDelegateMock.Object,
                new Mock <ICryptoDelegate>().Object
                );

            RequestResult <UserComment> actualResult = service.Add(userComment);

            Assert.Equal(ResultType.Error, actualResult.ResultStatus);
        }
示例#3
0
        public async Task AddComment()
        {
            //Arrange
            var user = new User()
            {
                Id = "user-id", UserName = "******"
            };

            await this.context.AddAsync(user);

            await this.context.SaveChangesAsync();

            var mapper         = new Mock <IMapper>();
            var store          = new Mock <IUserStore <User> >();
            var userManager    = new Mock <UserManager <User> >(store.Object, null, null, null, null, null, null, null, null);
            var userService    = new UserService(this.context, userManager.Object, mapper.Object);
            var commentService = new CommentService(this.context, userService, mapper.Object);

            //Act

            await commentService.Add("chris", "product-id", "Comment.");

            var comment = this.context.Comments.First();

            //Assert

            Assert.Single(this.context.Comments);
            Assert.Equal("Comment.", comment.Content);
            Assert.Equal("product-id", comment.ProductId);
            Assert.Equal("user-id", comment.UserId);
        }
示例#4
0
        public ActionResult Add(string articleId, string userName, string email, string site, string content, string commentId)
        {
            try
            {
                AddValidate(articleId, content, userName, email, site);

                int id = _commentService.Add(
                    new Comment
                {
                    ArticleId = Convert.ToInt32(articleId),
                    UserName  = string.IsNullOrEmpty(userName) ? "游客" : userName,
                    Email     = email,
                    Site      = site,
                    Content   = content,
                    ParentId  = Convert.ToInt32(commentId)
                }
                    );

                return(Json(new { code = 200, msg = "ok", data = _commentService.GetById(id.ToString()) }));
            }
            catch (Exception ex)
            {
                LogService.Instance.AddAsync(Models.Level.Error, ex);
                return(Json(new { code = 500, msg = ex.Message }));
            }
        }
示例#5
0
        public HtmlString AddComments(int projectId, string text)
        {
            var user = UserService.Find(t => t.login == User.Identity.Name);

            CommentService.Add(new Comment()
            {
                ProjectId   = projectId,
                Text        = text,
                UserId      = user.Id,
                PublishDate = DateTime.Now
            });
            return(new HtmlString(string.Format(@"
<div class=""item"">
	<div class=""row"">
		<div class=""col-2"">
			<div class=""user-img BlueThemeColor"">

			</div>
		</div>
		<div class=""col-10"">
			<div class=""user-name"">
				{0}
			</div>
			<div class=""comment-text"">
				{1}
			</div>

			<div class=""comment-border""></div>
		</div>
	</div>
</div>
", User.Identity.Name, text)));
        }
示例#6
0
        public void AddTest()
        {
            //Arange
            CommentDTO projectDto = new CommentDTO()
            {
                Id   = "b0",
                Text = "Zero"
            };
            bool isAdded = false;
            Mock <IUnitOfWork>            unitOfWorkMock = new Mock <IUnitOfWork>();
            Mock <IRepository <Comment> > repositoryMock = new Mock <IRepository <Comment> >();

            repositoryMock.Setup(repo => repo.Get(It.IsAny <Expression <Func <Comment, bool> > >()))
            .Returns <Expression <Func <Comment, bool> > >(predicate =>
                                                           _comments.Where(predicate.Compile()).AsQueryable());
            repositoryMock.Setup(repo => repo.Add(It.IsAny <Comment>())).Callback(() => isAdded = true);
            unitOfWorkMock.Setup(getRepo => getRepo.GetRepository <Comment>()).Returns(repositoryMock.Object);
            CommentService _commentService = new CommentService(unitOfWorkMock.Object);

            //Act
            _commentService.Add(projectDto);

            //Assert
            Assert.True(isAdded);
        }
 public void AddCommentTests()
 {
     commentService.Add(new Comment()
     {
         Id = 1, Text = "Content"
     });
     Assert.Equal(1, DbContext.Comments.Count(p => p.Text == "Content"));
 }
        public void TestAdd()
        {
            mockCommentRepository.Setup(x => x.Add(It.IsAny <Comment>())).Returns(cmt);
            var     testService = new CommentService(mockCommentRepository.Object, mockPostRepository.Object, Options.Create(_setting));
            Comment comment     = testService.Add(cmt);

            Assert.AreEqual(cmt, comment);
        }
        public void Add_IsCalled_CalledOneTime()
        {
            _commentRepository.Setup(p => p.Add(It.IsAny <Comment>()));

            _sut.Add(new Comment(), It.IsAny <string>());

            _commentRepository.Verify(u => u.Add(It.IsAny <Comment>()), Times.Once);
        }
 public ActionResult Add(Comment _comment, HttpPostedFileBase image)
 {
     _comment.UserID          = _UserService.GetByDefault(x => x.UserName == User.Identity.Name).ID;
     _comment.ProfilePhotoURL = new byte[image.ContentLength];
     image.InputStream.Read(_comment.ProfilePhotoURL, 0, image.ContentLength);
     _CommentService.Add(_comment);
     return(Redirect("/SysAdmin/Comment/List"));
 }
示例#11
0
        // POST: api/Comment
        public IActionResult Post([FromBody] CommentDTO commentDTO)
        {
            var obj = Mapper.Map <CommentDTO, Comment>(commentDTO);

            CommentService.Add(obj);

            return(Ok());
        }
示例#12
0
 public ActionResult Update(Comment model)
 {
     if (ModelState.IsValid)
     {
         cs.Add(model);
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
示例#13
0
        public ActionResult CreateComment(int PostId, string ContenuCom)
        {
            Comment comment = new Comment()
            {
                ContenuCom      = ContenuCom,
                PostId          = PostId,
                ParticipantId   = Int32.Parse(User.Identity.GetUserId()),
                DateCom         = DateTime.Now,
                ParticipantName = User.Identity.GetUserName(),
            };

            CommentService.Add(comment);
            CommentService.Commit();



            return(Json(comment, JsonRequestBehavior.AllowGet));
        }
示例#14
0
        public IActionResult Post([FromBody] CommentRequestBody body)
        {
            var comment = commentService.Add(body.MapTo <CommentToAdd>());

            return(this.CreateHalResponse(comment.MapTo <CommentResponseBody>())
                   .AddLink(LinkTemplates.Comment.Self)
                   .AddLink(LinkTemplates.Comment.Create)
                   .AddLocationHeader(this, comment.Id)
                   .ToActionResult(this, HttpStatusCode.Created));
        }
示例#15
0
        public ActionResult PostComment(CommentDTO comment)
        {
            if (!ModelState.IsValid)
            {
                return(Json(null));
            }

            var dto = CommentService.Add(comment.PostId, comment.Message);

            return(Json(dto));
        }
示例#16
0
        public ActionResult AddComment(CommentVM data)
        {
            Comment comment = new Comment();

            comment.ProductID   = data.ID;
            comment.Content     = data.Content;
            comment.Header      = data.Header;
            comment.CreatedDate = DateTime.Now;
            _commentService.Add(comment);
            return(Redirect("/Web/Product/ProductDetails/" + data.ID));
        }
示例#17
0
        //添加评论
        public JsonResult Add(Comment model)
        {
            var modelDetailDto = serviceDetail.GetListDtoByOrderId(model.OrderId);

            model.RoomId  = modelDetailDto[0].RoomId;
            model.UserId  = currentUser.UserId;
            model.AddTime = DateTime.Now;
            serviceComment.Add(model);
            serviceOrder.UpdateStatus(model.OrderId, Enums.OrderStatus.CommentEnd, Enums.OrderStatus.WaitComment);
            result.code = 1;
            return(Json(result));
        }
示例#18
0
        public ActionResult CommentAdd(CommentDTO comment)
        {
            Comment data = new Comment();
            AppUser user = appUserService.GetByDefault(x => x.UserName == User.Identity.Name);

            data.AppUserID       = user.ID;
            data.CommentUserName = user.UserName;
            data.TweetID         = comment.TweetID;
            data.CommentContent  = comment.CommentContent;
            commentService.Add(data);
            return(Redirect("/Member/Home/Index"));
        }
示例#19
0
        public ActionResult Create(int id, CommentViewModel cvm)
        {
            Comment b = new Comment();

            b.BlogId  = id;
            b.Contenu = cvm.Contenu;
            b.NbrLike = 0;
            commentService.Add(b);
            commentService.Commit();

            return(View());
        }
示例#20
0
        public void ShouldInsertComment()
        {
            string encryptionKey = "abc";
            DBResult <UserProfile> profileDBResult = new DBResult <UserProfile>
            {
                Payload = new UserProfile()
                {
                    EncryptionKey = encryptionKey
                }
            };

            Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>();

            profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(profileDBResult);

            Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>();

            cryptoDelegateMock.Setup(s => s.Encrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text + key);
            cryptoDelegateMock.Setup(s => s.Decrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text.Remove(text.Length - key.Length));

            UserComment userComment = new UserComment()
            {
                UserProfileId   = hdid,
                ParentEntryId   = parentEntryId,
                Text            = "Inserted Comment",
                EntryTypeCode   = CommentEntryType.Medication,
                CreatedDateTime = new DateTime(2020, 1, 1)
            };
            Comment comment = userComment.ToDbModel(cryptoDelegateMock.Object, encryptionKey);

            DBResult <Comment> insertResult = new DBResult <Comment>
            {
                Payload = comment,
                Status  = DBStatusCode.Created
            };

            Mock <ICommentDelegate> commentDelegateMock = new Mock <ICommentDelegate>();

            commentDelegateMock.Setup(s => s.Add(It.Is <Comment>(x => x.Text == comment.Text), true)).Returns(insertResult);

            ICommentService service = new CommentService(
                new Mock <ILogger <CommentService> >().Object,
                commentDelegateMock.Object,
                profileDelegateMock.Object,
                cryptoDelegateMock.Object
                );

            RequestResult <UserComment> actualResult = service.Add(userComment);

            Assert.Equal(Common.Constants.ResultType.Success, actualResult.ResultStatus);
            Assert.True(actualResult.ResourcePayload.IsDeepEqual(userComment));
        }
示例#21
0
        public void AddCommentTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <Comment>(applicationDbContext);
            commentService       = new CommentService(repository);
            commentService.Add(new Comment()
            {
                Id = Guid.NewGuid(), Content = "Content"
            });
            Assert.Equal(1, applicationDbContext.Comments.Count(p => p.Content == "Content"));
        }
        private Tuple <RequestResult <UserComment>, UserComment> ExecuteInsertComment(Database.Constants.DBStatusCode dBStatusCode = Database.Constants.DBStatusCode.Created)
        {
            string encryptionKey = "abc";
            DBResult <UserProfile> profileDBResult = new DBResult <UserProfile>
            {
                Payload = new UserProfile()
                {
                    EncryptionKey = encryptionKey
                }
            };

            Mock <IUserProfileDelegate> profileDelegateMock = new Mock <IUserProfileDelegate>();

            profileDelegateMock.Setup(s => s.GetUserProfile(hdid)).Returns(profileDBResult);

            Mock <ICryptoDelegate> cryptoDelegateMock = new Mock <ICryptoDelegate>();

            cryptoDelegateMock.Setup(s => s.Encrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text + key);
            cryptoDelegateMock.Setup(s => s.Decrypt(It.IsAny <string>(), It.IsAny <string>())).Returns((string key, string text) => text.Remove(text.Length - key.Length));

            UserComment userComment = new UserComment()
            {
                UserProfileId   = hdid,
                ParentEntryId   = parentEntryId,
                Text            = "Inserted Comment",
                EntryTypeCode   = CommentEntryType.Medication,
                CreatedDateTime = new DateTime(2020, 1, 1)
            };
            Comment comment = userComment.ToDbModel(cryptoDelegateMock.Object, encryptionKey);

            DBResult <Comment> insertResult = new DBResult <Comment>
            {
                Payload = comment,
                Status  = dBStatusCode
            };

            Mock <ICommentDelegate> commentDelegateMock = new Mock <ICommentDelegate>();

            commentDelegateMock.Setup(s => s.Add(It.Is <Comment>(x => x.Text == comment.Text), true)).Returns(insertResult);

            ICommentService service = new CommentService(
                new Mock <ILogger <CommentService> >().Object,
                commentDelegateMock.Object,
                profileDelegateMock.Object,
                cryptoDelegateMock.Object
                );

            RequestResult <UserComment> actualResult = service.Add(userComment);

            return(new Tuple <RequestResult <UserComment>, UserComment>(actualResult, userComment));
        }
示例#23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //分页
            int pageNumber = 1;

            if (!Int32.TryParse(Request["page"], out pageNumber))
            {
                pageNumber = 1;
            }

            CommentService commentService = new CommentService();

            //求最大页
            int pageRecord = commentService.GetRecordCount("");
            int maxPage    = 0;

            if (pageRecord / commentService.pageCount == 0)
            {
                maxPage = pageRecord % commentService.pageCount;
            }
            else
            {
                maxPage = pageRecord % commentService.pageCount + 1;
            }
            if (pageNumber > maxPage)
            {
                pageNumber = maxPage;
            }
            commentList = commentService.FindAllComment(pageNumber);

            pageCode = PageUtil.genPagination("/Comments.aspx", commentService.GetRecordCount(""), pageNumber, commentService.pageCount, "");

            //将数据保存到数据库中
            if (IsPostBack)
            {
                uname      = ((User)Session["userList"]).uname;
                comcontent = Request["comcontent"];
                comtime    = DateTime.Now;
                Comment comment = new Comment();
                comment.uname      = uname;
                comment.comtime    = comtime;
                comment.comcontent = comcontent;
                int i = commentService.Add(comment);

                if (i > 0)
                {
                    Response.Redirect("/Comments.aspx");
                }
            }
        }
 public ActionResult <Result <Comment> > Post([FromBody] Comment model)
 {
     try
     {
         model.createdUserId = Current.user.id;
         _commentService.Add(model);
         _logger.LogInformation("Added one Comment");
         return(new Result <Comment>(true, "Comment added successfully"));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error occurred on Comment adding");
         throw ex;
     }
 }
        public async Task <ActionResult <Comment> > PostComment(int id, Comment comment)
        {
            var post = await PostService.Get(id, "Category");

            if (post == null)
            {
                return(NotFound("The post you're trying to comment on doesn't exist"));
            }

            comment.UserId    = AuthService.GetUserId(User);
            comment.CreatedAt = DateTime.Now;
            await CommentService.Add(comment);

            return(Ok(comment));
        }
示例#26
0
        public ActionResult Add(TubeRehber.Model.Entities.Comment data, string ChannelName)
        {
            if (data.comment != null)
            {
                TubeRehber.Model.Entities.Member currentUser = _memberService.GetuserByUserName(HttpContext.User.Identity.Name);
                data.MemberID = currentUser.ID;
                TubeRehber.Model.Entities.Channel channel = _channelService.GetChannelByChannelName(ChannelName);
                data.ChannelID = channel.ID;


                _commentService.Add(data);
                _commentService.Save();
            }
            return(RedirectToAction("Index"));
        }
示例#27
0
        public ActionResult Create(CommentViewModel pvm, PostViewModel id)
        {
            var c = Ps.GetAll();

            foreach (var item in c)
            {
                PostViewModel Cvm = new PostViewModel();
                Cvm.postId    = item.postId;
                Cvm.posttitre = item.posttitre;
                Cvm.content   = item.content;

                /*Cvm.categoryId = item.categoryId;
                 * Cvm.description = item.description;
                 * Cvm.plan = item.plan;
                 * Cvm.goals = item.goals;
                 * Cvm.state = (WebApplication1.Models.stat)stat.To_Do;*/
            }

            // ViewBag.cat = new SelectList(c, "projectId", "projectname");

            Comment p = new Comment();

            p.commentId = pvm.commentId;
            p.postId    = id.postId;
            // p.deadline = pvm.deadline;
            p.content = pvm.content;



            //p.state = (Domain.Entities.state)stat.To_Do;
            //p.ListTask = (ICollection<Domain.Entities.Task>)pvm.ListTask;
            Ts.Add(p);
            Ts.Commit();

            try
            {
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
示例#28
0
        public ActionResult Create(int id, CommentViewModel cvm)
        {
            User        u           = new User();
            UserService userService = new UserService();

            Comment c = new Comment();

            c.CommentId       = cvm.CommentId;
            c.DateCom         = DateTime.Now;
            c.ParticipantId   = int.Parse(User.Identity.GetUserId());;
            c.PostId          = id;
            c.ParticipantName = us.GetUserById(c.ParticipantId).FirstName + " " + us.GetUserById(c.ParticipantId).LastName;
            c.ContenuCom      = cvm.ContenuCom;

            repo.Add(c);
            repo.Commit();

            return(RedirectToAction("../Post/Details", new { id = c.PostId }));
        }
示例#29
0
        public async Task <IActionResult> AddComment([FromForm] AddCommentModel model,
                                                     [FromServices] CommentService commentService)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(this.Notice(new NoticePageViewModel
                {
                    Message = L["Invalid request, please try again later"].Value,
                    RedirectUrl = Url.Action("Topic", "Home", new { id = model.TopicId }),
                    MessageType = NoticePageViewModel.NoticeMessageType.Error
                }));
            }

            var result = await commentService.Add(model);

            this.Response.Cookies.Append(CookieCommentName, model.Name);
            this.Response.Cookies.Append(CookieCommentEmail, model.Email);

            if (result.Success)
            {
                if (result.Data.Status != Core.Enums.CommentStatus.Approved)
                {
                    return(this.Notice(new NoticePageViewModel
                    {
                        Message = L["Your comment has been added successfully and requires an administrator to approve it before it can be displayed"].Value,
                        RedirectUrl = Url.Action("Topic", "Home", new { id = model.TopicId }),
                        MessageType = NoticePageViewModel.NoticeMessageType.Success
                    }));
                }
            }
            else
            {
                return(this.Notice(new NoticePageViewModel
                {
                    Message = result.ErrorMessage,
                    RedirectUrl = Url.Action("Topic", "Home", new { id = model.TopicId }),
                    MessageType = NoticePageViewModel.NoticeMessageType.Error
                }));
            }

            return(this.RedirectToAction("Topic", "Home", new { id = result.Data.TopicId }));
        }
示例#30
0
        public IActionResult AddComment([FromForm] AddCommentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var authorExists = authorService.VerifyIfAuthorExistsByEmail(model.Email);

            if (authorExists)
            {
                var article = articleService.GetArticleById(model.ArticleId);

                var author = authorService.GetAuthorByEmail(model.Email);

                commentService.Add(article, author, model.Content);
            }

            return(Redirect(Url.Action("ViewArticle", "Article", new { id = model.ArticleId })));
        }