|
@page "/P1"
@using FakerDotNet
@if (products != null)
{
<table class="table table-striped table-bordered table-hover" itemscope="@products">
<thead class="thead-light">
<th>نام محصول</th>
<th>برند</th>
<th>قیمت</th>
<th>توضیحات</th>
<th>ویژگی ها</th>
<th>ابعاد</th>
<th>وزن</th>
<th>تصاویر</th>
<th>موجودی</th>
<th>کشور سازنده</th>
<th>واحد فروش</th>
<th>تاریخ انقضا</th>
<th>شرایط بازگشت</th>
<th>نحوه ارسال</th>
<th>توضیحات فنی</th>
<th>امتیاز مشتری</th>
<th>تعداد بازدید</th>
<th>شناسه گروه کالا</th>
</thead>
@foreach (var context in products)
{
<tbody>
<td>@context.Name</td>
<td>@context.Brand</td>
<td>@context.Price</td>
<td>@context.Description</td>
<td>@context.Features</td>
<td>@context.Dimensions</td>
<td>@context.Weight</td>
<td>@context.Images</td>
<td>@context.Inventory</td>
<td>@context.CountryOfOrigin</td>
<td>@context.UnitOfSale</td>
<td>@context.ExpirationDate</td>
<td>@context.ReturnPolicy</td>
<td>@context.ShippingMethod</td>
<td>@context.TechnicalSpecifications</td>
<td>@context.CustomerRating</td>
<td>@context.ViewCount</td>
<td>@context.CategoryId</td>
</tbody>
}
</table>
}
@code {
public List<Data.Product> products = new List<Data.Product>();
protected override void OnInitialized()
{
MakeData();
}
public void MakeData()
{
// ایجاد دسته بندی ها
var categories = new List<Data.Category>
{
new Data.Category {Id = 1, Name = "لپ تاپ", Description = "لپ تاپ های مختلف" },
new Data.Category {Id = 2, Name = "تبلت", Description = "تبلت های مختلف" },
new Data.Category {Id = 3, Name = "موبایل", Description = "موبایل های مختلف" },
new Data.Category {Id = 3, Name = "کجت", Description = "گجت های مختلف" },
};
for (int i = 0; i < 200; i++)
{
//var Faker = new Faker();
var product = new Data.Product
{
Name = Faker.Commerce.ProductName(),
Brand = Faker.Company.Name(),
Price = (decimal)Faker.Random.Element(new[] { 1, 2, 3, 4, 5 }),
Description = Faker.Commerce.PromotionCode(),
Features = Faker.Commerce.Department(),
Dimensions = $"{Faker.Random.Element(new[] { 1, 2, 3, 4, 5 }) } x {Faker.Random.Element(new[] { 1, 2, 3, 4, 5 }) } x {Faker.Random.Element(new[] { 1, 2, 3, 4, 5 }) } cm",
Weight = (decimal)Faker.Random.Element(new[] { 1, 2, 3, 4, 5 }),
Images = Faker.Internet.Url(),
Inventory = Faker.Random.Element(new[] { 1, 2, 3, 4, 5 }),
CountryOfOrigin = Faker.Address.Country(),
UnitOfSale = Faker.Commerce.Department(),
ExpirationDate = Faker.Date.Forward(365),
ReturnPolicy = Faker.Commerce.Material(),
ShippingMethod = Faker.Company.Bs(),
TechnicalSpecifications = Faker.Commerce.Material(),
CustomerRating = (decimal)Faker.Random.Element(new[] { 1, 2, 3, 4, 5 }),
ViewCount = Faker.Random.Element(new[] { 1, 2, 3, 4, 5 }),
CategoryId = GetRndNum()
};
products.Add(product);
}
}
private int GetRndNum()
{
Random rnd = new Random();
int randomNumber = rnd.Next(1, 5);
switch (randomNumber)
{
case 1:
return 1;
case 2:
return 2;
case 3:
return 3;
case 4:
return 4;
default:
throw new Exception("Invalid random number generated.");
}
}
}
|