Beispiel #1
0
        public List <DtoComputerComment> GetComments(int computerId)
        {
            var commentIds = _uow.ComputerCommentRepository.Get(x => x.ComputerId == computerId).Select(x => x.CommentId).ToList();

            if (commentIds.Count == 0)
            {
                return(new List <DtoComputerComment>());
            }

            var list = new List <DtoComputerComment>();

            foreach (var commentId in commentIds)
            {
                var comment = _uow.CommentRepository.GetById(commentId);
                if (comment == null)
                {
                    continue;
                }
                var computerComment = new DtoComputerComment();
                computerComment.Comment     = comment.CommentText;
                computerComment.CommentTime = comment.CommentTime;
                computerComment.Username    = comment.Username;
                list.Add(computerComment);
            }

            return(list.OrderByDescending(x => x.CommentTime).ToList());
        }
Beispiel #2
0
 public DtoActionResult AddComment(DtoComputerComment comment)
 {
     Request.Method   = Method.POST;
     Request.Resource = string.Format("{0}/AddComment/", Resource);
     Request.AddJsonBody(comment);
     return(new ApiRequest().Execute <DtoActionResult>(Request));
 }
Beispiel #3
0
        protected void buttonUpdate_OnClick(object sender, EventArgs e)
        {
            var dtoComment = new DtoComputerComment();

            dtoComment.ComputerId = ComputerEntity.Id;
            dtoComment.Comment    = txtComment.Text.Replace("\r\n", "<br>");
            var result = Call.ComputerApi.AddComment(dtoComment);

            if (!result.Success)
            {
                EndUserMessage = result.ErrorMessage;
                return;
            }

            PopulateComments();
        }
Beispiel #4
0
        public DtoActionResult AddComment(DtoComputerComment comment, int userId)
        {
            if (string.IsNullOrEmpty(comment.Comment))
            {
                return(new DtoActionResult()
                {
                    ErrorMessage = "Comments Cannot Be Empty"
                });
            }

            var user = new ServiceUser().GetUser(userId);

            if (user == null)
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = "Could Not Determine Current User"
                       }
            }
            ;

            var entityComment = new EntityComment();

            entityComment.CommentText = comment.Comment;
            entityComment.CommentTime = DateTime.Now;
            entityComment.Username    = user.Name;
            _uow.CommentRepository.Insert(entityComment);
            _uow.Save();

            var computerComment = new EntityComputerComment();

            computerComment.ComputerId = comment.ComputerId;
            computerComment.CommentId  = entityComment.Id;
            _uow.ComputerCommentRepository.Insert(computerComment);
            _uow.Save();

            return(new DtoActionResult()
            {
                Success = true, Id = computerComment.Id
            });
        }
Beispiel #5
0
 public DtoActionResult AddComment(DtoComputerComment comment)
 {
     return(_computerServices.AddComment(comment, _userId));
 }