Product Shop XML - svetlilaloli/EntityFramework-SoftUni GitHub Wiki
A products shop holds users, products, and categories for the products. Users can sell and buy products.
- Users have an id, first name (optional), last name, and age (optional).
- Products have an id, name, price, buyerId (optional), and sellerId as IDs of users.
- Categories have an id and name.
Using Entity Framework Code First create a database following the above description.
Constraints:
- Users should have many products sold and many products bought.
- Products should have many categories
- Categories should have many products
- CategoryProducts should map products and categories
NOTE: You will need a method public static string ImportUsers(ProductShopContext context, string inputXml)
and public StartUp
class.
Import the users from the provided file users.xml
.
Your method should return a string with a message $"Successfully imported {Users.Count}";
NOTE: You will need a method public static string ImportProducts(ProductShopContext context, string inputXml)
and public StartUp
class.
Import the products from the provided file products.xml
.
Your method should return a string with a message $"Successfully imported {Products.Count}";
NOTE: You will need a method public static string ImportCategories(ProductShopContext context, string inputXml)
and public StartUp
class.
Import the categories from the provided file categories.xml
.
Some of the names will be null, so you don’t have to add them to the database. Just skip the record and continue.
Your method should return a string with a message $"Successfully imported {Categories.Count}";
NOTE: You will need a method public static string ImportCategoryProducts(ProductShopContext context, string inputXml)
and public StartUp
class.
Import the categories and products ids from the provided file categories-products.xml
.
If provided category or product id, doesn’t exist, skip the whole entry!
Your method should return a string with a message $"Successfully imported {CategoryProducts.Count}";
Write the below-described queries and export the returned data to the specified format. Make sure that Entity Framework generates only a single query for each task.
NOTE: You will need a method public static string GetProductsInRange(ProductShopContext context)
and public StartUp
class.
Get all products in the price range between 500 and 1000 (inclusive). Order them by price (ascending). Select only the product name, price, and the full name of the buyer. Take top 10 records.
Return the list of products in the format provided below.
products-in-range.xml
<?xml version="1.0" encoding="utf-16"?>
<Products>
<Product>
<name>TRAMADOL HYDROCHLORIDE</name>
<price>516.48</price>
</Product>
<Product>
<name>Allopurinol</name>
<price>518.5</price>
<buyer>Wallas Duffyn</buyer>
</Product>
<Product>
<name>Parsley</name>
<price>519.06</price>
<buyer>Brendin Predohl</buyer>
</Product>
...
</Products>
NOTE: You will need a method public static string GetSoldProducts(ProductShopContext context)
and public StartUp
class.
Get all users who have at least 1 sold item. Order them by the last name, then by the first name. Select the person's first and last name. For each of the sold products, select the product's name and price. Take top 5 records.
Return the list of users in the format provided below.
users-sold-products.xml
<?xml version="1.0" encoding="utf-16"?>
<Users>
<User>
<firstName>Almire</firstName>
<lastName>Ainslee</lastName>
<soldProducts>
<Product>
<name>olio activ mouthwash</name>
<price>206.06</price>
</Product>
<Product>
<name>Acnezzol Base</name>
<price>710.6</price>
</Product>
<Product>
<name>ENALAPRIL MALEATE</name>
<price>210.42</price>
</Product>
</soldProducts>
</User>...
</Users>
NOTE: You will need a method public static string GetCategoriesByProductsCount(ProductShopContext context)
and public StartUp
class.
Get all categories. For each category select its name, the number of products, the average price of those products, and the total revenue (total price sum) of those products (regardless of whether they have a buyer or not). Order them by the number of products (descending) then by total revenue.
Return the list of categories in the format provided below.
categories-by-products.xml
<?xml version="1.0" encoding="utf-16"?>
<Categories>
<Category>
<name>Garden</name>
<count>23</count>
<averagePrice>709.94739130434782608695652174</averagePrice>
<totalRevenue>16328.79</totalRevenue>
</Category>
<Category>
<name>Adult</name>
<count>22</count>
<averagePrice>704.41</averagePrice>
<totalRevenue>15497.02</totalRevenue>
</Category>
...
</Categories>
NOTE: You will need a method public static string GetUsersWithProducts(ProductShopContext context)
and public StartUp
class.
Select users who have at least 1 sold product. Order them by the number of sold products (descending). Select only their first, last name, age, count of sold products, and for each product - name and price, sorted by price (descending). Take top 10 records.
Return the list of users in the format provided below.
users-and-products.xml
<Users>
<count>54</count>
<users>
<User>
<firstName>Cathee</firstName>
<lastName>Rallings</lastName>
<age>33</age>
<SoldProducts>
<count>9</count>
<products>
<Product>
<name>Fair Foundation SPF 15</name>
<price>1394.24</price>
</Product>
<Product>
<name>IOPE RETIGEN MOISTURE TWIN CAKE NO.21</name>
<price>1257.71</price>
</Product>
<Product>
<name>ESIKA</name>
<price>879.37</price>
</Product>
<Product>
<name>allergy eye</name>
<price>426.91</price>
</Product>
...
</Users>