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

Class BasketExtensions

API/Extensions/BasketExtensions.cs:8–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6namespace API.Extensions;
7
8public static class BasketExtensions
9{
10 public static BasketDto ToDto(this Basket basket)
11 {
12 return new BasketDto
13 {
14 BasketId = basket.BasketId,
15 ClientSecret = basket.ClientSecret,
16 Coupon = basket.Coupon,
17 Items = basket.Items.Select(x => new BasketItemDto
18 {
19 ProductId = x.ProductId,
20 Name = x.Product.Name,
21 Price = x.Product.Price,
22 Brand = x.Product.Brand,
23 Type = x.Product.Type,
24 PictureUrl = x.Product.PictureUrl,
25 Quantity = x.Quantity
26 }).ToList()
27 };
28 }
29
30 public static async Task<Basket> GetBasketWithItems(this IQueryable<Basket> query,
31 string? basketId)
32 {
33 return await query
34 .Include(x => x.Items)
35 .ThenInclude(x => x.Product)
36 .FirstOrDefaultAsync(x => x.BasketId == basketId)
37 ?? throw new Exception("Cannot get basket");
38 }
39}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected