/// <summary> /// Implementación de <see cref="IRequestHandler{TRequest, TResponse}.Handle(TRequest, CancellationToken)"/> /// </summary> public async Task <int> Handle(Request request, CancellationToken cancellationToken) { int response = 0; try { CarModelModel model = await _CarModelRepository.Get(request.BrandId, request.Name); if (model == null) { ModelInfo info = new ModelInfo { BrandId = request.BrandId, Name = request.Name }; await _CarModelRepository.Create(info); await _CarModelRepository.Save(); response = info.Id; } else { response = model.Id; } } catch (Exception ex) { CommandExceptionHandler.Handle(ex, request); } return(response); }
/// <summary> /// Implementación de <see cref="IRequestHandler{TRequest, TResponse}.Handle(TRequest, CancellationToken)"/> /// </summary> public async Task <int> Handle(Request request, CancellationToken cancellationToken) { int response = 0; try { BrandModel model = await _BrandRepository.GetByName(request.Name); if (model == null) { BrandInfo brand = new BrandInfo { Name = request.Name }; await _BrandRepository.Create(brand); await _BrandRepository.Save(); response = brand.Id; } else { response = model.Id; } } catch (Exception ex) { CommandExceptionHandler.Handle(ex, request); } return(response); }
/// <summary> /// Implementación de <see cref="IRequestHandler{TRequest, TResponse}.Handle(TRequest, CancellationToken)"/> /// </summary> public async Task <BrandModel> Handle(Request request, CancellationToken cancellationToken) { BrandModel response = null; try { response = await BrandRepository.Get(request.Id); } catch (Exception ex) { CommandExceptionHandler.Handle(ex, request); } return(response); }
/// <summary> /// Implementación de <see cref="IRequestHandler{TRequest, TResponse}.Handle(TRequest, CancellationToken)"/> /// </summary> public async Task <Unit> Handle(Request request, CancellationToken cancellationToken) { try { if (request != null) { BrandInfo brand = new BrandInfo { Id = request.Id, Name = request.Name }; await BrandRepository.Delete(brand); } } catch (Exception ex) { CommandExceptionHandler.Handle(ex, request); } return(Unit.Value); }