Skip to content

Commit e090b62

Browse files
committed
model update
1 parent d86717f commit e090b62

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

WebApiLab.DAL/AppDbContext.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,23 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
2424
.IsRequired();
2525

2626
modelBuilder.Entity<Category>().HasData(
27-
new Category { Id = 1, Name = "Ital" }
27+
new Category("Ital") { Id = 1 }
2828
);
2929

3030
modelBuilder.Entity<Product>().HasData(
31-
new Product { Id = 1, Name = "Sör", UnitPrice = 50, CategoryId = 1, ShipmentRegion = ShipmentRegion.Asia },
32-
new Product { Id = 2, Name = "Bor", UnitPrice = 550, CategoryId = 1 },
33-
new Product { Id = 3, Name = "Tej", UnitPrice = 260, CategoryId = 1 },
34-
new Product
31+
new Product("Sör") { Id = 1, UnitPrice = 50, CategoryId = 1, ShipmentRegion = ShipmentRegion.Asia },
32+
new Product("Bor") { Id = 2, UnitPrice = 550, CategoryId = 1 },
33+
new Product("Tej") { Id = 3, UnitPrice = 260, CategoryId = 1 },
34+
new Product("Whiskey")
3535
{
3636
Id = 4,
37-
Name = "Whiskey",
3837
UnitPrice = 960,
3938
CategoryId = 1,
4039
ShipmentRegion = ShipmentRegion.Australia
4140
},
42-
new Product
41+
new Product("Rum")
4342
{
4443
Id = 5,
45-
Name = "Rum",
4644
UnitPrice = 960,
4745
CategoryId = 1,
4846
ShipmentRegion = ShipmentRegion.Eu | ShipmentRegion.NorthAmerica

WebApiLab.DAL/Entities/Category.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ public class Category
44
{
55
public int Id { get; set; }
66

7-
public string Name { get; set; } = null!;
7+
public string Name { get; set; }
88

99
public ICollection<Product> Products { get; } = new List<Product>();
10+
11+
public Category(string name)
12+
{
13+
Name = name;
14+
}
1015
}

WebApiLab.DAL/Entities/OrderItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ public class OrderItem
66

77
public int ProductId { get; set; }
88

9-
public Product? Product { get; set; }
9+
public Product? Product { get; set; } = null!;
1010

1111
public int OrderId { get; set; }
1212

13-
public Order? Order { get; set; }
13+
public Order? Order { get; set; } = null!;
1414

1515
public int Quantity { get; set; }
1616

WebApiLab.DAL/Entities/Product.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Product
77
public int Id { get; set; }
88

99
[Column("ProductName")]
10-
public string Name { get; set; } = null!;
10+
public string Name { get; set; }
1111

1212
public int UnitPrice { get; set; }
1313

@@ -19,5 +19,10 @@ public class Product
1919
public ICollection<Order> Orders { get; } = new List<Order>();
2020

2121
public ShipmentRegion ShipmentRegion { get; set; }
22+
23+
public Product(string name)
24+
{
25+
Name = name;
26+
}
2227
}
2328

0 commit comments

Comments
 (0)