Exemple #1
0
        public void Execute(ScorePhotoDto request)
        {
            _validator.ValidateAndThrow(request);

            if (_context.Photos.Find(request.PhotoId) == null)
            {
                throw new EntityNotFoundException(request.PhotoId, typeof(Photo));
            }

            if (_context.UserPhotoScores.Any(s => s.PhotoId == request.PhotoId && s.UserId == _actor.Id))
            {
                throw new ActionNotRepeatableException(UseCase.getUseCase(this.Id), _actor);
            }

            var userPhotoScore = _mapper.Map <UserPhotoScore>(request);

            userPhotoScore.UserId = _actor.Id;

            _context.UserPhotoScores.Add(userPhotoScore);

            _context.SaveChanges();
        }
 public IActionResult ScorePhoto(int photoId, [FromBody] ScorePhotoDto dto, [FromServices] IScorePhotoCommand command)
 {
     dto.PhotoId = photoId;
     _executor.ExecuteCommand(command, dto);
     return(NoContent());
 }