Created
June 6, 2021 13:16
-
-
Save Defcoq/e4e0a1ed9e0a3282ee3284b85de85d8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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