We will list the customers in this exercise, along with the cumulative value of their orders. This will be similar to exercise 2: we will use aggregation and merging in C# code.The method to implement is IList<Customer> ListCustomers(). The method shall return every customer. The properties of Model.Customer are:Name: the name of the customerZipCode, City, Street: the address fields of the main site of the customerTotalOrders: the cumulative total of all orders of the customer. You have to aggregate the price*amount for each order of a customer to get this total. If a particular customer has no orders, this value shall be null.Follow these steps to solve this exercise:Create and initialize the _customerCollection.List all customers. The customer entity has the list of Sites; the main site is the item MainSiteId points to. Use this value to find the main in among the list.In the collection of the orders, use an aggregation pipeline to calculate the total of all orders for each CustomerId.Finally, you need the "merge" the two result sets. Every customer has a main site; however, not all of them have orders (in which case TotalOrders shall be null).Use the Customers link of the website to test your solution. This will list the data provided by your code in a tabular format. You can use the Add new order functionality from before to create new orders. This must result in an increase in the total for one of the customers.
Question
We will list the customers in this exercise, along with the cumulative value of their orders. This will be similar to exercise 2: we will use aggregation and merging in C# code.The method to implement is IList<Customer> ListCustomers(). The method shall return every customer. The properties of Model.Customer are:Name: the name of the customerZipCode, City, Street: the address fields of the main site of the customerTotalOrders: the cumulative total of all orders of the customer. You have to aggregate the price*amount for each order of a customer to get this total. If a particular customer has no orders, this value shall be null.Follow these steps to solve this exercise:Create and initialize the _customerCollection.List all customers. The customer entity has the list of Sites; the main site is the item MainSiteId points to. Use this value to find the main in among the list.In the collection of the orders, use an aggregation pipeline to calculate the total of all orders for each CustomerId.Finally, you need the "merge" the two result sets. Every customer has a main site; however, not all of them have orders (in which case TotalOrders shall be null).Use the Customers link of the website to test your solution. This will list the data provided by your code in a tabular format. You can use the Add new order functionality from before to create new orders. This must result in an increase in the total for one of the customers.
Solution
The text you provided is a programming exercise that requires you to implement a method in C# to list customers and the cumulative value of their orders. Here's a step-by-step guide on how to solve this:
- Create and initialize the _customerCollection. This will be a collection of
Customerobjects.
List<Customer> _customerCollection = new List<Customer>();
- List all customers. You can do this by iterating over the
_customerCollection.
foreach (var customer in _customerCollection)
{
Console.WriteLine(customer.Name);
}
- For each customer, find the main site. You can do this by using the
MainSiteIdproperty of theCustomerobject.
foreach (var customer in _customerCollection)
{
var mainSite = customer.Sites.FirstOrDefault(site => site.Id == customer.MainSiteId);
Console.WriteLine(mainSite);
}
- Calculate the total of all orders for each customer. You can do this by using an aggregation pipeline. For each
Customerobject, iterate over itsOrderscollection and sum the product ofpriceandamountfor each order.
foreach (var customer in _customerCollection)
{
var totalOrders = customer.Orders.Sum(order => order.Price * order.Amount);
customer.TotalOrders = totalOrders;
}
- Merge the two result sets. If a customer has no orders, set
TotalOrdersto null.
foreach (var customer in _customerCollection)
{
if (!customer.Orders.Any())
{
customer.TotalOrders = null;
}
}
- Test your solution by using the Customers link of the website. This will list the data provided by your code in a tabular format. You can use the Add new order functionality from before to create new orders. This must result in an increase in the total for one of the customers.
Similar Questions
We will list the customers in this exercise, along with the cumulative value of their orders. This will be similar to exercise 2: we will use aggregation and merging in C# code.The method to implement is IList<Customer> ListCustomers(). The method shall return every customer. The properties of Model.Customer are:Name: the name of the customerZipCode, City, Street: the address fields of the main site of the customerTotalOrders: the cumulative total of all orders of the customer. You have to aggregate the price*amount for each order of a customer to get this total. If a particular customer has no orders, this value shall be null.Follow these steps to solve this exercise:Create and initialize the _customerCollection.List all customers. The customer entity has the list of Sites; the main site is the item MainSiteId points to. Use this value to find the main in among the list.In the collection of the orders, use an aggregation pipeline to calculate the total of all orders for each CustomerId.Finally, you need the "merge" the two result sets. Every customer has a main site; however, not all of them have orders (in which case TotalOrders shall be null).Use the Customers link of the website to test your solution. This will list the data provided by your code in a tabular format. You can use the Add new order functionality from before to create new orders. This must result in an increase in the total for one of the customers.
Write a query to retrieve the names of customers who have made multiple purchases and the count of their purchases.
You are tasked with managing sales data for a company. The data includes information about salesmen, customers, and orders. Write a query to find the name and numbers of all salesmen who had more than one customer.The following table is already created, and the records are inserted into the table.The Sample records are given below Input format :The input records are already prepopulated, as given in the problem statement.Output format :The output should include the Salesman_id, Salesman_Name, and Customer_Count for all salesmen who had more than one customer as shown below.Salesman_id Salesman_Name Customer_Count5 Chris Wilson 2Refer to the sample output for the column headers.
ou have an Excel file of 50 orders placed by customers. There are three columns:Column A stores whether a customer is a repeat customer or not. It can only be Yes or NoColumn B stores whether an order was placed on a weekend. It can also only be Yes or NoColumn C stores the order amountWhich of the following is best suited to calculate: the total order amount placed by all repeat customers on a weekend?SUMSUMIFIFSUMSUMIFS
We have following relationorders(order_id,customer_id,order_date,amount)1) Find out the number of orders for each customer by customer_id.2) Find out the total amount by order_id and order_date.3) Find out the number of orders for each customer by customer_id. Show onlycustomer_id with number of orders above 5
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.