Exemple #1
0
        public static CommentDTO ToDTO(this Comment entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            var result = new CommentDTO() { ID = entity.ID, CreatedDate = entity.CreatedDate };

            result.ContentText = !string.IsNullOrEmpty(entity.Content) ? entity.Content : string.Empty;

            if(entity.Person != null)
            {
                result.Person = entity.Person.ToDTO();
            }

            if(entity.CommentXContents != null && entity.CommentXContents.Count > 0)
            {
                result.Contents = new List<ContentDTO>();

                foreach (var cxc in entity.CommentXContents)
                {
                    if(cxc.Content != null)
                    {
                        var content = cxc.Content.ToDTO();

                        result.Contents.Add(content);
                    }
                }
            }

            return result;
        }
Exemple #2
0
        protected void btnCommentSubmit_Click(object sender, EventArgs e)
        {
            CommentDTO comment = new CommentDTO();
            comment.CommentText = commentBox.Text;
            comment.UserName = "******";
            comment.ArticleID = sessionArticleID;
            comment.CommentDateTime = DateTime.Now;

            DataTransaction.submitComment(comment);
        }
Exemple #3
0
        public async Task OnGetAsync(Guid? id)
        {
            if (!id.HasValue)
                return;
            var item = await pcc.GetPostByIdAsync(id.Value);
            ViewData["Post"] = item.PostId.ToString() + " : " + item.Description.Trim();

            foreach (var cc in item.Comments)
            {
                var cdto = new CommentDTO();
                cdto.PostPostId = cc.PostPostId.ToString();
                cdto.Text = cc.Text;
                cdto.CommentId = cc.CommentId.ToString();
                Comments.Add(cdto);
            }
        }
Exemple #4
0
        public void AddComment_ItemSentToDAL_ValidItemWithParrent(CommentDTO commentDto, Comment parentComment,
                                                                  Game game)
        {
            // Arrange
            _mock.Setup(a => a.Repository <Comment>().GetSingle(It.IsAny <string>())).Returns(parentComment);
            _mock.Setup(a => a.Repository <Game>().FindBy(It.IsAny <Expression <Func <Game, bool> > >()))
            .Returns(new List <Game> {
                game
            });

            // Act
            _commentService.AddEntity(commentDto, game.Key);

            // Assert
            Mock.Verify(_mock);
        }
