Skip to content

Commit a180b3c

Browse files
committed
Fix invalid entity message formatting in
OrderService, ProductService, and TerritoryService
1 parent a25300a commit a180b3c

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

NorthwindCRUD/Services/OrderService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ public OrderDb Create(OrderDb model)
7676
{
7777
if (this.dataContext.Customers.FirstOrDefault(c => c.CustomerId == model.CustomerId) == null)
7878
{
79-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Customer), model.CustomerId?.ToString()));
79+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Customer), model.CustomerId?.ToString(CultureInfo.InvariantCulture)));
8080
}
8181

8282
if (this.dataContext.Employees.FirstOrDefault(e => e.EmployeeId == model.EmployeeId) == null)
8383
{
84-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Employee), model.EmployeeId.ToString()));
84+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Employee), model.EmployeeId?.ToString(CultureInfo.InvariantCulture)));
8585
}
8686

8787
if (this.dataContext.Shippers.FirstOrDefault(s => s.ShipperId == model.ShipperId) == null)
8888
{
89-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Shipper), model.ShipperId.ToString()));
89+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Shipper), model.ShipperId?.ToString(CultureInfo.InvariantCulture)));
9090
}
9191

9292
var id = IdGenerator.CreateDigitsId();
@@ -123,12 +123,12 @@ public OrderDb Create(OrderDb model)
123123

124124
if (this.dataContext.Employees.FirstOrDefault(e => e.EmployeeId == model.EmployeeId) == null)
125125
{
126-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Employee), model.EmployeeId.ToString()));
126+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Employee), model.EmployeeId?.ToString(CultureInfo.InvariantCulture)));
127127
}
128128

129129
if (this.dataContext.Shippers.FirstOrDefault(s => s.ShipperId == model.ShipperId) == null)
130130
{
131-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Shipper), model.ShipperId.ToString()));
131+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Shipper), model.ShipperId?.ToString(CultureInfo.InvariantCulture)));
132132
}
133133

134134
var orderEntity = this.dataContext.Orders

NorthwindCRUD/Services/ProductService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public ProductDb Create(ProductDb model)
4545
{
4646
if (this.dataContext.Categories.FirstOrDefault(c => c.CategoryId == model.CategoryId) == null)
4747
{
48-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Category), model.CategoryId.ToString()));
48+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Category), model.CategoryId?.ToString(CultureInfo.InvariantCulture)));
4949
}
5050

5151
if (this.dataContext.Suppliers.FirstOrDefault(s => s.SupplierId == model.SupplierId) == null)
5252
{
53-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Supplier), model.SupplierId.ToString()));
53+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Supplier), model.SupplierId?.ToString(CultureInfo.InvariantCulture)));
5454
}
5555

5656
var id = IdGenerator.CreateDigitsId();
@@ -75,12 +75,12 @@ public ProductDb Create(ProductDb model)
7575
{
7676
if (this.dataContext.Categories.FirstOrDefault(c => c.CategoryId == model.CategoryId) == null)
7777
{
78-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Category), model.CategoryId.ToString()));
78+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Category), model.CategoryId?.ToString(CultureInfo.InvariantCulture)));
7979
}
8080

8181
if (this.dataContext.Suppliers.FirstOrDefault(s => s.SupplierId == model.SupplierId) == null)
8282
{
83-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Supplier), model.SupplierId.ToString()));
83+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Supplier), model.SupplierId?.ToString(CultureInfo.InvariantCulture)));
8484
}
8585

8686
var productEntity = this.dataContext.Products.FirstOrDefault(p => p.ProductId == model.ProductId);

NorthwindCRUD/Services/TerritoryService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public TerritoryDb Create(TerritoryDb model)
3333
{
3434
if (this.dataContext.Regions.FirstOrDefault(r => r.RegionId == model.RegionId) == null)
3535
{
36-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Region), model.RegionId.ToString()));
36+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Region), model.RegionId?.ToString(CultureInfo.InvariantCulture)));
3737
}
3838

3939
var id = IdGenerator.CreateDigitsId().ToString(CultureInfo.InvariantCulture);
@@ -58,7 +58,7 @@ public TerritoryDb Create(TerritoryDb model)
5858
{
5959
if (this.dataContext.Regions.FirstOrDefault(r => r.RegionId == model.RegionId) == null)
6060
{
61-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Region), model.RegionId.ToString()));
61+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Region), model.RegionId?.ToString(CultureInfo.InvariantCulture)));
6262
}
6363

6464
var territoryEntity = this.dataContext.Territories.FirstOrDefault(p => p.TerritoryId == model.TerritoryId);

0 commit comments

Comments
 (0)