Skip to content

Commit 0d72aa7

Browse files
Merge pull request #44 from IgniteUI/vkombov/customers-with-orders
Add customers with orders
2 parents f6d1a80 + 239dc22 commit 0d72aa7

File tree

12 files changed

+108
-23
lines changed

12 files changed

+108
-23
lines changed

NorthwindCRUD/Controllers/CustomersController.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ public ActionResult<CountResultDto> GetCustomersCount()
120120
}
121121
}
122122

123+
[HttpGet("WithOrders")]
124+
public ActionResult<CustomerWithOrdersDto[]> GetAllCustomersWithOrders()
125+
{
126+
try
127+
{
128+
var customers = this.customerService.GetAllCustomersWithOrders();
129+
return Ok(this.mapper.Map<CustomerDb[], CustomerWithOrdersDto[]>(customers));
130+
}
131+
catch (Exception error)
132+
{
133+
logger.LogError(error.Message);
134+
return StatusCode(500);
135+
}
136+
}
137+
123138
[HttpGet("{id}")]
124139
public ActionResult<CustomerDto> GetById(string id)
125140
{
@@ -156,6 +171,21 @@ public ActionResult<OrderDto[]> GetOrdersByCustomerId(string id)
156171
}
157172
}
158173

174+
[HttpGet("{id}/Orders/WithDetails")]
175+
public ActionResult<OrderWithDetailsDto[]> GetOrdersAndOrderDetailsByCustomerId(string id)
176+
{
177+
try
178+
{
179+
var orders = this.orderService.GetOrdersWithDetailsByCustomerId(id);
180+
return Ok(this.mapper.Map<OrderDb[], OrderWithDetailsDto[]>(orders));
181+
}
182+
catch (Exception error)
183+
{
184+
logger.LogError(error.Message);
185+
return StatusCode(500);
186+
}
187+
}
188+
159189
[HttpPost]
160190
[Authorize]
161191
public ActionResult<CustomerDto> Create(CustomerDto model)

NorthwindCRUD/Controllers/RegionsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public ActionResult<RegionDto> GetById(int id)
141141
}
142142

143143
[HttpGet("{id}/Territories")]
144-
public ActionResult<CustomerDto> GetTerritoryByRegionId(int id)
144+
public ActionResult<TerritoryDto[]> GetTerritoryByRegionId(int id)
145145
{
146146
try
147147
{

NorthwindCRUD/Helpers/MappingProfiles.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public MappingProfiles()
1818
CreateMap<TerritoryDto, TerritoryDb>().ReverseMap();
1919
CreateMap<CustomerDto, CustomerDb>().ReverseMap();
2020
CreateMap<OrderDto, OrderDb>().ReverseMap();
21+
CreateMap<CustomerWithOrdersDto, CustomerDb>().ReverseMap();
22+
CreateMap<OrderWithDetailsDto, OrderDb>().ReverseMap();
2123
CreateMap<OrderDetailDto, OrderDetailDb>().ReverseMap();
2224
CreateMap<AddressDto, AddressDb>().ReverseMap();
2325
CreateMap<LoginDto, UserDb>().ReverseMap();

NorthwindCRUD/Models/DbModels/OrderDb.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ public OrderDb()
4646
public bool Completed { get; set; }
4747

4848
public AddressDb? ShipAddress { get; set; }
49+
50+
public ICollection<OrderDetailDb> OrderDetails { get; set; }
4951
}
5052
}

NorthwindCRUD/Models/DbModels/ProductDb.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class ProductDb : IProduct
1010
[DatabaseGenerated(DatabaseGeneratedOption.None)]
1111
public int ProductId { get; set; }
1212

13+
public string Productname { get; set; }
14+
1315
public int? SupplierId { get; set; }
1416

1517
public SupplierDb? Supplier { get; set; }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using NorthwindCRUD.Models.Contracts;
2+
3+
namespace NorthwindCRUD.Models.Dtos
4+
{
5+
public class CustomerWithOrdersDto : CustomerDto, ICustomer
6+
{
7+
public OrderWithDetailsDto[] Orders { get; set; }
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using NorthwindCRUD.Models.Contracts;
2+
3+
namespace NorthwindCRUD.Models.Dtos
4+
{
5+
public class OrderWithDetailsDto : OrderDto, IOrder
6+
{
7+
public OrderDetailDto[] OrderDetails { get; set; }
8+
}
9+
}

NorthwindCRUD/Models/Dtos/ProductDto.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class ProductDto : IProduct
66
{
77
public int ProductId { get; set; }
88

9+
public string ProductName { get; set; }
10+
911
public int? SupplierId { get; set; }
1012

1113
public int? CategoryId { get; set; }

NorthwindCRUD/Providers/DbContextConfigurationProvider.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ public void ConfigureOptions(DbContextOptionsBuilder options)
4242
var connectionString = this.GetSqlLiteConnectionString(tenantId);
4343
connection = new SqliteConnection(connectionString);
4444
memoryCache.Set(cacheKey, connection, GetCacheConnectionEntryOptions());
45-
}
4645

47-
// For SQLite in memory to be shared across multiple EF calls, we need to maintain a separate open connection.
48-
// see post https://stackoverflow.com/questions/56319638/entityframeworkcore-sqlite-in-memory-db-tables-are-not-created
49-
connection.Open();
46+
// For SQLite in memory to be shared across multiple EF calls, we need to maintain a separate open connection.
47+
// see post https://stackoverflow.com/questions/56319638/entityframeworkcore-sqlite-in-memory-db-tables-are-not-created
48+
connection.Open();
5049

51-
options.UseSqlite(connection).EnableSensitiveDataLogging();
50+
options.UseSqlite(connection).EnableSensitiveDataLogging();
5251

53-
SeedDb(options);
52+
SeedDb(options);
53+
}
54+
else
55+
{
56+
options.UseSqlite(connection).EnableSensitiveDataLogging();
57+
}
5458
}
5559
}
5660

