public async Task <CommandResult> Handle(DeleteWarrantyCommand request, CancellationToken cancellationToken) { try { var warranty = await _warrantyRepository.GetById(request.Id); if (warranty != null) { warranty.ChangeStatusToCancel(); await _warrantyDbContext.SaveChangesAsync(); return(new CommandResult { IsCompleted = true }); } throw new InvalidOperationException("Not found warranty with given guid"); } catch (Exception ex) { return(new CommandResult { IsCompleted = false, Reason = ex.Message }); } }
public async Task <GetWarrantyInfoResponse> Handle(GetWarrantyInfoRequest request, CancellationToken cancellationToken) { var warranty = await _warrantyRepository.GetById(request.Id); if (warranty != null) { return(warranty.ToResponseDto()); } return(null); }
public async Task <WarrantyDecisionResponse> Handle(WarrantyDecisionRequest request, CancellationToken cancellationToken) { var warranty = await _warrantyRepository.GetById(request.Id); if (warranty != null) { var status = warranty.GetStatus(request.IsInStock); return(new WarrantyDecisionResponse { Decision = status }); } return(null); }