Guest User

Guest User

  • Tech Writer
  • 357
  • 120.1k

Message - Request\Response code analysis

Mar 7 2012 9:44 AM
Hi

Im working from an existing code base in order to replicate and implement the Message based Request\Response architecture and wondered if I could be corrected (if needed) on the below code snippet next to my comments please.

// Method declaration which Returns the CustomerResponse type and accepts an input arguement of type CustomerRequest.

public CustomerResponse GetCustomers(CustomerRequest request)

// Local variable declaration which creates an instance of the CustomerReponse and stores the object in the local variable named response.

var response = new CustomerResponse(request.RequestId);

// Sets or Sets the Criteria and which stores it in the local variable criteria?

var criteria = request.Criteria as CustomerCriteria;

// Gets the SortExpression property and stores it in the sort local variable

string sort = criteria.SortExpression;

// Checks if the LoadOptions property contains a string name Customers.

if (request.LoadOptions.Contains("Customers"))

// Creates an enumerable of type Customer called customers.

IEnumerable<Customer> customers;

// If the Criteria does not use the IncludeOrderStatistics property

if (!criteria.IncludeOrderStatistics)

// Invoke the GetCustomers and store the return value in the local variable named customers

customers = _customerDao.GetCustomers(sort);

// Otherise store the GetCustomersWithOrderStatistics in the customers local variable instead

customers = _customerDao.GetCustomersWithOrderStatistics(sort);

/ Set the response Customer property to the customers local variable and run a lambda which will translate to the correct DTO object.

response.Customers = customers.Select(c => Mapper.ToDataTransferObject(c)).ToList();

// Get and store the return value of the Getcustomer method into the local variable named customer.

var customer = _customerDao.GetCustomer(criteria.CustomerId);

// Check if the request LoadOptions property holds the string Orders

if (request.LoadOptions.Contains("Orders"))

// Set the customer Orders property to the GetOrdersByCustomer method.

customer.Orders = _orderDao.GetOrdersByCustomer(customer.CustomerId);

// Set the ToDTO method to the response Customer property.

response.Customer = Mapper.ToDataTransferObject(customer);

// Return the value of the response object.

return response;

Thanks!



Answers (5)