public GetProductByIdResponse GetProductById(GetProductByIdRequest request) { var response = new GetProductByIdResponse { Errors = new List <Error>() }; try { response.Product = Repository.GetProductById(request.Id); } catch (Exception ex) { response.Errors.Add( new Error { CustomisedMessage = "Unable to get product by id", StackTrace = ex.StackTrace, SystemMessage = ex.Message, }); Logger.Fatal(request); Logger.Fatal(response, ex); } return(response); }
public async Task <ActionResult <GetProductByIdResponse> > GetProduct(Guid id) { _logger.LogDebug($"VND: {HttpContext.Request.Headers.ToArray().ToString()}"); GetProductByIdResponse product = await _catalogService.GetProductByIdAsync(new GetProductByIdRequest { Id = id }); return(Ok(product)); }
public async Task <GetProductByIdResponse> GetProductByIdAsync(GetProductByIdRequest request) { string getProductEndPoint = $"{_catalogServiceUri}/api/v1/products/{request.Id}"; RestClient.SetOpenTracingInfo(request.Headers); GetProductByIdResponse response = await RestClient.GetAsync <GetProductByIdResponse>(getProductEndPoint); return(response); }
/// <summary> /// Gets the product by id.--by Will /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public ProductBE GetProductById(int id) { GetProductByIdRequest request = new GetProductByIdRequest(); request.Id = id; GetProductByIdResponse response = MyChannelFactory.CreateChannel().GetProductById(request); if (response.IsFailed) { throw (new Exception(response.Message)); } return(response.Product); }
/// <summary> /// Gets the product by id.--by Will /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public ProductBE GetProductById(int id) { GetProductByIdRequest request = new GetProductByIdRequest(); request.Id = id; GetProductByIdResponse response = MyChannelFactory.CreateChannel().GetProductById(request); if (response.IsFailed) { ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); log.Error("error", new Exception(response.Message)); log.Fatal("fatal", new Exception(response.Message)); throw (new Exception(response.Message)); } return(response.Product); }
public async Task <GetProductByIdResponse> GetByIdAsync(string productId) { var result = await _productsService.GetByIdAsync(productId); var response = new GetProductByIdResponse(); if (result.IsSuccess) { response.Product = _convertService.Convert <Product, ProductContract>(result.Value); } else { response.ErrorCode = _convertService.Convert <ProductsErrorCodes, ProductsErrorCodesContract>( result.Error.GetValueOrDefault()); } return(response); }
/// <summary> /// Gets the product by id. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public GetProductByIdResponse GetProductById(GetProductByIdRequest request) { GetProductByIdResponse response = new GetProductByIdResponse(); ProductService service = new ProductService(); try { response.Product = service.GetById(request.Id); if (response.Product == null) { response.IsFailed = true; response.Message = "We do not have Product"; } } catch (Exception ex) { response.IsFailed = true; response.Message = ex.Message; } return(response); }
public async Task <GetProductByIdResponse> GetProductById(Guid id) { _logger.LogInformation($"Getting product by id: {id}"); var product = await _productRepository.GetProductById(id); if (product == null) { _logger.LogInformation($"No product with id: {id} found"); return(null); } var getProductByIdResponse = new GetProductByIdResponse { DeliveryPrice = product.DeliveryPrice, Description = product.Description, Id = product.Id, Name = product.Name, Price = product.Price }; return(getProductByIdResponse); }