public override async Task <CommentIdResponse> AddComment(CommentRequest request, ServerCallContext context)
        {
            var comment = new Comment
            {
                ProductId   = request.ProductId,
                LeavedAt    = DateTime.Parse(request.LeavedAt),
                Username    = request.Username,
                Description = request.Description,
                Id          = Guid.NewGuid()
            };

            _log.LogInformation("New comment formed");
            comment = await _comments.Create(comment);

            if (comment != null)
            {
                _log.LogInformation($"Added new comment to database: Id: {comment.Id}," +
                                    $" ProductId: {comment.ProductId}, Leaved at: {comment.LeavedAt.ToShortDateString()}");
                return(new CommentIdResponse {
                    Id = comment.Id.ToString()
                });
            }
            else
            {
                return(new CommentIdResponse {
                    Id = null
                });
            }
        }
        public async Task <IdResource> Handle(CreateCommentCommand command, CancellationToken ct)
        {
            var comment = _mapper.Map <Comment>(command);

            comment.SetInitialTimestamps();

            var id = await _commentsRepository.Create(comment, ct);

            return(new IdResource(id));
        }
Пример #3
0
        public async Task Create(CommentView commentView)
        {
            if (string.IsNullOrWhiteSpace(commentView.Text))
            {
                throw new ArgumentException("Comment is empty");
            }
            var commentId = NewId.Next().ToGuid();

            var comment = _mapper.Map <Comment>(commentView);

            comment.Id = commentId;
            await _commentsRepository.Create(comment);
        }
Пример #4
0
        public async Task <IActionResult> AddComment([FromBody] CommentsDto newCommentDto)
        {
            var comment = _mapper.Map <Comments>(newCommentDto);

            comment.CreatedDate = DateTime.UtcNow;
            await _iCommentsRepository.Create(comment);

            if (await _iCommentsRepository.SaveAll())
            {
                return(Ok(_mapper.Map <CommentsDto>(comment)));
            }

            throw new Exception("Error adding the category");
        }
        public async Task <IActionResult> CreateComment(CommentDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Fill all comments field"));
            }
            var comment = _mapper.Map <Comment>(dto);

            if (await _repos.Create(comment))
            {
                return(Ok("Created comment"));
            }
            return(StatusCode(500));
        }
Пример #6
0
        public IActionResult AddComment(string text, int product_id, int user_id)
        {
            Comment comment = new Comment
            {
                Id         = _commentsRepository.GetAll().Count(),
                User       = _usersRepository.Get(user_id),
                User_Id    = user_id,
                Product    = _productsRepository.Get(product_id),
                Product_Id = product_id,
                Text       = text
            };

            _commentsRepository.Create(comment);
            return(Redirect($"~/Product/About/{product_id}"));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("NotificationId,Description")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                comment.OwnerID = _userManager.GetUserId(User);
                if (!await CheckIfUserAuthorizedForNotification(comment, NotificatinOperations.Create))
                {
                    return(Forbid());
                }
                await _repository.Create(comment);

                await _repository.SaveChangesAsync();

                return(Redirect($"/Notification/Details/{comment.NotificationId}"));
            }
            return(BadRequest());
        }
Пример #8
0
        public bool Create(CreateCommentDto commentDto, User user)
        {
            string guid = Guid.NewGuid().ToString();

            try
            {
                string  url     = _s3Uploader.UploadFile(commentDto.Image, guid);
                Comment comment = CreateComment(commentDto, guid, url);
                _commentsRepository.Create(comment, user.UserId, commentDto.PostId);
            }
            catch (Exception e)
            {
                _log.Error(e);
                return(false);
            }

            NotifyPostingUser(commentDto, user, guid);

            CreateUserReferences(commentDto, user, guid);
            return(true);
        }
        public ActionResult CreateComment(CommentCreateViewModel model, int?idPost)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "For some reason you can not create a comment");
                return(View(model));
            }

            if (!User.Identity.IsAuthenticated)
            {
                return(PartialView("CommentError"));
            }

            var firstOrDefault = _userRepo.Get.FirstOrDefault(u => u.Login == User.Identity.Name);

            if (firstOrDefault == null)
            {
                ModelState.AddModelError("", "For some reason you can not create a comment");
                return(View(model));
            }
            var comment = new Comments
            {
                Content = model.Content,
                IdPost  = idPost ?? 0,
                IdUsers = firstOrDefault.Id,
            };

            _repository.Create(comment);
            model.CreateTime = comment.CreateTime;
            model.User       = firstOrDefault;
            model.Post       = _postRepos.Get.FirstOrDefault(p => p.Id == idPost);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("Comment", model));
            }

            return(RedirectToAction("AllPost", "Post", new { idPost }));
        }
Пример #10
0
 public void Post([FromBody] Comments comment)
 {
     _repository.Create(comment);
 }
 public ActionResult Create(CommentModel comment)
 {
     _commentsRepository.Create(comment);
     return(Ok());
 }
Пример #12
0
 public async Task <Comment> Create(Comment model)
 {
     model.LeftAt = DateTime.Now;
     return(await _comments.Create(model));
 }
Пример #13
0
 public void Create(Comment comment)
 {
     comment.DateTime = DateTimeOffset.UtcNow;
     _commentsRepository.Create(comment);
     _commentsRepository.Save();
 }