NorthwindCRUD/Resources/products.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
},
254254
{
255255
"productId": 22,
256-
"productName": "Gustaf's Kn�ckebr�d",
256+
"productName": "Gustaf's Knäckebröd",
257257
"supplierId": 9,
258258
"categoryId": 5,
259259
"quantityPerUnit": "24 - 500 g pkgs.",
@@ -265,7 +265,7 @@
265265
},
266266
{
267267
"productId": 23,
268-
"productName": "Tunnbr�d",
268+
"productName": "Tunnbröd",
269269
"supplierId": 9,
270270
"categoryId": 5,
271271
"quantityPerUnit": "12 - 250 g pkgs.",
@@ -277,7 +277,7 @@
277277
},
278278
{
279279
"productId": 24,
280-
"productName": "Guaran� Fant�stica",
280+
"productName": "Guaraná Fantástica",
281281
"supplierId": 10,
282282
"categoryId": 1,
283283
"quantityPerUnit": "12 - 355 ml cans",
@@ -289,7 +289,7 @@
289289
},
290290
{
291291
"productId": 25,
292-
"productName": "NuNuCa Nu�-Nougat-Creme",
292+
"productName": "NuNuCa Nuß-Nougat-Creme",
293293
"supplierId": 11,
294294
"categoryId": 3,
295295
"quantityPerUnit": "20 - 450 g glasses",
@@ -301,7 +301,7 @@
301301
},
302302
{
303303
"productId": 26,
304-
"productName": "Gumb�r Gummib�rchen",
304+
"productName": "Gumbär Gummibärchen",
305305
"supplierId": 11,
306306
"categoryId": 3,
307307
"quantityPerUnit": "100 - 250 g bags",
@@ -325,7 +325,7 @@
325325
},
326326
{
327327
"productId": 28,
328-
"productName": "R�ssle Sauerkraut",
328+
"productName": "Rössle Sauerkraut",
329329
"supplierId": 12,
330330
"categoryId": 7,
331331
"quantityPerUnit": "25 - 825 g cans",
@@ -337,7 +337,7 @@
337337
},
338338
{
339339
"productId": 29,
340-
"productName": "Th�ringer Rostbratwurst",
340+
"productName": "Thüringer Rostbratwurst",
341341
"supplierId": 12,
342342
"categoryId": 6,
343343
"quantityPerUnit": "50 bags x 30 sausgs.",
@@ -445,7 +445,7 @@
445445
},
446446
{
447447
"productId": 38,
448-
"productName": "C�te de Blaye",
448+
"productName": "Côte de Blaye",
449449
"supplierId": 18,
450450
"categoryId": 1,
451451
"quantityPerUnit": "12 - 75 cl bottles",
@@ -637,7 +637,7 @@
637637
},
638638
{
639639
"productId": 54,
640-
"productName": "Tourti�re",
640+
"productName": "Tourtière",
641641
"supplierId": 25,
642642
"categoryId": 6,
643643
"quantityPerUnit": "16 pies",
@@ -649,7 +649,7 @@
649649
},
650650
{
651651
"productId": 55,
652-
"productName": "P�t� chinois",
652+
"productName": "Pâté chinois",
653653
"supplierId": 25,
654654
"categoryId": 6,
655655
"quantityPerUnit": "24 boxes x 2 pies",
@@ -721,7 +721,7 @@
721721
},
722722
{
723723
"productId": 61,
724-
"productName": "Sirop d'�rable",
724+
"productName": "Sirop d'érable",
725725
"supplierId": 29,
726726
"categoryId": 2,
727727
"quantityPerUnit": "24 - 500 ml bottles",
@@ -757,7 +757,7 @@
757757
},
758758
{
759759
"productId": 64,
760-
"productName": "Wimmers gute Semmelkn�del",
760+
"productName": "Wimmers gute Semmelknödel",
761761
"supplierId": 12,
762762
"categoryId": 5,
763763
"quantityPerUnit": "20 bags x 4 pieces",
@@ -865,7 +865,7 @@
865865
},
866866
{
867867
"productId": 73,
868-
"productName": "R�d Kaviar",
868+
"productName": "Röd Kaviar",
869869
"supplierId": 17,
870870
"categoryId": 8,
871871
"quantityPerUnit": "24 - 150 g jars",
@@ -889,7 +889,7 @@
889889
},
890890
{
891891
"productId": 75,
892-
"productName": "Rh�nbr�u Klosterbier",
892+
"productName": "Rhönbräu Klosterbier",
893893
"supplierId": 12,
894894
"categoryId": 1,
895895
"quantityPerUnit": "24 - 0.5 l bottles",
@@ -901,7 +901,7 @@
901901
},
902902
{
903903
"productId": 76,
904-
"productName": "Lakkalik��ri",
904+
"productName": "Lakkalikööri",
905905
"supplierId": 23,
906906
"categoryId": 1,
907907
"quantityPerUnit": "500 ml",
@@ -913,7 +913,7 @@
913913
},
914914
{
915915
"productId": 77,
916-
"productName": "Original Frankfurter gr�ne So�e",
916+
"productName": "Original Frankfurter grüne Soße",
917917
"supplierId": 12,
918918
"categoryId": 2,
919919
"quantityPerUnit": "12 boxes",

0 commit comments

Comments
 (0)