diff --git a/NorthwindCRUD.Tests/CategroyServiceFixture.cs b/NorthwindCRUD.Tests/CategroyServiceFixture.cs index 95de263..ceeacd3 100644 --- a/NorthwindCRUD.Tests/CategroyServiceFixture.cs +++ b/NorthwindCRUD.Tests/CategroyServiceFixture.cs @@ -28,7 +28,7 @@ public void ShouldUpdateCategory() createdCategory.Name = "Updated Category"; createdCategory.Description = "Updated Description"; - var updatedCategory = DataHelper.CategoryService.Update(createdCategory); + var updatedCategory = DataHelper.CategoryService.Update(createdCategory.CategoryId, createdCategory); Assert.IsNotNull(updatedCategory); updatedCategory = DataHelper2.CategoryService.GetById(updatedCategory.CategoryId); diff --git a/NorthwindCRUD.Tests/EmployeeServiceFixture.cs b/NorthwindCRUD.Tests/EmployeeServiceFixture.cs index 832881f..40cb8d0 100644 --- a/NorthwindCRUD.Tests/EmployeeServiceFixture.cs +++ b/NorthwindCRUD.Tests/EmployeeServiceFixture.cs @@ -29,7 +29,7 @@ public void ShouldUpdateEmployee() var createdEmployee = DataHelper.EmployeeService.Create(employee); createdEmployee.Title = "Director"; - var updatedEmployee = DataHelper.EmployeeService.Update(createdEmployee); + var updatedEmployee = DataHelper.EmployeeService.Update(createdEmployee.EmployeeId, createdEmployee); Assert.IsNotNull(updatedEmployee); updatedEmployee = DataHelper2.EmployeeService.GetById(updatedEmployee.EmployeeId); diff --git a/NorthwindCRUD.Tests/OrderServiceFixture.cs b/NorthwindCRUD.Tests/OrderServiceFixture.cs index 67aebc7..a66e7a6 100644 --- a/NorthwindCRUD.Tests/OrderServiceFixture.cs +++ b/NorthwindCRUD.Tests/OrderServiceFixture.cs @@ -37,7 +37,7 @@ public void ShouldUpdateOrder() order.CustomerId = DataHelper.CreateCustomer().CustomerId; order.EmployeeId = DataHelper.CreateEmployee().EmployeeId; - var updatedOrder = DataHelper.OrderService.Update(order); + var updatedOrder = DataHelper.OrderService.Update(order.OrderId, order); Assert.IsNotNull(updatedOrder); updatedOrder = DataHelper2.OrderService.GetById(updatedOrder.OrderId); diff --git a/NorthwindCRUD.Tests/ProductServiceFixture.cs b/NorthwindCRUD.Tests/ProductServiceFixture.cs index d3be0ba..3293d75 100644 --- a/NorthwindCRUD.Tests/ProductServiceFixture.cs +++ b/NorthwindCRUD.Tests/ProductServiceFixture.cs @@ -27,7 +27,7 @@ public void ShouldUpdateProduct() createdProduct.UnitPrice = 15; createdProduct.UnitsInStock = 50; - var updatedProduct = DataHelper.ProductService.Update(createdProduct); + var updatedProduct = DataHelper.ProductService.Update(createdProduct.ProductId, createdProduct); Assert.IsNotNull(updatedProduct); updatedProduct = DataHelper2.ProductService.GetById(updatedProduct.ProductId); diff --git a/NorthwindCRUD.Tests/RegionServiceFixture.cs b/NorthwindCRUD.Tests/RegionServiceFixture.cs index f263088..4b53c1f 100644 --- a/NorthwindCRUD.Tests/RegionServiceFixture.cs +++ b/NorthwindCRUD.Tests/RegionServiceFixture.cs @@ -27,7 +27,7 @@ public void ShouldUpdateRegion() string originalRegionDescription = region.RegionDescription; region.RegionDescription = "Updated Region"; - var updatedRegion = DataHelper.RegionService.Update(region); + var updatedRegion = DataHelper.RegionService.Update(region.RegionId, region); Assert.IsNotNull(updatedRegion); updatedRegion = DataHelper2.RegionService.GetById(updatedRegion.RegionId); diff --git a/NorthwindCRUD.Tests/ShipperServiceFixture.cs b/NorthwindCRUD.Tests/ShipperServiceFixture.cs index eb6713a..4b88243 100644 --- a/NorthwindCRUD.Tests/ShipperServiceFixture.cs +++ b/NorthwindCRUD.Tests/ShipperServiceFixture.cs @@ -31,7 +31,7 @@ public void ShouldUpdateShipper() shipper.CompanyName = "Updated shipper company"; shipper.Phone = "555-555-5555"; - var updatedShipper = DataHelper.ShipperService.Update(shipper); + var updatedShipper = DataHelper.ShipperService.Update(shipper.ShipperId, shipper); Assert.IsNotNull(updatedShipper); updatedShipper = DataHelper2.ShipperService.GetById(updatedShipper.ShipperId); diff --git a/NorthwindCRUD.Tests/SupplierServiceFixture.cs b/NorthwindCRUD.Tests/SupplierServiceFixture.cs index 60357af..823dafc 100644 --- a/NorthwindCRUD.Tests/SupplierServiceFixture.cs +++ b/NorthwindCRUD.Tests/SupplierServiceFixture.cs @@ -34,7 +34,7 @@ public void ShouldUpdateSupplier() supplier.ContactName = "Updated Contact"; supplier.ContactTitle = "Updated Title"; - var updatedSupplier = DataHelper.SupplierService.Update(supplier); + var updatedSupplier = DataHelper.SupplierService.Update(supplier.SupplierId, supplier); Assert.IsNotNull(updatedSupplier); updatedSupplier = DataHelper2.SupplierService.GetById(updatedSupplier.SupplierId); Assert.IsNotNull(updatedSupplier); diff --git a/NorthwindCRUD.Tests/TerritoryServiceFixture.cs b/NorthwindCRUD.Tests/TerritoryServiceFixture.cs index 4747dc3..b636f6d 100644 --- a/NorthwindCRUD.Tests/TerritoryServiceFixture.cs +++ b/NorthwindCRUD.Tests/TerritoryServiceFixture.cs @@ -29,7 +29,7 @@ public void ShouldUpdateTerritory() createdTerritory.TerritoryDescription = "Updated Territory"; - var updatedTerritory = DataHelper.TerritoryService.Update(createdTerritory); + var updatedTerritory = DataHelper.TerritoryService.Update(createdTerritory.TerritoryId, createdTerritory); Assert.IsNotNull(updatedTerritory); updatedTerritory = DataHelper2.TerritoryService.GetById(updatedTerritory.TerritoryId); diff --git a/NorthwindCRUD/Controllers/CategoriesController.cs b/NorthwindCRUD/Controllers/CategoriesController.cs index bf61678..eb7d20d 100644 --- a/NorthwindCRUD/Controllers/CategoriesController.cs +++ b/NorthwindCRUD/Controllers/CategoriesController.cs @@ -198,16 +198,16 @@ public ActionResult Create(CategoryDto model) } } - [HttpPut] + [HttpPut("{id}")] [Authorize] - public ActionResult Update(CategoryDto model) + public ActionResult Update(int id, CategoryDto model) { try { if (ModelState.IsValid) { var mappedModel = this.mapper.Map(model); - var category = this.categoryService.Update(mappedModel); + var category = this.categoryService.Update(id, mappedModel); if (category != null) { diff --git a/NorthwindCRUD/Controllers/CustomersController.cs b/NorthwindCRUD/Controllers/CustomersController.cs index 756149b..98f6abd 100644 --- a/NorthwindCRUD/Controllers/CustomersController.cs +++ b/NorthwindCRUD/Controllers/CustomersController.cs @@ -209,16 +209,16 @@ public ActionResult Create(CustomerDto model) } } - [HttpPut] + [HttpPut("{id}")] [Authorize] - public ActionResult Update(CustomerDto model) + public ActionResult Update(string id, CustomerDto model) { try { if (ModelState.IsValid) { var mappedModel = this.mapper.Map(model); - var customer = this.customerService.Update(mappedModel); + var customer = this.customerService.Update(id, mappedModel); if (customer != null) { diff --git a/NorthwindCRUD/Controllers/EmployeesController.cs b/NorthwindCRUD/Controllers/EmployeesController.cs index a7b20bf..7974acd 100644 --- a/NorthwindCRUD/Controllers/EmployeesController.cs +++ b/NorthwindCRUD/Controllers/EmployeesController.cs @@ -304,16 +304,16 @@ public ActionResult Create(EmployeeDto model) } } - [HttpPut] + [HttpPut("{id}")] [Authorize] - public ActionResult Update(EmployeeDto model) + public ActionResult Update(int id, EmployeeDto model) { try { if (ModelState.IsValid) { var mappedModel = this.mapper.Map(model); - var employee = this.employeeService.Update(mappedModel); + var employee = this.employeeService.Update(id, mappedModel); if (employee != null) { diff --git a/NorthwindCRUD/Controllers/OrdersController.cs b/NorthwindCRUD/Controllers/OrdersController.cs index e247d03..49b7f0f 100644 --- a/NorthwindCRUD/Controllers/OrdersController.cs +++ b/NorthwindCRUD/Controllers/OrdersController.cs @@ -311,16 +311,16 @@ public ActionResult Create(OrderDto model) } } - [HttpPut] + [HttpPut("{id}")] [Authorize] - public ActionResult Update(OrderDto model) + public ActionResult Update(int id, OrderDto model) { try { if (ModelState.IsValid) { var mappedModel = this.mapper.Map(model); - var order = this.orderService.Update(mappedModel); + var order = this.orderService.Update(id, mappedModel); if (order != null) { return Ok(this.mapper.Map(order)); diff --git a/NorthwindCRUD/Controllers/ProductsController.cs b/NorthwindCRUD/Controllers/ProductsController.cs index e66ac19..976af04 100644 --- a/NorthwindCRUD/Controllers/ProductsController.cs +++ b/NorthwindCRUD/Controllers/ProductsController.cs @@ -277,16 +277,16 @@ public ActionResult Create(ProductDto model) } } - [HttpPut] + [HttpPut("{id}")] [Authorize] - public ActionResult Update(ProductDto model) + public ActionResult Update(int id, ProductDto model) { try { if (ModelState.IsValid) { var mappedModel = this.mapper.Map(model); - var product = this.productService.Update(mappedModel); + var product = this.productService.Update(id, mappedModel); if (product != null) { diff --git a/NorthwindCRUD/Controllers/RegionsController.cs b/NorthwindCRUD/Controllers/RegionsController.cs index 7fde371..72467d5 100644 --- a/NorthwindCRUD/Controllers/RegionsController.cs +++ b/NorthwindCRUD/Controllers/RegionsController.cs @@ -183,16 +183,16 @@ public ActionResult Create(RegionDto model) } } - [HttpPut] + [HttpPut("{id}")] [Authorize] - public ActionResult Update(RegionDto model) + public ActionResult Update(int id, RegionDto model) { try { if (ModelState.IsValid) { var mappedModel = this.mapper.Map(model); - var region = this.regionService.Update(mappedModel); + var region = this.regionService.Update(id, mappedModel); if (region != null) { diff --git a/NorthwindCRUD/Controllers/ShippersController.cs b/NorthwindCRUD/Controllers/ShippersController.cs index 0a28356..a7c3268 100644 --- a/NorthwindCRUD/Controllers/ShippersController.cs +++ b/NorthwindCRUD/Controllers/ShippersController.cs @@ -178,16 +178,16 @@ public ActionResult Create(ShipperDto model) } } - [HttpPut] + [HttpPut("{id}")] [Authorize] - public ActionResult Update(ShipperDto model) + public ActionResult Update(int id, ShipperDto model) { try { if (ModelState.IsValid) { var mappedModel = this.mapper.Map(model); - var shipper = this.shipperService.Update(mappedModel); + var shipper = this.shipperService.Update(id, mappedModel); if (shipper != null) { diff --git a/NorthwindCRUD/Controllers/SuppliersController.cs b/NorthwindCRUD/Controllers/SuppliersController.cs index c8b65e6..280f45e 100644 --- a/NorthwindCRUD/Controllers/SuppliersController.cs +++ b/NorthwindCRUD/Controllers/SuppliersController.cs @@ -178,16 +178,16 @@ public ActionResult Create(SupplierDto model) } } - [HttpPut] + [HttpPut("{id}")] [Authorize] - public ActionResult Update(SupplierDto model) + public ActionResult Update(int id, SupplierDto model) { try { if (ModelState.IsValid) { var mappedModel = this.mapper.Map(model); - var supplier = this.supplierService.Update(mappedModel); + var supplier = this.supplierService.Update(id, mappedModel); if (supplier != null) { diff --git a/NorthwindCRUD/Controllers/TerritoriesController.cs b/NorthwindCRUD/Controllers/TerritoriesController.cs index e96ba59..1a858fe 100644 --- a/NorthwindCRUD/Controllers/TerritoriesController.cs +++ b/NorthwindCRUD/Controllers/TerritoriesController.cs @@ -214,16 +214,16 @@ public ActionResult Create(TerritoryDto model) } } - [HttpPut] + [HttpPut("{id}")] [Authorize] - public ActionResult Update(TerritoryDto model) + public ActionResult Update(string id, TerritoryDto model) { try { if (ModelState.IsValid) { var mappedModel = this.mapper.Map(model); - var territory = this.territoryService.Update(mappedModel); + var territory = this.territoryService.Update(id, mappedModel); if (territory != null) { diff --git a/NorthwindCRUD/ControllersGraphQL/CategoryController.cs b/NorthwindCRUD/ControllersGraphQL/CategoryController.cs index c5ba167..96ff99f 100644 --- a/NorthwindCRUD/ControllersGraphQL/CategoryController.cs +++ b/NorthwindCRUD/ControllersGraphQL/CategoryController.cs @@ -50,10 +50,10 @@ public CategoryDto Create(CategoryDto model) } [Mutation] - public CategoryDto? Update(CategoryDto model) + public CategoryDto? Update(int id, CategoryDto model) { var mappedModel = this.mapper.Map(model); - var category = this.categoryService.Update(mappedModel); + var category = this.categoryService.Update(id, mappedModel); return category != null ? this.mapper.Map(category) : null; } diff --git a/NorthwindCRUD/ControllersGraphQL/CustomerController.cs b/NorthwindCRUD/ControllersGraphQL/CustomerController.cs index af5d0a1..6a6927b 100644 --- a/NorthwindCRUD/ControllersGraphQL/CustomerController.cs +++ b/NorthwindCRUD/ControllersGraphQL/CustomerController.cs @@ -51,10 +51,10 @@ public CustomerDto Create(CustomerDto model) } [Mutation] - public CustomerDto? Update(CustomerDto model) + public CustomerDto? Update(string id, CustomerDto model) { var mappedModel = this.mapper.Map(model); - var customer = this.customerService.Update(mappedModel); + var customer = this.customerService.Update(id, mappedModel); return customer != null ? this.mapper.Map(customer) : null; } diff --git a/NorthwindCRUD/ControllersGraphQL/EmployeeController.cs b/NorthwindCRUD/ControllersGraphQL/EmployeeController.cs index f9cead2..2a56db1 100644 --- a/NorthwindCRUD/ControllersGraphQL/EmployeeController.cs +++ b/NorthwindCRUD/ControllersGraphQL/EmployeeController.cs @@ -51,10 +51,10 @@ public EmployeeDto Create(EmployeeDto model) } [Mutation] - public EmployeeDto? Update(EmployeeDto model) + public EmployeeDto? Update(int id, EmployeeDto model) { var mappedModel = this.mapper.Map(model); - var employee = this.employeeService.Update(mappedModel); + var employee = this.employeeService.Update(id, mappedModel); return employee != null ? this.mapper.Map(employee) : null; } diff --git a/NorthwindCRUD/ControllersGraphQL/OrderController.cs b/NorthwindCRUD/ControllersGraphQL/OrderController.cs index 06eda20..5d22114 100644 --- a/NorthwindCRUD/ControllersGraphQL/OrderController.cs +++ b/NorthwindCRUD/ControllersGraphQL/OrderController.cs @@ -50,10 +50,10 @@ public OrderDto Create(OrderDto model) } [Mutation] - public OrderDto? Update(OrderDto model) + public OrderDto? Update(int id, OrderDto model) { var mappedModel = this.mapper.Map(model); - var order = this.orderService.Update(mappedModel); + var order = this.orderService.Update(id, mappedModel); return order != null ? this.mapper.Map(order) : null; } diff --git a/NorthwindCRUD/Models/Contracts/ICategory.cs b/NorthwindCRUD/Models/Contracts/ICategory.cs index 0826e3d..8596d43 100644 --- a/NorthwindCRUD/Models/Contracts/ICategory.cs +++ b/NorthwindCRUD/Models/Contracts/ICategory.cs @@ -2,7 +2,7 @@ { public interface ICategory { - int CategoryId { get; set; } + int CategoryId { get; } string Description { get; set; } diff --git a/NorthwindCRUD/Models/Contracts/ICustomer.cs b/NorthwindCRUD/Models/Contracts/ICustomer.cs index 3f05c49..95cbf15 100644 --- a/NorthwindCRUD/Models/Contracts/ICustomer.cs +++ b/NorthwindCRUD/Models/Contracts/ICustomer.cs @@ -4,7 +4,7 @@ namespace NorthwindCRUD.Models.Contracts { public interface ICustomer { - string CustomerId { get; set; } + string CustomerId { get; } string CompanyName { get; set; } diff --git a/NorthwindCRUD/Models/Contracts/IEmployee.cs b/NorthwindCRUD/Models/Contracts/IEmployee.cs index 62f4428..1e125b1 100644 --- a/NorthwindCRUD/Models/Contracts/IEmployee.cs +++ b/NorthwindCRUD/Models/Contracts/IEmployee.cs @@ -4,7 +4,7 @@ namespace NorthwindCRUD.Models.Contracts { public interface IEmployee { - int EmployeeId { get; set; } + int EmployeeId { get; } string LastName { get; set; } diff --git a/NorthwindCRUD/Models/Contracts/IOrder.cs b/NorthwindCRUD/Models/Contracts/IOrder.cs index a427a8a..51f3d60 100644 --- a/NorthwindCRUD/Models/Contracts/IOrder.cs +++ b/NorthwindCRUD/Models/Contracts/IOrder.cs @@ -5,7 +5,7 @@ namespace NorthwindCRUD.Models.Contracts { public interface IOrder { - int OrderId { get; set; } + int OrderId { get; } string? CustomerId { get; set; } diff --git a/NorthwindCRUD/Models/Contracts/IProduct.cs b/NorthwindCRUD/Models/Contracts/IProduct.cs index 072cbc8..66bd316 100644 --- a/NorthwindCRUD/Models/Contracts/IProduct.cs +++ b/NorthwindCRUD/Models/Contracts/IProduct.cs @@ -2,7 +2,7 @@ { public interface IProduct { - int ProductId { get; set; } + int ProductId { get; } int? SupplierId { get; set; } diff --git a/NorthwindCRUD/Models/Contracts/IRegion.cs b/NorthwindCRUD/Models/Contracts/IRegion.cs index 95f3b08..9cb7657 100644 --- a/NorthwindCRUD/Models/Contracts/IRegion.cs +++ b/NorthwindCRUD/Models/Contracts/IRegion.cs @@ -2,7 +2,7 @@ { public interface IRegion { - int RegionId { get; set; } + int RegionId { get; } string RegionDescription { get; set; } } diff --git a/NorthwindCRUD/Models/Contracts/IShipper.cs b/NorthwindCRUD/Models/Contracts/IShipper.cs index e8321a0..027524c 100644 --- a/NorthwindCRUD/Models/Contracts/IShipper.cs +++ b/NorthwindCRUD/Models/Contracts/IShipper.cs @@ -2,7 +2,7 @@ { public interface IShipper { - int ShipperId { get; set; } + int ShipperId { get; } string CompanyName { get; set; } diff --git a/NorthwindCRUD/Models/Contracts/ISupplier.cs b/NorthwindCRUD/Models/Contracts/ISupplier.cs index 264a424..5f45064 100644 --- a/NorthwindCRUD/Models/Contracts/ISupplier.cs +++ b/NorthwindCRUD/Models/Contracts/ISupplier.cs @@ -2,7 +2,7 @@ { public interface ISupplier { - int SupplierId { get; set; } + int SupplierId { get; } string? CompanyName { get; set; } diff --git a/NorthwindCRUD/Models/Contracts/ITerritory.cs b/NorthwindCRUD/Models/Contracts/ITerritory.cs index 75d9269..38ac2a0 100644 --- a/NorthwindCRUD/Models/Contracts/ITerritory.cs +++ b/NorthwindCRUD/Models/Contracts/ITerritory.cs @@ -2,7 +2,7 @@ { public interface ITerritory { - string TerritoryId { get; set; } + string TerritoryId { get; } string TerritoryDescription { get; set; } diff --git a/NorthwindCRUD/Models/Dtos/CategoryDto.cs b/NorthwindCRUD/Models/Dtos/CategoryDto.cs index ac04f4b..abc2d15 100644 --- a/NorthwindCRUD/Models/Dtos/CategoryDto.cs +++ b/NorthwindCRUD/Models/Dtos/CategoryDto.cs @@ -5,7 +5,7 @@ namespace NorthwindCRUD.Models.Dtos { public class CategoryDto : ICategory { - public int CategoryId { get; set; } + public int CategoryId { get; private set; } [StringLength(500, ErrorMessage = "Description cannot exceed 500 characters.")] public string Description { get; set; } diff --git a/NorthwindCRUD/Models/Dtos/CustomerDto.cs b/NorthwindCRUD/Models/Dtos/CustomerDto.cs index 47a55ae..0672f5c 100644 --- a/NorthwindCRUD/Models/Dtos/CustomerDto.cs +++ b/NorthwindCRUD/Models/Dtos/CustomerDto.cs @@ -5,7 +5,7 @@ namespace NorthwindCRUD.Models.Dtos { public class CustomerDto : ICustomer { - public string CustomerId { get; set; } + public string CustomerId { get; private set; } [Required(ErrorMessage = "Company Name is required.")] [StringLength(100, ErrorMessage = "Company Name cannot exceed 100 characters.")] diff --git a/NorthwindCRUD/Models/Dtos/EmployeeDto.cs b/NorthwindCRUD/Models/Dtos/EmployeeDto.cs index 31c70c4..1a14c59 100644 --- a/NorthwindCRUD/Models/Dtos/EmployeeDto.cs +++ b/NorthwindCRUD/Models/Dtos/EmployeeDto.cs @@ -7,7 +7,7 @@ namespace NorthwindCRUD.Models.Dtos public class EmployeeDto : IEmployee { [SwaggerSchema("Number automatically assigned to new employee.")] - public int EmployeeId { get; set; } + public int EmployeeId { get; private set; } [Required(ErrorMessage = "Last name is required.")] [StringLength(50, ErrorMessage = "Last name cannot exceed 50 characters.")] diff --git a/NorthwindCRUD/Models/Dtos/OrderDto.cs b/NorthwindCRUD/Models/Dtos/OrderDto.cs index da6c9d8..dc0cc7a 100644 --- a/NorthwindCRUD/Models/Dtos/OrderDto.cs +++ b/NorthwindCRUD/Models/Dtos/OrderDto.cs @@ -6,7 +6,7 @@ namespace NorthwindCRUD.Models.Dtos { public class OrderDto : IOrder { - public int OrderId { get; set; } + public int OrderId { get; private set; } [Required(ErrorMessage = "CustomerId is required.")] public string? CustomerId { get; set; } diff --git a/NorthwindCRUD/Models/Dtos/ProductDto.cs b/NorthwindCRUD/Models/Dtos/ProductDto.cs index 83f5bf4..cdb3232 100644 --- a/NorthwindCRUD/Models/Dtos/ProductDto.cs +++ b/NorthwindCRUD/Models/Dtos/ProductDto.cs @@ -5,7 +5,7 @@ namespace NorthwindCRUD.Models.Dtos { public class ProductDto : IProduct { - public int ProductId { get; set; } + public int ProductId { get; private set; } public string ProductName { get; set; } diff --git a/NorthwindCRUD/Models/Dtos/RegionDto.cs b/NorthwindCRUD/Models/Dtos/RegionDto.cs index 6cec254..c267449 100644 --- a/NorthwindCRUD/Models/Dtos/RegionDto.cs +++ b/NorthwindCRUD/Models/Dtos/RegionDto.cs @@ -4,7 +4,7 @@ namespace NorthwindCRUD.Models.Dtos { public class RegionDto : IRegion { - public int RegionId { get; set; } + public int RegionId { get; private set; } public string RegionDescription { get; set; } } diff --git a/NorthwindCRUD/Models/Dtos/ShipperDto.cs b/NorthwindCRUD/Models/Dtos/ShipperDto.cs index 283b215..a282557 100644 --- a/NorthwindCRUD/Models/Dtos/ShipperDto.cs +++ b/NorthwindCRUD/Models/Dtos/ShipperDto.cs @@ -5,7 +5,7 @@ namespace NorthwindCRUD.Models.Dtos { public class ShipperDto : IShipper { - public int ShipperId { get; set; } + public int ShipperId { get; private set; } [Required(ErrorMessage = "Company Name is required.")] [StringLength(100, ErrorMessage = "Company Name cannot exceed 100 characters.")] diff --git a/NorthwindCRUD/Models/Dtos/SupplierDto.cs b/NorthwindCRUD/Models/Dtos/SupplierDto.cs index 6916760..1d8a57a 100644 --- a/NorthwindCRUD/Models/Dtos/SupplierDto.cs +++ b/NorthwindCRUD/Models/Dtos/SupplierDto.cs @@ -5,7 +5,7 @@ namespace NorthwindCRUD.Models.Dtos { public class SupplierDto : ISupplier { - public int SupplierId { get; set; } + public int SupplierId { get; private set; } [Required(ErrorMessage = "Company Name is required.")] [StringLength(100, ErrorMessage = "Company Name cannot exceed 100 characters.")] diff --git a/NorthwindCRUD/Models/Dtos/TerritoryDto.cs b/NorthwindCRUD/Models/Dtos/TerritoryDto.cs index 75570e2..55847a5 100644 --- a/NorthwindCRUD/Models/Dtos/TerritoryDto.cs +++ b/NorthwindCRUD/Models/Dtos/TerritoryDto.cs @@ -4,7 +4,7 @@ namespace NorthwindCRUD.Models.Dtos { public class TerritoryDto : ITerritory { - public string TerritoryId { get; set; } + public string TerritoryId { get; private set; } public string TerritoryDescription { get; set; } diff --git a/NorthwindCRUD/Services/CategoryService.cs b/NorthwindCRUD/Services/CategoryService.cs index 67e8986..a5157fd 100644 --- a/NorthwindCRUD/Services/CategoryService.cs +++ b/NorthwindCRUD/Services/CategoryService.cs @@ -48,9 +48,9 @@ public CategoryDb Create(CategoryDb model) return categoryEntity.Entity; } - public CategoryDb? Update(CategoryDb model) + public CategoryDb? Update(int id, CategoryDb model) { - var categoryEntity = this.dataContext.Categories.FirstOrDefault(c => c.CategoryId == model.CategoryId); + var categoryEntity = this.dataContext.Categories.FirstOrDefault(c => c.CategoryId == id); if (categoryEntity != null) { categoryEntity.Description = model.Description != null ? model.Description : categoryEntity.Description; diff --git a/NorthwindCRUD/Services/CustomerService.cs b/NorthwindCRUD/Services/CustomerService.cs index c2e6a1b..e3493bc 100644 --- a/NorthwindCRUD/Services/CustomerService.cs +++ b/NorthwindCRUD/Services/CustomerService.cs @@ -73,11 +73,11 @@ public CustomerDb Create(CustomerDb model) return customerEntity.Entity; } - public CustomerDb? Update(CustomerDb model) + public CustomerDb? Update(string id, CustomerDb model) { var customerEntity = this.dataContext.Customers .Include(c => c.Address) - .FirstOrDefault(c => c.CustomerId == model.CustomerId); + .FirstOrDefault(c => c.CustomerId == id); if (customerEntity != null) { diff --git a/NorthwindCRUD/Services/EmployeeService.cs b/NorthwindCRUD/Services/EmployeeService.cs index 722cef5..0151c79 100644 --- a/NorthwindCRUD/Services/EmployeeService.cs +++ b/NorthwindCRUD/Services/EmployeeService.cs @@ -70,11 +70,11 @@ public EmployeeDb Create(EmployeeDb model) return employeeEntity.Entity; } - public EmployeeDb? Update(EmployeeDb model) + public EmployeeDb? Update(int id, EmployeeDb model) { var employeeEntity = this.dataContext.Employees .Include(c => c.Address) - .FirstOrDefault(e => e.EmployeeId == model.EmployeeId); + .FirstOrDefault(e => e.EmployeeId == id); if (employeeEntity != null) { diff --git a/NorthwindCRUD/Services/OrderService.cs b/NorthwindCRUD/Services/OrderService.cs index ae29119..0732741 100644 --- a/NorthwindCRUD/Services/OrderService.cs +++ b/NorthwindCRUD/Services/OrderService.cs @@ -128,7 +128,7 @@ public OrderDb Create(OrderDb model) return orderEntity.Entity; } - public OrderDb? Update(OrderDb model) + public OrderDb? Update(int id, OrderDb model) { if (this.dataContext.Customers.FirstOrDefault(c => c.CustomerId == model.CustomerId) == null) { @@ -147,7 +147,7 @@ public OrderDb Create(OrderDb model) var orderEntity = this.dataContext.Orders .Include(c => c.ShipAddress) - .FirstOrDefault(e => e.OrderId == model.OrderId); + .FirstOrDefault(e => e.OrderId == id); if (orderEntity != null) { diff --git a/NorthwindCRUD/Services/ProductService.cs b/NorthwindCRUD/Services/ProductService.cs index 32089bb..f0bf74f 100644 --- a/NorthwindCRUD/Services/ProductService.cs +++ b/NorthwindCRUD/Services/ProductService.cs @@ -76,7 +76,7 @@ public ProductDb Create(ProductDb model) return productEntity.Entity; } - public ProductDb? Update(ProductDb model) + public ProductDb? Update(int id, ProductDb model) { if (this.dataContext.Categories.FirstOrDefault(c => c.CategoryId == model.CategoryId) == null) { @@ -88,7 +88,7 @@ public ProductDb Create(ProductDb model) throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Supplier), model.SupplierId?.ToString(CultureInfo.InvariantCulture))); } - var productEntity = this.dataContext.Products.FirstOrDefault(p => p.ProductId == model.ProductId); + var productEntity = this.dataContext.Products.FirstOrDefault(p => p.ProductId == id); if (productEntity != null) { productEntity.SupplierId = model.SupplierId != null ? model.SupplierId : productEntity.SupplierId; diff --git a/NorthwindCRUD/Services/RegionService.cs b/NorthwindCRUD/Services/RegionService.cs index 2f5d6d7..ce0bfbc 100644 --- a/NorthwindCRUD/Services/RegionService.cs +++ b/NorthwindCRUD/Services/RegionService.cs @@ -47,9 +47,9 @@ public RegionDb Create(RegionDb model) return regionEntity.Entity; } - public RegionDb? Update(RegionDb model) + public RegionDb? Update(int id, RegionDb model) { - var regionEntity = this.dataContext.Regions.FirstOrDefault(p => p.RegionId == model.RegionId); + var regionEntity = this.dataContext.Regions.FirstOrDefault(p => p.RegionId == id); if (regionEntity != null) { regionEntity.RegionDescription = model.RegionDescription != null ? model.RegionDescription : regionEntity.RegionDescription; diff --git a/NorthwindCRUD/Services/ShipperService.cs b/NorthwindCRUD/Services/ShipperService.cs index b9143f2..3243a37 100644 --- a/NorthwindCRUD/Services/ShipperService.cs +++ b/NorthwindCRUD/Services/ShipperService.cs @@ -47,9 +47,9 @@ public ShipperDb Create(ShipperDb model) return shipperEntity.Entity; } - public ShipperDb? Update(ShipperDb model) + public ShipperDb? Update(int id, ShipperDb model) { - var shipperEntity = this.dataContext.Shippers.FirstOrDefault(p => p.ShipperId == model.ShipperId); + var shipperEntity = this.dataContext.Shippers.FirstOrDefault(p => p.ShipperId == id); if (shipperEntity != null) { shipperEntity.Phone = model.Phone != null ? model.Phone : shipperEntity.Phone; diff --git a/NorthwindCRUD/Services/SupplierService.cs b/NorthwindCRUD/Services/SupplierService.cs index e7a852e..197f34b 100644 --- a/NorthwindCRUD/Services/SupplierService.cs +++ b/NorthwindCRUD/Services/SupplierService.cs @@ -47,9 +47,9 @@ public SupplierDb Create(SupplierDb model) return supplierEntity.Entity; } - public SupplierDb? Update(SupplierDb model) + public SupplierDb? Update(int id, SupplierDb model) { - var supplierEntity = this.dataContext.Suppliers.FirstOrDefault(p => p.SupplierId == model.SupplierId); + var supplierEntity = this.dataContext.Suppliers.FirstOrDefault(p => p.SupplierId == id); if (supplierEntity != null) { supplierEntity.Address = model.Address != null ? model.Address : supplierEntity.Address; diff --git a/NorthwindCRUD/Services/TerritoryService.cs b/NorthwindCRUD/Services/TerritoryService.cs index 5f5c799..6d2b197 100644 --- a/NorthwindCRUD/Services/TerritoryService.cs +++ b/NorthwindCRUD/Services/TerritoryService.cs @@ -59,14 +59,14 @@ public TerritoryDb Create(TerritoryDb model) return territoryEntity.Entity; } - public TerritoryDb? Update(TerritoryDb model) + public TerritoryDb? Update(string id, TerritoryDb model) { if (this.dataContext.Regions.FirstOrDefault(r => r.RegionId == model.RegionId) == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, StringTemplates.InvalidEntityMessage, nameof(model.Region), model.RegionId?.ToString(CultureInfo.InvariantCulture))); } - var territoryEntity = this.dataContext.Territories.FirstOrDefault(p => p.TerritoryId == model.TerritoryId); + var territoryEntity = this.dataContext.Territories.FirstOrDefault(p => p.TerritoryId == id); if (territoryEntity != null) { territoryEntity.TerritoryDescription = model.TerritoryDescription != null ? model.TerritoryDescription : territoryEntity.TerritoryDescription;