public ProductListResponse GetAllProductsFor(ProductListRequest request) { ProductListResponse response = new ProductListResponse(); try { IList<Product> products = _modelService.GetAllProducts(request.CustomerType); response.Products = products.ToViews(); response.Success = true; } catch (System.Data.SqlClient.SqlException ex) { // Log the exception... response.Success = false; // Return a friendly error message response.Message = ex.Message; } catch { // 记录日志 // 显示友好的错误信息 response.Success = false; response.Message = "An error occurred"; } return response; }
public void Display() { ProductListRequest request = new ProductListRequest(); request.CustomerType = _productListView.CustomerType; ProductListResponse response = _productService.GetAllProductsFor(request); if (response.Success) { _productListView.Display(response.Products); } else { _productListView.ErrorMessage = response.Message; } }