ShopPlatform.Web
1.0.0.0
농산물, 소프트웨어 라이선스와 개발 용역을 직접 판매하는 CodeMaru 직영 쇼핑몰입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
CartService.cs
이 파일의 문서화 페이지로 가기
1
using
ShopPlatform.Models
;
2
3
namespace
ShopPlatform.Services
;
4
13
public
sealed
class
CartService
14
{
23
private
readonly List<CartItem>
_items
=
new
();
24
33
public
IReadOnlyList<CartItem>
Items
=>
_items
;
42
public
decimal
Total
=>
_items
.Sum(i => i.Subtotal);
51
public
int
Count
=>
_items
.Sum(i => i.Quantity);
52
77
public
void
Add
(
Product
product,
int
quantity = 1)
78
{
79
var existing =
_items
.FirstOrDefault(i => i.ProductId == product.
Id
);
80
if
(existing !=
null
)
81
existing.Quantity += quantity;
82
else
83
_items
.Add(
new
CartItem
84
{
85
ProductId = product.
Id
,
86
ProductName = product.
Name
,
87
UnitPrice = product.
Price
,
88
Quantity = quantity
89
});
90
}
91
108
public
void
Remove
(
int
productId)
109
=>
_items
.RemoveAll(i => i.ProductId == productId);
110
135
public
void
UpdateQuantity
(
int
productId,
int
quantity)
136
{
137
var item =
_items
.FirstOrDefault(i => i.ProductId == productId);
138
if
(item ==
null
)
return
;
139
if
(quantity <= 0)
Remove
(productId);
140
else
item.Quantity = quantity;
141
}
142
151
public
void
Clear
() =>
_items
.Clear();
152
}
ShopPlatform.Models
Definition
CartItem.cs:1
ShopPlatform.Services
Definition
CartService.cs:3
ShopPlatform.Models.CartItem
Definition
CartItem.cs:12
ShopPlatform.Models.Product
Definition
Product.cs:12
ShopPlatform.Models.Product.Name
string Name
Definition
Product.cs:30
ShopPlatform.Models.Product.Id
int Id
Definition
Product.cs:21
ShopPlatform.Models.Product.Price
decimal Price
Definition
Product.cs:48
ShopPlatform.Services.CartService
Definition
CartService.cs:14
ShopPlatform.Services.CartService.Clear
void Clear()
Definition
CartService.cs:151
ShopPlatform.Services.CartService._items
readonly List< CartItem > _items
Definition
CartService.cs:23
ShopPlatform.Services.CartService.Count
int Count
Definition
CartService.cs:51
ShopPlatform.Services.CartService.UpdateQuantity
void UpdateQuantity(int productId, int quantity)
Definition
CartService.cs:135
ShopPlatform.Services.CartService.Add
void Add(Product product, int quantity=1)
Definition
CartService.cs:77
ShopPlatform.Services.CartService.Items
IReadOnlyList< CartItem > Items
Definition
CartService.cs:33
ShopPlatform.Services.CartService.Total
decimal Total
Definition
CartService.cs:42
ShopPlatform.Services.CartService.Remove
void Remove(int productId)
Definition
CartService.cs:108
Services
CartService.cs
다음에 의해 생성됨 :
1.17.0