public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var streamPersisted = _streamRepository.GetStream(request.Id).Result; /* Caso stream nao encontrada nao sera prosseguida a edicao */ if (streamPersisted == null) { throw new NotFoundException("Stream nao encontrada"); } /* Atualizacao dos valores */ streamPersisted.Name = request.Name ?? streamPersisted.Name; streamPersisted.Description = request.Description ?? streamPersisted.Description; streamPersisted.CountryId = request.IdCountry ?? streamPersisted.CountryId; /* Tentativa de persistencia */ var sucesso = await _streamRepository.UpdateStream(streamPersisted); /* Caso o salvar tenha sido bem sucedido */ if (sucesso) { return(Unit.Value); } throw new SaveException("Nao foi possivel salvar, tente novamente"); }
public async Task <Unit> Handle(Command request, CancellationToken cancelation) { Stream stream = await _streamRepository.GetStream(request.Id); if (stream == null) { throw new NotFoundException($"Stream with id {request.Id} not found"); } Boolean result = await _streamRepository.DeleteStream(stream); if (result) { return(Unit.Value); } throw new SaveException("Problem saving changes"); }
public async Task <Stream> Handle(Query request, CancellationToken cancellationToken) { var stream = await _streamRepository.GetStream(request.Id); return(stream); }