Skip to content

Commit 68ead97

Browse files
committed
replace update dto with private set
1 parent 7209e8b commit 68ead97

File tree

6 files changed

+5
-20
lines changed

6 files changed

+5
-20
lines changed

NorthwindCRUD.Tests/CategroyServiceFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void ShouldUpdateCategory()
2828

2929
createdCategory.Name = "Updated Category";
3030
createdCategory.Description = "Updated Description";
31-
var updatedCategory = DataHelper.CategoryService.Update(createdCategory);
31+
var updatedCategory = DataHelper.CategoryService.Update(createdCategory.CategoryId, createdCategory);
3232

3333
Assert.IsNotNull(updatedCategory);
3434
updatedCategory = DataHelper2.CategoryService.GetById(updatedCategory.CategoryId);

NorthwindCRUD/Controllers/CategoriesController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ public ActionResult<CategoryDetailsDto> Create(CategoryDto model)
200200

201201
[HttpPut("{id}")]
202202
[Authorize]
203-
public ActionResult<CategoryDto> Update(int id, CategoryUpdateDto model)
203+
public ActionResult<CategoryDto> Update(int id, CategoryDto model)
204204
{
205205
try
206206
{
207207
if (ModelState.IsValid)
208208
{
209-
var mappedModel = this.mapper.Map<CategoryUpdateDto, CategoryDb>(model);
209+
var mappedModel = this.mapper.Map<CategoryDto, CategoryDb>(model);
210210
var category = this.categoryService.Update(id, mappedModel);
211211

212212
if (category != null)

NorthwindCRUD/Helpers/MappingProfiles.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class MappingProfiles : Profile
99
public MappingProfiles()
1010
{
1111
CreateMap<CategoryDto, CategoryDb>().ReverseMap();
12-
CreateMap<CategoryUpdateDto, CategoryDb>().ReverseMap();
1312
CreateMap<CategoryDb, CategoryDetailsDto>();
1413

1514
CreateMap<ProductDto, ProductDb>().ReverseMap();

NorthwindCRUD/Models/Contracts/ICategory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public interface ICategory
44
{
5-
int CategoryId { get; set; }
5+
int CategoryId { get; }
66

77
string Description { get; set; }
88

NorthwindCRUD/Models/Dtos/CategoryDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
public class CategoryDto : ICategory
77
{
8-
public int CategoryId { get; set; }
8+
public int CategoryId { get; private set; }
99

1010
[StringLength(500, ErrorMessage = "Description cannot exceed 500 characters.")]
1111
public string Description { get; set; }

NorthwindCRUD/Models/Dtos/CategoryUpdateDto.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)