Skip to content

Instantly share code, notes, and snippets.

@Defcoq
Created June 6, 2021 13:16
Show Gist options
  • Save Defcoq/e4e0a1ed9e0a3282ee3284b85de85d8b to your computer and use it in GitHub Desktop.
Save Defcoq/e4e0a1ed9e0a3282ee3284b85de85d8b to your computer and use it in GitHub Desktop.
public class ProductService
{
private Model.ProductService _productService;
public ProductService(Model.ProductService ProductService)
{
_productService = ProductService;
}
public ProductListResponse GetAllProductsFor(ProductListRequest productListRequest)
{
ProductListResponse productListResponse = new ProductListResponse();
try
{
IList<Model.Product> productEntities = _productService.GetAllProductsFor(productListRequest.CustomerType);
productListResponse.Products = productEntities.ConvertToProductListViewModel();
productListResponse.Success = true;
}
catch (System.Data.SqlClient.SqlException ex)
{
// Log the exception...
productListResponse.Success = false;
// Return a friendly error message
productListResponse.Message = "Check that your database is in the correct place. Hint: Check the AttachDbFilename section within App.config in the project ASPPatterns.Chap3.Layered.Repository.";
}
catch (Exception ex)
{
// Log the exception...
productListResponse.Success = false;
// Return a friendly error message
productListResponse.Message = "An error occured";
}
return productListResponse;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment