TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
357
121.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!
Reply
Answers (
5
)
I want to migrate from windows apllication to web based applications. Some brief question?
Form Authentication and Unable to load Application.global