public async Task <ActionResult <ActorModel> > Get(int actorId)
        {
            try
            {
                var results = await _actorRepository.GetActorAsync(actorId);

                if (results == null)
                {
                    return(NotFound($"No actor with id, {actorId}, has been found."));
                }

                return(Ok(_mapper.Map <ActorModel>(results)));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Esempio n. 2
0
    public async Task <Actor> GetActorAsync(Guid actorId)
    {
        var actor = await _actorRepository
                    .GetActorAsync(new ExternalActorId(actorId))
                    .ConfigureAwait(false);

        if (actor == null)
        {
            throw new InvalidOperationException($"Actor with id {actorId} not found.");
        }

        return(new Actor(
                   Guid.Parse(actor.Id.Value),
                   string.Empty,
                   string.Empty,
                   string.Empty));
    }
    public async Task <Unit> Handle(DeleteActorCommand request, CancellationToken cancellationToken)
    {
        ArgumentNullException.ThrowIfNull(request, nameof(request));

        _logger.LogInformation("Delete actor with ActorId: {ActorId}.", request.ActorId);

        var actorId = new ActorId(request.ActorId);

        var actor = await _actorRepository.GetActorAsync(actorId).ConfigureAwait(false);

        if (actor != null)
        {
            await _actorRepository.DeleteAsync(actor).ConfigureAwait(false);
        }

        return(Unit.Value);
    }