-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromotionCouponRepository.cs
More file actions
42 lines (34 loc) · 1.39 KB
/
Copy pathPromotionCouponRepository.cs
File metadata and controls
42 lines (34 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Threading;
using System.Threading.Tasks;
using CMS.Commerce;
using CMS.DataEngine;
namespace DancingGoat.Commerce;
/// <summary>
/// Repository for promotion coupon.
/// </summary>
public class PromotionCouponRepository
{
private readonly IInfoProvider<PromotionCouponInfo> promotionCouponInfoProvider;
/// <summary>
/// Initializes a new instance of the <see cref="PromotionCouponRepository"/> class.
/// </summary>
public PromotionCouponRepository(IInfoProvider<PromotionCouponInfo> promotionCouponInfoProvider)
{
this.promotionCouponInfoProvider = promotionCouponInfoProvider;
}
/// <summary>
/// Checks if a promotion coupon exists.
/// </summary>
/// <param name="couponCode">The coupon code to check.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>True if the promotion coupon exists, false otherwise.</returns>
public async Task<bool> PromotionCouponExists(string couponCode, CancellationToken cancellationToken)
{
var promotionCouponId = await promotionCouponInfoProvider.Get()
.WhereEquals(nameof(PromotionCouponInfo.PromotionCouponCode), couponCode)
.Column(nameof(PromotionCouponInfo.PromotionCouponID))
.TopN(1)
.GetScalarResultAsync<int>(cancellationToken: cancellationToken);
return promotionCouponId > 0;
}
}