Product Shop - 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) and last name (at least 3 characters), and age (optional).
- Products have an id, name (at least 3 characters), price, buyerId (optional), and sellerId as IDs of users.
- Categories have an id and name (from 3 to 15 characters)
Using Entity Framework Code First create a database following the above description.
- 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 method public static string ImportUsers(ProductShopContext context, string inputJson)
and public StartUp
class.
Import the users from the provided file users.json
.
Your method should return string
with a message $"Successfully imported {Users.Count}";
NOTE: You will need method public static string ImportProducts(ProductShopContext context, string inputJson)
and public StartUp
class.
Import the users from the provided file products.json
.
Your method should return string
with message $"Successfully imported {Products.Count}";
NOTE: You will need method public static string ImportCategories(ProductShopContext context, string inputJson)
and public StartUp
class.
Import the users from the provided file categories.json
. Some of the names will be null
, so you donβt have to add them in the database. Just skip the record and continue.
Your method should return string
with message $"Successfully imported {Categories.Count}";
NOTE: You will need method public static string ImportCategoryProducts(ProductShopContext context, string inputJson)
and public StartUp
class.
Import the users from the provided file categories-products.json
.
Your method should return string
with 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 that because of the random generation of the data output probably will be different.
NOTE: You will need method public static string GetProductsInRange(ProductShopContext context)
and public StartUp
class.
Get all products in a specified price range: 500 to 1000 (inclusive). Order them by price (from lowest to highest). Select only the product name, price, and the full name of the seller. Export the result to JSON.
products-in-range.json |
---|
[ β{ ββ"name": "TRAMADOL HYDROCHLORIDE", ββ"price": 516.48, ββ"seller": "Christine Gomez" β}, β{ ββ"name": "Allopurinol", ββ"price": 518.50, ββ"seller": "Kathy Gilbert" β}, β{ ββ"name": "Parsley", ββ"price": 519.06, ββ"seller": "Jacqueline Perez" β}, ... ] |
NOTE: You will need method public static string GetSoldProducts(ProductShopContext context)
and public StartUp
class.
Get all users who have at least 1 sold item with a buyer. Order them by last name, then by first name. Select the person's first and last name. For each of the sold products (products with buyers), select the product's name, price and the buyer's first and last name.
users-sold-products.json |
---|
[ β{ ββ"firstName": "Gloria", ββ"lastName": "Alexander", ββ"soldProducts": [ ββ{ βββ"name": " Metoprolol Tartrate", βββ"price": 1405.74, βββ"buyerFirstName": "Bonnie", βββ"buyerLastName": "Fox" ββ} ββ] β}, ... ] |
NOTE: You will need method public static string GetCategoriesByProductsCount(ProductShopContext context)
and public StartUp
class.
Get all categories. Order them in descending order by the categoryβs products count. For each category select its name, the number of products, the average price of those products (rounded to second digit after the decimal separator) and the total revenue (total price sum and rounded to second digit after the decimal separator) of those products (regardless if they have a buyer or not).
categories-by-products.json |
---|
[ β{ ββ"category": "Garden", ββ"productsCount": 23, ββ"averagePrice": "800.15", ββ"totalRevenue": "18403.47", β}, β{ ββ"category": "Drugs", ββ"productsCount": 22, ββ"averagePrice": "882.20", ββ"totalRevenue": "19408.43" β}, ... ] |
NOTE: You will need method public static string GetUsersWithProducts(ProductShopContext context)
and public StartUp
class.
Get all users who have at least 1 sold product with a buyer. Order them in descending order by the number of sold products with a buyer. Select only their first and last name, age and for each product - name and price. Ignore all null values. Export the results to JSON. Follow the format below to better understand how to structure your data.
users-and-products.json |
---|
{ β"usersCount":54, β"users": β[ ββ{ βββ"lastName": "Stewart", βββ"age": 39, βββ"soldProducts": βββ{ ββββ"count": 9, ββββ"products": ββββ[ βββββ{ ββββββ"name": "Finasteride", ββββββ"price": 1374.01 βββββ}, βββββ{ ββββββ"name": "Glyburide", ββββββ"price": 95.1 βββββ}, βββββ{ ββββββ"name": "GOONG SECRET CALMING BATH ", ββββββ"price": 742.47 βββββ}, βββββ{ ββββββ"name": "EMEND", ββββββ"price": 1365.51 βββββ}, βββββ{ ββββββ"name": "Allergena", ββββββ"price": 109.32 βββββ}, βββββ... ββββ] βββ} ββ}, ββ... β] } |