MCPcopy Create free account
hub / github.com/TryCatchLearn/Restore-v2 / OrderExtensions

Class OrderExtensions

API/Extensions/OrderExtensions.cs:8–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6namespace API.Extensions;
7
8public static class OrderExtensions
9{
10 public static IQueryable<OrderDto> ProjectToDto(this IQueryable<Order> query)
11 {
12 return query.Select(order => new OrderDto
13 {
14 Id = order.Id,
15 BuyerEmail = order.BuyerEmail,
16 OrderDate = order.OrderDate,
17 ShippingAddress = order.ShippingAddress,
18 PaymentSummary = order.PaymentSummary,
19 DeliveryFee = order.DeliveryFee,
20 Subtotal = order.Subtotal,
21 Discount = order.Discount,
22 OrderStatus = order.OrderStatus.ToString(),
23 Total = order.GetTotal(),
24 OrderItems = order.OrderItems.Select(item => new OrderItemDto
25 {
26 ProductId = item.ItemOrdered.ProductId,
27 Name = item.ItemOrdered.Name,
28 PictureUrl = item.ItemOrdered.PictureUrl,
29 Price = item.Price,
30 Quantity = item.Quantity
31 }).ToList()
32 }).AsNoTracking();
33 }
34
35 public static OrderDto ToDto(this Order order)
36 {
37 return new OrderDto
38 {
39 Id = order.Id,
40 BuyerEmail = order.BuyerEmail,
41 OrderDate = order.OrderDate,
42 ShippingAddress = order.ShippingAddress,
43 PaymentSummary = order.PaymentSummary,
44 DeliveryFee = order.DeliveryFee,
45 Subtotal = order.Subtotal,
46 Discount = order.Discount,
47 OrderStatus = order.OrderStatus.ToString(),
48 Total = order.GetTotal(),
49 OrderItems = order.OrderItems.Select(item => new OrderItemDto
50 {
51 ProductId = item.ItemOrdered.ProductId,
52 Name = item.ItemOrdered.Name,
53 PictureUrl = item.ItemOrdered.PictureUrl,
54 Price = item.Price,
55 Quantity = item.Quantity
56 }).ToList()
57 };
58 }
59}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected