-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditCoupon.ascx.cs
213 lines (177 loc) · 7.24 KB
/
EditCoupon.ascx.cs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Exceptions;
using System;
using System.Web.UI.WebControls;
using Ventrian.Modules.Subscriptions.Base;
using Ventrian.Modules.Subscriptions.Components.Controllers;
using Ventrian.Modules.Subscriptions.Components.Entities;
using Ventrian.Modules.Subscriptions.Components.Types;
namespace Ventrian.Modules.Subscriptions
{
public partial class EditCoupon : SubscriptionBase<SubscriptionSettings>
{
#region Private Properties
private int CouponID
{
get
{
int couponID;
if (!Int32.TryParse(Page.Request["cid"], out couponID))
couponID = Null.NullInteger;
return couponID;
}
}
#endregion
#region Private Methods
private void BindDiscountType()
{
foreach (int value in Enum.GetValues(typeof(DiscountType)))
{
var li = new ListItem()
{
Value = value.ToString(),
Text = LocalizeString(Enum.GetName(typeof(DiscountType), value))
};
lstDiscountType.Items.Add(li);
}
if (lstDiscountType.Items.Count > 0)
lstDiscountType.Items[0].Selected = true;
}
private void BindCoupon()
{
if (CouponID != Null.NullInteger)
{
var objCouponController = new CouponController();
var objCoupon = objCouponController.GetCoupon(CouponID, ModuleId);
if (objCoupon == null)
{
Response.Redirect(EditUrl("EditCoupons"));
}
else
{
txtCode.Text = objCoupon.Code;
if (lstDiscountType.Items.FindByValue(objCoupon.DiscountType.ToString()) != null)
lstDiscountType.SelectedValue = objCoupon.DiscountType.ToString();
txtAmount.Text = objCoupon.Amount.ToString();
txtQuantity.Text = objCoupon.Quantity.ToString();
txtStartDate.SelectedDate = objCoupon.StartDate;
txtEndDate.SelectedDate = objCoupon.EndDate;
chkIsActive.Checked = objCoupon.IsActive;
// Allow users to delete coupon
cmdDelete.Visible = true;
}
}
}
#endregion
#region Event Handlers
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
BindDiscountType();
BindCoupon();
lnkCancel.NavigateUrl = EditUrl("EditCoupons");
txtCode.Focus();
}
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void OnSaveClick(object sender, EventArgs e)
{
try
{
if (Page.IsValid)
{
if (CouponID != Null.NullInteger)
{
// Update Coupon
var objCouponController = new CouponController();
var objCoupon = objCouponController.GetCoupon(CouponID, ModuleId);
if (objCoupon != null)
{
objCoupon.ModuleID = ModuleId;
objCoupon.Code = txtCode.Text;
objCoupon.DiscountType = (DiscountType)Enum.Parse(typeof(DiscountType), lstDiscountType.SelectedValue);
Int32 amount;
if (!Int32.TryParse(txtAmount.Text, out amount))
amount = 0;
if (amount < 0)
amount = 0;
objCoupon.Amount = amount;
Int32 quantity;
if (Int32.TryParse(txtQuantity.Text, out quantity))
{
if (quantity > 0)
objCoupon.Quantity = quantity;
}
objCoupon.Quantity = null;
if( txtStartDate.SelectedDate.HasValue )
objCoupon.StartDate = txtStartDate.SelectedDate.Value;
if (txtEndDate.SelectedDate.HasValue)
objCoupon.EndDate = txtEndDate.SelectedDate.Value;
objCoupon.IsActive = chkIsActive.Checked;
objCouponController.UpdateCoupon(objCoupon);
}
}
else
{
// Add Coupon
var objCoupon = new Coupon();
objCoupon.ModuleID = ModuleId;
objCoupon.Code = txtCode.Text;
objCoupon.DiscountType = (DiscountType)Enum.Parse(typeof(DiscountType), lstDiscountType.SelectedValue);
Int32 amount;
if (!Int32.TryParse(txtAmount.Text, out amount))
amount = 0;
if (amount < 0)
amount = 0;
objCoupon.Amount = amount;
Int32 quantity;
if (Int32.TryParse(txtQuantity.Text, out quantity))
{
if (quantity > 0)
objCoupon.Quantity = quantity;
}
if (txtStartDate.SelectedDate.HasValue)
objCoupon.StartDate = txtStartDate.SelectedDate.Value;
if (txtEndDate.SelectedDate.HasValue)
objCoupon.EndDate = txtEndDate.SelectedDate.Value;
objCoupon.IsActive = chkIsActive.Checked;
var objCouponController = new CouponController();
objCouponController.AddCoupon(objCoupon);
}
Response.Redirect(EditUrl("EditCoupons"));
}
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void OnDeleteClick(object sender, EventArgs e)
{
try
{
if (CouponID != Null.NullInteger)
{
// Update Coupon
var objCouponController = new CouponController();
var objCoupon = objCouponController.GetCoupon(CouponID, ModuleId);
if (objCoupon != null)
objCouponController.DeleteCoupon(objCoupon);
}
Response.Redirect(EditUrl("EditCoupons"));
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
#endregion
}
}