Beispiel #1
0
        public async Task <IActionResult> AddPhotoComment(int id, CommentForPostDto commentForPostDto)
        {
            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo == null)
            {
                return(BadRequest("Photo doesn't exist"));
            }
            commentForPostDto.Author   = User.FindFirst(ClaimTypes.Name).Value;
            commentForPostDto.AuthorId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            commentForPostDto.PostId   = id;
            var comment = _mapper.Map <CommentForPost>(commentForPostDto);

            photoFromRepo.Comments.Add(comment);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Could not add comment"));
        }
Beispiel #2
0
        public async Task <IActionResult> Submit(CommentForPostDto commentForPostDto)
        {
            if (await _repo.CommentExists(commentForPostDto.Producer, DateTime.Now))
            {
                return(BadRequest("Comment already exists for this day"));
            }

            _user = _httpContextAccessor.HttpContext.User.Identity.Name;

            var commentToPost = new Comment
            {
                Producer   = commentForPostDto.Producer,
                Content    = commentForPostDto.Content,
                CreatedBy  = _user,
                Created    = DateTime.Now.Date,
                LastEdited = DateTime.Now.Date,
                EditedBy   = _user
            };

            var postedComment = await _repo.Submit(commentToPost);

            return(StatusCode(201));
        }