Skip to content

Commit b765e01

Browse files
committed
Add CustomerWithOrders and OrderWithDetails dtos
1 parent 190b68a commit b765e01

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

NorthwindCRUD/Controllers/CustomersController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ public ActionResult<CountResultDto> GetCustomersCount()
122122
}
123123

124124
[HttpGet("WithOrders")]
125-
public ActionResult<CustomerDto[]> GetAllCustomersWithOrders()
125+
public ActionResult<CustomerWithOrdersDto[]> GetAllCustomersWithOrders()
126126
{
127127
try
128128
{
129129
var customers = this.customerService.GetAllCustomersWithOrders();
130-
return Ok(this.mapper.Map<CustomerDb[], CustomerDto[]>(customers));
130+
return Ok(this.mapper.Map<CustomerDb[], CustomerWithOrdersDto[]>(customers));
131131
}
132132
catch (Exception error)
133133
{
@@ -173,12 +173,12 @@ public ActionResult<OrderDto[]> GetOrdersByCustomerId(string id)
173173
}
174174

175175
[HttpGet("{id}/Orders/WithDetails")]
176-
public ActionResult<OrderDto[]> GetOrdersAndOrderDetailsByCustomerId(string id)
176+
public ActionResult<OrderWithDetailsDto[]> GetOrdersAndOrderDetailsByCustomerId(string id)
177177
{
178178
try
179179
{
180180
var orders = this.orderService.GetOrdersWithDetailsByCustomerId(id);
181-
return Ok(this.mapper.Map<OrderDb[], OrderDto[]>(orders));
181+
return Ok(this.mapper.Map<OrderDb[], OrderWithDetailsDto[]>(orders));
182182
}
183183
catch (Exception error)
184184
{

NorthwindCRUD/Helpers/MappingProfiles.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ public MappingProfiles()
1616
CreateMap<ShipperDto, ShipperDb>().ReverseMap();
1717
CreateMap<SupplierDto, SupplierDb>().ReverseMap();
1818
CreateMap<TerritoryDto, TerritoryDb>().ReverseMap();
19-
CreateMap<CustomerDto, CustomerDb>().ReverseMap()
19+
CreateMap<CustomerDto, CustomerDb>().ReverseMap();
20+
CreateMap<OrderDto, OrderDb>().ReverseMap();
21+
CreateMap<CustomerWithOrdersDto, CustomerDb>().ReverseMap()
2022
.ForMember(dest => dest.Orders, opt => opt.MapFrom(src => src.Orders.ToArray()));
21-
CreateMap<OrderDto, OrderDb>().ReverseMap()
23+
CreateMap<OrderWithDetailsDto, OrderDb>().ReverseMap()
2224
.ForMember(dest => dest.OrderDetails, opt => opt.MapFrom(src => src.OrderDetails.ToArray()));
2325
CreateMap<OrderDetailDto, OrderDetailDb>().ReverseMap();
2426
CreateMap<AddressDto, AddressDb>().ReverseMap();

NorthwindCRUD/Models/Dtos/CustomerDto.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@ public class CustomerDto : ICustomer
1818
public string ContactTitle { get; set; }
1919

2020
public AddressDto Address { get; set; }
21-
22-
public OrderDto[] Orders { get; set; }
2321
}
2422
}
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+
}

NorthwindCRUD/Models/Dtos/OrderDto.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,5 @@ public class OrderDto : IOrder
3636
public bool Completed { get; set; }
3737

3838
public AddressDto ShipAddress { get; set; }
39-
40-
public OrderDetailDto[] OrderDetails { get; set; }
4139
}
4240
}
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+
}

0 commit comments

Comments
 (0)