-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditPlan.ascx.cs
229 lines (197 loc) · 8 KB
/
EditPlan.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using DotNetNuke.Common.Utilities;
using DotNetNuke.Security.Roles;
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 EditPlan : SubscriptionBase<SubscriptionSettings>
{
#region Private Properties
private int PlanID
{
get
{
int planID;
if (!Int32.TryParse(Page.Request["pid"], out planID))
planID = Null.NullInteger;
return planID;
}
}
#endregion
#region Private Methods
private void AdjustControlVisibility()
{
divBillingPeriod.Visible = !(lstBillingFrequency.SelectedValue == ((int)FrequencyType.OneTimeFee).ToString());
divAutoRecurring.Visible = !(lstBillingFrequency.SelectedValue == ((int)FrequencyType.OneTimeFee).ToString());
}
private void BindFrequency()
{
foreach(int value in Enum.GetValues(typeof(FrequencyType)))
{
var li = new ListItem()
{
Value = value.ToString(),
Text = LocalizeString(Enum.GetName(typeof(FrequencyType), value))
};
lstBillingFrequency.Items.Add(li);
}
if (lstBillingFrequency.Items.Count > 0)
lstBillingFrequency.Items[0].Selected = true;
}
private void BindPeriod()
{
for(int i = 1; i <= 100; i++)
lstBillingPeriod.Items.Add(i.ToString());
lstBillingPeriod.Items.Insert(0, new ListItem(LocalizeString("SelectPeriod"), "-1"));
}
private void BindPlan()
{
if (PlanID != Null.NullInteger)
{
var objPlanController = new PlanController();
var objPlan = objPlanController.GetPlan(PlanID, ModuleId);
if (objPlan == null)
{
Response.Redirect(EditUrl("EditPlans"));
}
else
{
txtName.Text = objPlan.Name;
if (lstRoles.Items.FindByValue(objPlan.RoleID.ToString()) != null)
lstRoles.SelectedValue = objPlan.RoleID.ToString();
txtServiceFee.Text = objPlan.ServiceFee.ToString();
if (lstBillingFrequency.Items.FindByValue(objPlan.BillingFrequency.ToString()) != null)
lstBillingFrequency.SelectedValue = objPlan.BillingFrequency.ToString();
if (lstBillingPeriod.Items.FindByValue(objPlan.BillingPeriod.ToString()) != null)
lstBillingPeriod.SelectedValue = objPlan.BillingPeriod.ToString();
chkAutoRecurring.Checked = objPlan.AutoRecurring;
chkIsActive.Checked = objPlan.IsActive;
AdjustControlVisibility();
// Allow users to delete plan
cmdDelete.Visible = true;
}
}
else
{
AdjustControlVisibility();
}
}
private void BindRoles()
{
var objRoleController = new RoleController();
lstRoles.DataSource = objRoleController.GetRoles(PortalId);
lstRoles.DataBind();
lstRoles.Items.Insert(0, new ListItem(LocalizeString("SelectRole"), Null.NullInteger.ToString()));
}
#endregion
#region Event Handlers
protected void Page_Load(object sender, EventArgs e)
{
try
{
if( !IsPostBack )
{
BindFrequency();
BindPeriod();
BindRoles();
BindPlan();
lnkCancel.NavigateUrl = EditUrl("EditPlans");
txtName.Focus();
}
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void lstBillingFrequency_OnSelectedIndexChanged(object sender, EventArgs e)
{
try
{
AdjustControlVisibility();
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void OnSaveClick(object sender, EventArgs e)
{
try
{
if( Page.IsValid )
{
if (PlanID != Null.NullInteger)
{
// Update Plan
var objPlanController = new PlanController();
var objPlan = objPlanController.GetPlan(PlanID, ModuleId);
if( objPlan != null )
{
objPlan.ModuleID = ModuleId;
objPlan.Name = txtName.Text;
objPlan.RoleID = Convert.ToInt32(lstRoles.SelectedValue);
decimal serviceFee;
if (!Decimal.TryParse(txtServiceFee.Text, out serviceFee))
serviceFee = 0;
objPlan.ServiceFee = serviceFee;
objPlan.BillingFrequency = (FrequencyType) Enum.Parse(typeof(FrequencyType), lstBillingFrequency.SelectedValue);
objPlan.BillingPeriod = Convert.ToInt32(lstBillingPeriod.SelectedValue);
objPlan.AutoRecurring = chkAutoRecurring.Checked;
objPlan.IsActive = chkIsActive.Checked;
objPlanController.UpdatePlan(objPlan);
}
}
else
{
// Add Plan
var objPlan = new Plan();
objPlan.ModuleID = ModuleId;
objPlan.Name = txtName.Text;
objPlan.RoleID = Convert.ToInt32(lstRoles.SelectedValue);
decimal serviceFee;
if (!Decimal.TryParse(txtServiceFee.Text, out serviceFee))
serviceFee = 0;
objPlan.ServiceFee = serviceFee;
objPlan.BillingFrequency = (FrequencyType)Enum.Parse(typeof(FrequencyType), lstBillingFrequency.SelectedValue);
objPlan.BillingPeriod = Convert.ToInt32(lstBillingPeriod.SelectedValue);
objPlan.AutoRecurring = chkAutoRecurring.Checked;
objPlan.IsActive = chkIsActive.Checked;
var objPlanController = new PlanController();
objPlanController.AddPlan(objPlan);
}
Response.Redirect(EditUrl("EditPlans"));
}
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void OnDeleteClick(object sender, EventArgs e)
{
try
{
if (PlanID != Null.NullInteger)
{
// Update Plan
var objPlanController = new PlanController();
var objPlan = objPlanController.GetPlan(PlanID, ModuleId);
if (objPlan != null)
objPlanController.DeletePlan(objPlan);
}
Response.Redirect(EditUrl("EditPlans"));
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
#endregion
}
}