using FileHandBatch1;
class Product
{
public string ProductCode { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public override string ToString()
{
return $"ProductCode: {ProductCode}, Name: {Name}, Price: {Price:C}";
}
}
internal class Program
{
private static void Main(string[] args)
{
// Step 1: Create a generic collection to store products
List<Product> products = new List<Product>();
// Step 2: Accept product details from the user
[Link]("Enter the number of products to add: ");
int numberOfProducts = [Link]([Link]());
for (int i = 0; i < numberOfProducts; i++)
{
[Link]($"\nEnter details for product {i + 1}:");
[Link]("Product Code: ");
string productCode = [Link]();
[Link]("Name: ");
string name = [Link]();
[Link]("Price: ");
decimal price = [Link]([Link]());
[Link](new Product { ProductCode = productCode, Name = name,
Price = price });
}
// Step 3: Store the products in a file
string filePath = "[Link]";
using (StreamWriter writer = new StreamWriter(filePath))
{
foreach (var product in products)
{
[Link]($"{[Link]},{[Link]},
{[Link]}");
}
}
[Link]($"\nProducts have been stored in {filePath}.");
// Step 4: Read the products from the file and display them on the console
[Link]("\nReading products from the file:");
using (StreamReader reader = new StreamReader(filePath))
{
string line;
while ((line = [Link]()) != null)
{
string[] parts = [Link](',');
[Link]($"ProductCode: {parts[0]}, Name: {parts[1]},
Price: {[Link](parts[2]):C}");
}
}
}
}
******
Scaffold-DbContext "Server=(localdb)\MSSQLLocalDB;Database=ProductDB2;Integrated
Security=True;" [Link] -OutputDir Models
[Link]<ProductDb2Context>(options =>
[Link]([Link]("ProductDb2Context")
));
{
"Logging": {
"LogLevel": {
"Default": "Information",
"[Link]": "Warning"
}
},
"ConnectionStrings": {
"ProductDB2Context": "Data Source=(localdb)\\MsSqlLocalDb;Initial
Catalog=ProductDB2;Integrated Security=true;MultipleActiveResultSets=true"
},
"AllowedHosts": "*"
}
add contolller
of entity type