Exemple #5
0
        public void AddCommentToPost(int id, CommentDTO comment)
        {
            try
            {
                var client       = new MongoClient(_conn);
                var db           = client.GetDatabase(_DbName);
                var posts        = db.GetCollection <PostDTO>("Posts");
                var UpdateFilter = Builders <PostDTO> .Update.AddToSet("Comments", comment);

                posts.UpdateOne(g => g.PostId == id, UpdateFilter);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
 public void ShowComments()
 {
     commentBLL = new CommentBLL();
     commentDTO = commentBLL.GetApprovedComments();
     dataGridView1.DataSource                           = commentDTO.Comments;
     dataGridView1.Columns["ID"].Visible                = false;
     dataGridView1.Columns["Title"].HeaderText          = "標題";
     dataGridView1.Columns["CommentContent"].HeaderText = "內容";
     dataGridView1.Columns["MemberID"].Visible          = false;
     dataGridView1.Columns["Member"].HeaderText         = "會員";
     dataGridView1.Columns["AddDate"].HeaderText        = "留言時間";
     dataGridView1.Columns["IsApproved"].Visible        = false;
     dataGridView1.Columns["MealID"].Visible            = false;
     dataGridView1.Columns["MealName"].HeaderText       = "評論餐點";
     dataGridView1.Columns["Rating"].HeaderText         = "評分";
 }
Exemple #7
0
        public async Task <ActionResult <CommentDTO> > PostComment(CommentDTO CommentDTO)
        {
            var comment = new Comment
            {
                QuestionId = CommentDTO.QuestionId,
                Text       = CommentDTO.Text
            };

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

            return(CreatedAtAction(
                       nameof(GetComment),
                       new { id = comment.Id },
                       CommentToDTO(comment)));
        }
Exemple #8
0
        private CommentDTO ToDTO(Comment r)
        {
            CommentDTO dto = new CommentDTO();

            dto.CreateDateTime = r.CreateDateTime;
            dto.Uid            = r.User.Id;
            dto.Context        = r.Context;
            dto.PhoneNum       = r.User.PhoneNum;
            dto.htmlcode       = r.Raiders.content;
            dto.title          = r.Raiders.title;
            dto.Email          = r.User.Email;
            dto.UserName       = r.User.NickName;
            dto.Id             = r.Id;

            return(dto);
        }
Exemple #9
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CommentDTO = await _context.CommentDTO
                         .Include(c => c.Post).FirstOrDefaultAsync(m => m.CommentId == id);

            if (CommentDTO == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public ActionResult Update(int id)
        {
            Comment    Comment    = _CommentService.GetByID(id);
            CommentDTO CommentDTO = new CommentDTO()
            {
                ID              = Comment.ID,
                Authority       = Comment.Authority,
                CommentContent  = Comment.CommentContent,
                CompanyName     = Comment.CompanyName,
                CustomerName    = Comment.CustomerName,
                Email           = Comment.Email,
                ProfilePhotoURL = Comment.ProfilePhotoURL,
            };

            return(View(CommentDTO));
        }
 public ActionResult <IEnumerable <CommentDTO> > Delete(CommentDTO dto)
 {
     try
     {
         _deleteCommentCommand.Execute(dto);
         return(NoContent());
     }
     catch (EntityNotFoundException)
     {
         return(NotFound());
     }
     catch (Exception)
     {
         return(StatusCode(500));
     }
 }
        public void RemoveComment_RightActivityIdButNonExistingUserId_ReturnsNotFound()
        {
            DateTime   date       = DateTime.Today;
            TimeOfDay  timeOfDay  = TimeOfDay.AVOND;
            int        activityId = 1;
            int        userId     = -2;
            CommentDTO commentDTO = new CommentDTO()
            {
                Comment = "Dit was een zeer leuke activiteit"
            };

            _dayActivityRepository.Setup(d => d.GetCustomDayActivity(date, timeOfDay, activityId)).Returns(_dummyDBContext.DayActivity1);

            ActionResult <Attendance> actionResult = _controller.RemoveComment(date, timeOfDay, activityId, userId);

            Assert.IsType <NotFoundResult>(actionResult?.Result);
        }
Exemple #13
0
        /// <summary>
        /// Creates a new comment.
        /// </summary>
        /// <param name="commentDTO">  </param>
        /// <exception cref="ArgumentNullException">
        ///  if <paramref name="commentDTO"/> is <c>null</c>.
        /// </exception>
        public void Create(CommentDTO commentDTO)
        {
            if (commentDTO == null)
            {
                throw new ArgumentNullException(nameof(commentDTO));
            }
            Comment newComment = new Comment()
            {
                Date    = DateTime.Now,
                Profile = _unitOfWork.UserProfileRepository.Find(profile => profile.Id == commentDTO.UserId).SingleOrDefault(),
                Article = _unitOfWork.ArticleRepository.Get(commentDTO.ArticleId),
                Body    = commentDTO.Body
            };

            _unitOfWork.CommentRepository.Create(newComment);
            _unitOfWork.Save();
        }
Exemple #14
0
        public IHttpActionResult PostComment(int postId, [FromBody] CommentViewModel comment)
        {
            if (comment == null)
            {
                return(BadRequest());
            }

            comment.PostId = postId;
            CommentDTO commentDTO = Mapper.Map <CommentDTO>(comment);
            bool       success    = commentService.AddComment(commentDTO, User.Identity.Name);

            if (success)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Exemple #15
0
 public static Comment MapDTOToComment(this CommentDTO c)
 {
     try
     {
         var comment = new Comment()
         {
             ID          = c.ID,
             ReviewID    = c.ReviewID,
             Description = c.Description
         };
         return(comment);
     }
     catch (Exception)
     {
         return(new Comment());
     }
 }
        public bool FlagComment(CommentDTO comment)
        {
            bool result;

            try
            {
                var tmp = db.Comment.Where(x => x.Id == comment.Id).SingleOrDefault();
                tmp.isFlagged = true;
                db.SaveChanges();
                result = true;
            }
            catch (Exception)
            {
                result = false;
            }
            return(result);
        }
Exemple #17
0
        public bool InsertComment(CommentDTO comment)
        {
            this.ConnectToDatabase();
            string Query = "insert into COMMENT values('" + comment.CardId + "','" +
                           comment.UserId + "','" + comment.Content + "',@time,'" +
                           comment.CmtIndex + "');";

            //This is command class which will handle the query and connection object.
            MySqlCommand command = new MySqlCommand(Query, mySQLConnection);

            command.Parameters.Add("@time", MySqlDbType.DateTime).Value = comment.Time;
            command.ExecuteNonQuery();


            this.Close();
            return(true);
        }
Exemple #18
0
        public IActionResult Put(Guid id, Guid CommId, [FromBody] CommentDTO value)
        {
            if (Guid.Parse(HttpContext.Session.GetString("userId")) != commentsCollection.Find(n => n.Id == CommId).FirstOrDefault().AuthorId)
            {
                return(Forbid());
            }
            var update = Builders <Comment> .Update.Set(c => c.Content, value.Content).Set(c => c.Date, DateTime.Now);

            var updateRes = commentsCollection.UpdateOne(c => c.Id == CommId, update);

            if (updateRes.MatchedCount == 0)
            {
                return(NotFound("Comment with this id not found"));
            }

            return(new ObjectResult(commentsCollection.Find(c => c.Id == CommId).FirstOrDefault()));
        }
Exemple #19
0
 public IActionResult DeleteComment(int id)
 {
     try
     {
         CommentDTO comment = _commentService.Get(id);
         if (comment != null)
         {
             _commentService.Delete(comment.Id);
         }
         return(RedirectToAction("AllComments", "Home"));
     }
     catch (ValidationException ex)
     {
         ModelState.AddModelError(ex.Property, ex.Message);
     }
     return(RedirectToAction("Index", "Home"));
 }
        public async Task <CommentDTO> GetCommentAsync(int commentId)
        {
            Comment comment = await db.Comments.GetAsync(commentId);

            if (comment == null)
            {
                return(null);
            }
            var commentDTO = new  CommentDTO(comment.Id,
                                             comment.Text,
                                             comment.Create_Id,
                                             await db.Users.ExtractFullNameAsync(comment.Create_Id),
                                             comment.Create_Date,
                                             comment.Mod_Date);

            return(commentDTO);
        }
        public async Task <OperationDetails> UpdateCommentAsync(CommentDTO commentDTO)
        {
            if (commentDTO == null)
            {
                return(new OperationDetails(false, "Comment  is null", "UpdateComment"));
            }
            var comment = await _database.commentRepository.GetByIdAsync(commentDTO.CommentId);

            if (comment == null)
            {
                return(new OperationDetails(false, "Comment with this id is null", "UpdateComment"));
            }
            _database.commentRepository.Update(_mapper.Map(commentDTO, comment));
            await _database.SaveAsync();

            return(new OperationDetails(true, "User is Updated", "Update"));
        }
Exemple #22
0
 public CommentDTO Create(CommentDTO commentDto)
 {
     try
     {
         Mapper.Initialize(cfg => cfg.CreateMap <CommentDTO, Comment>());
         var comment = Mapper.Map <CommentDTO, Comment>(commentDto);
         comment.ApplicationUser = _unitOfWork.UserManager.FindById(comment.ApplicationUserId);
         comment.Post            = _unitOfWork.Posts.GetById(comment.PostId);
         _unitOfWork.Comments.Create(comment);
         _unitOfWork.Save();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(null);
 }
        public void GetComment_GetCommentWithId2_ReturnComment()
        {
            // Arrange
            CommentDTO comment = Mapper.Map <CommentDTO>(unitOfWork.CommentManager.Get(2));

            // Act
            CommentDTO result = service.GetComment(2);

            // Assert
            Assert.AreEqual(comment.Id, result.Id);
            Assert.AreEqual(comment.Text, result.Text);
            Assert.AreEqual(comment.AuthorId, result.AuthorId);
            Assert.AreEqual(comment.PostId, result.PostId);
            Assert.AreEqual(comment.ParentId, result.ParentId);
            Assert.AreEqual(comment.IsApproved, result.IsApproved);
            Assert.AreEqual(comment.Date, result.Date);
        }
Exemple #24
0
        public CommentDTO GetComment(int commentId)
        {
            var comment = db.Comments.Get(commentId);

            if (comment == null)
            {
                return(null);
            }
            var commentDTO = new CommentDTO(comment.Id,
                                            comment.Text,
                                            comment.Create_Id,
                                            db.Users.ExtractFullName(comment.Create_Id),
                                            comment.Create_Date,
                                            comment.Mod_Date);

            return(commentDTO);
        }
Exemple #25
0
        public void IsCreateSuccessful_should_be_return_0_if_commentdto_not_exists()
        {
            // Arrange
            CommentDTO  commentDTO = new CommentDTO();
            Post        post       = new Post();
            List <User> listUser   = new List <User>();

            mockPostRepository.Setup(c => c.GetById(It.IsAny <int?>()))
            .Returns(post);
            mockUserRepository.Setup(c => c.GetAll())
            .Returns(listUser.AsQueryable());
            //Act
            int?result = commentService.IsCreateSuccessful(commentDTO);

            //Assert
            Assert.Equal(0, result);
        }
Exemple #26
0
        public async Task <ActionResult> Put(long id, [FromBody] CommentDTO updatedComment)
        {
            logger.LogInformation("Calling put for object: {@0}", updatedComment);
            try
            {
                Comment modifiedComment = await repository.UpdateAsync(mappingProvider.Map <Comment>(updatedComment));

                return(Ok(mappingProvider.Map <CommentDTO>(modifiedComment)));
                //[Note] - zwracać zawsze aktualny status z bazy - Zwracać ten updatedComment, czy raczej powinienem zwracać z repo obiekt na nowo zaczytany z bazy
                //(żeby np. wyeliminować przekłamanie, gdyby coś zostało ustawione na bazie inaczej)?
            }
            catch (BlogPostsDomainException)
            {
                logger.LogWarning("There was nothing to update");
                return(NotFound(id));
            }
        }
Exemple #27
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CommentDTO = await _context.CommentDTO.FindAsync(id);

            if (CommentDTO != null)
            {
                _context.CommentDTO.Remove(CommentDTO);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemple #28
0
        public void InsertCommentOnActorId(CommentDTO cmt)
        {
            var     film = context.Films.Find(cmt.FilmId);
            Comment cm   = new Comment
            {
                CommentContent = cmt.Content,
                CommentActorId = cmt.ActorId,
                CommentAverage = cmt.Average,
                CommentAvatar  = cmt.Avatar,
                CommentDate    = cmt.Date
            };

            film.Comments.Add(cm);
            cm.Film = film;
            context.Comments.Add(cm);
            context.SaveChanges();
        }
        public List <CommentDTO> GetAll()
        {
            List <CommentDTO> comments = new List <CommentDTO>();

            foreach (var comment in unitOfWork.CommentRepository.GetAll())
            {
                var newComment = new CommentDTO();
                newComment.Id              = comment.Id;
                newComment.CommentContent  = comment.CommentContent;
                newComment.ArticleId       = comment.ArticleId;
                newComment.Date            = comment.Date;
                newComment.UserName        = comment.UserName;
                newComment.ParentCommentId = comment.ParentCommentId;
                comments.Add(newComment);
            }
            return(comments);
        }
Exemple #30
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CommentDTO = await _context.CommentDTO
                         .Include(c => c.Post).FirstOrDefaultAsync(m => m.CommentId == id);

            if (CommentDTO == null)
            {
                return(NotFound());
            }
            ViewData["PostPostId"] = new SelectList(_context.Set <PostDTO>(), "PostId", "PostId");
            return(Page());
        }
Exemple #31
0
        public async Task <OperationDetails> CreateCommentAsync(CommentDTO commentDTO)
        {
            if (commentDTO == null)
            {
                return(new OperationDetails("Comment is null", false));
            }
            var customer = await _dataBase.customerRepository.GetWhereAsync(c => c.Phone == commentDTO.Phone && c.Name == commentDTO.Name);

            if (customer.Count == 0)
            {
                return(new OperationDetails("You can not leave a comment", false));
            }
            _dataBase.commentRepository.Create(_mapper.Map <Comment>(commentDTO));
            await _dataBase.SaveAsync();

            return(new OperationDetails("Comment is created!", true));
        }
Exemple #32
0
        public ICollection <CommentDTO> GetComments()
        {
            using (var db = new SovaContext())
            {
                var comments = db.Comments.ToList();
                List <CommentDTO> commentsDTO = new List <CommentDTO>();

                foreach (var c in comments)
                {
                    var commentsPost = db.Posts.Where(i => i.Id == c.PostId).FirstOrDefault();
                    var newComment   = new CommentDTO(c.CommentId, c.PostId, c.CommentText, c.CommentScore, c.CommentCreateDate, c.OwnerUserId
                                                      , commentsPost, GetUserByCommentId(c.CommentId));
                    commentsDTO.Add(newComment);
                }
                return(commentsDTO);
            }
        }