LicenseController.cs
10.4 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using AIAHTML5.ADMIN.API.Models;
using System.Web.Http.Cors;
using System.Web.Cors;
using AIAHTML5.Server.Constants;
using log4net;
using System.Text;
using AIAHTML5.ADMIN.API.Entity;
namespace AIAHTML5.ADMIN.API.Controllers
{
//[EnableCors(origins: "http://localhost:4200", headers: "*", methods: "*")]
[RoutePrefix("License")]
public class LicenseController : ApiController
{
AIADatabaseV5Entities dbContext = new AIADatabaseV5Entities();
[Route("LicenseTypes")]
[HttpGet]
public HttpResponseMessage GetLicenseTypes()
{
List<LicenseTypeModel> LicenseTypeList = new List<LicenseTypeModel>();
try
{
LicenseTypeList = LicenseTypeModel.GetLicenseTypes(dbContext);
return Request.CreateResponse(HttpStatusCode.OK, LicenseTypeList);
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
[Route("Licenses")]
[HttpGet]
public HttpResponseMessage GetLicenses(string accountNumber, string licenseeFirstName, string licenseeLastName, byte licenseTypeId,
string institutionName, int stateId, int countryId, string emailId, DateTime subscriptionStartDate, DateTime subscriptionEndDate,
bool isActive)
{
List<LicenseModel> LicenseList = new List<LicenseModel>();
try
{
LicenseList = LicenseModel.GetLicenses(dbContext, accountNumber, licenseeFirstName, licenseeLastName, licenseTypeId, institutionName,
stateId, countryId, emailId, subscriptionStartDate, subscriptionEndDate, isActive);
return Request.CreateResponse(HttpStatusCode.OK, LicenseList);
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
[Route("InsertLicense")]
[HttpPost]
public HttpResponseMessage InsertLicense(JObject jsonData)
{
bool Status = false;
LicenseModel licenseModel = new LicenseModel();
licenseModel.LicenseId = jsonData["licenseId"].Value<int>();
licenseModel.AccountNumber = jsonData["accountNumber"].Value<string>();
licenseModel.LicenseeFirstName = jsonData["licenseeFirstName"].Value<string>();
licenseModel.LicenseeLastName = jsonData["licenseeLastName"].Value<string>();
licenseModel.LicenseTypeId = jsonData["licenseTypeId"].Value<byte>();
licenseModel.AccountTypeId = jsonData["accountTypeId"].Value<byte>();
licenseModel.InstitutionName = jsonData["institutionName"].Value<string>();
licenseModel.Address1 = jsonData["address1"].Value<string>();
licenseModel.Address2 = jsonData["address2"].Value<string>();
licenseModel.City = jsonData["city"].Value<string>();
licenseModel.Zip = jsonData["zip"].Value<string>();
licenseModel.StateId = jsonData["stateId"].Value<int?>();
licenseModel.CountryId = jsonData["countryId"].Value<int?>();
licenseModel.Phone = jsonData["phone"].Value<string>();
licenseModel.EmailId = jsonData["email"].Value<string>();
licenseModel.TotalLogins = jsonData["totalLogins"].Value<int?>();
licenseModel.EditionLogins = jsonData["editionLogins"].Value<string>();
licenseModel.Price = jsonData["price"].Value<decimal>();
licenseModel.ProductKey = jsonData["productKey"].Value<string>();
licenseModel.MasterSiteUrl = jsonData["masterSiteUrl"].Value<string>();
licenseModel.SiteUrlFrom = jsonData["siteFromUrl"].Value<string>();
licenseModel.SiteUrlTo = jsonData["siteToUrl"].Value<string>();
licenseModel.NoOfImages = jsonData["noOfImages"].Value<int?>();
licenseModel.LoginId = jsonData["loginId"].Value<string>();
licenseModel.Password = jsonData["password"].Value<string>();
licenseModel.SubscriptionStartDate = jsonData["subscriptionStartDate"].Value<DateTime>();
licenseModel.SubscriptionEndDate = jsonData["subscriptionEndDate"].Value<DateTime>();
licenseModel.SecurityQuestionId = jsonData["securityQuestionId"].Value<byte?>();
licenseModel.Answer = jsonData["answer"].Value<string>();
licenseModel.TestLicenseEditionId = jsonData["testLicenseEditionId"].Value<byte?>();
licenseModel.CreatorId = jsonData["creatorId"].Value<int>();
try
{
Status = LicenseModel.InsertLicense(dbContext, licenseModel);
if (Status)
{
return Request.CreateResponse(HttpStatusCode.OK, Status.ToString());
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, Status.ToString());
}
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
[Route("UpdateLicense")]
[HttpPost]
public HttpResponseMessage UpdateLicense(JObject jsonData)
{
bool Status = false;
LicenseModel licenseModel = new LicenseModel();
licenseModel.LicenseId = jsonData["licenseId"].Value<int>();
licenseModel.AccountNumber = jsonData["accountNumber"].Value<string>();
licenseModel.LicenseeFirstName = jsonData["licenseeFirstName"].Value<string>();
licenseModel.LicenseeLastName = jsonData["licenseeLastName"].Value<string>();
licenseModel.LicenseTypeId = jsonData["licenseTypeId"].Value<byte>();
licenseModel.AccountTypeId = jsonData["accountTypeId"].Value<byte>();
licenseModel.InstitutionName = jsonData["institutionName"].Value<string>();
licenseModel.Address1 = jsonData["address1"].Value<string>();
licenseModel.Address2 = jsonData["address2"].Value<string>();
licenseModel.City = jsonData["city"].Value<string>();
licenseModel.Zip = jsonData["zip"].Value<string>();
licenseModel.StateId = jsonData["stateId"].Value<int?>();
licenseModel.CountryId = jsonData["countryId"].Value<int?>();
licenseModel.Phone = jsonData["phone"].Value<string>();
licenseModel.EmailId = jsonData["email"].Value<string>();
licenseModel.TotalLogins = jsonData["totalLogins"].Value<int?>();
licenseModel.EditionLogins = jsonData["editionLogins"].Value<string>();
licenseModel.Price = jsonData["price"].Value<decimal>();
licenseModel.ProductKey = jsonData["productKey"].Value<string>();
licenseModel.MasterSiteUrl = jsonData["masterSiteUrl"].Value<string>();
licenseModel.SiteUrlFrom = jsonData["siteUrlFrom"].Value<string>();
licenseModel.SiteUrlTo = jsonData["siteUrlTo"].Value<string>();
licenseModel.NoOfImages = jsonData["noOfImages"].Value<int?>();
licenseModel.LoginId = jsonData["loginId"].Value<string>();
licenseModel.Password = jsonData["password"].Value<string>();
licenseModel.SubscriptionStartDate = jsonData["subscriptionStartDate"].Value<DateTime>();
licenseModel.SubscriptionEndDate = jsonData["subscriptionEndDate"].Value<DateTime>();
licenseModel.RenewDate = jsonData["renewDate"].Value<DateTime>();
licenseModel.SecurityQuestionId = jsonData["securityQuestionId"].Value<byte?>();
licenseModel.Answer = jsonData["answer"].Value<string>();
licenseModel.TestLicenseEditionId = jsonData["testLicenseEditionId"].Value<byte?>();
licenseModel.CreatorId = jsonData["creatorId"].Value<int>();
licenseModel.IsActive = jsonData["isActive"].Value<bool>();
licenseModel.IsRenew = jsonData["renew"].Value<bool>();
try
{
Status = LicenseModel.UpdateLicense(dbContext, licenseModel);
if (Status)
{
return Request.CreateResponse(HttpStatusCode.OK, Status.ToString());
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, Status.ToString());
}
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
[Route("GetLicense")]
[HttpGet]
public HttpResponseMessage GetLicense(int LicenseId)
{
LicenseModel LicenseEntity = new LicenseModel();
try
{
LicenseEntity = LicenseModel.GetLicenseById(dbContext, LicenseId);
return Request.CreateResponse(HttpStatusCode.OK, LicenseEntity);
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
[Route("DeleteLicense")]
[HttpGet]
public HttpResponseMessage DeleteLicense(int LicenseId)
{
bool Status = false;
try
{
Status = LicenseModel.DeleteLicense(dbContext, LicenseId);
if (Status)
{
return Request.CreateResponse(HttpStatusCode.OK, Status.ToString());
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, Status.ToString());
}
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
}
}