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 LicenseTypeList = new List(); 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, string sortColumn, string sortOrder, int pageNo, int pageLength) { List LicenseList; int recordCount = 0; try { LicenseList = LicenseModel.GetLicenses(dbContext, accountNumber, licenseeFirstName, licenseeLastName, licenseTypeId, institutionName, stateId, countryId, emailId, subscriptionStartDate, subscriptionEndDate, isActive, sortColumn, sortOrder, pageNo, pageLength, out recordCount); return Request.CreateResponse(HttpStatusCode.OK, new { LicenseList = LicenseList, RecordCount = recordCount }); } 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(); licenseModel.AccountNumber = jsonData["accountNumber"].Value(); licenseModel.LicenseeFirstName = jsonData["licenseeFirstName"].Value(); licenseModel.LicenseeLastName = jsonData["licenseeLastName"].Value(); licenseModel.LicenseTypeId = jsonData["licenseTypeId"].Value(); licenseModel.AccountTypeId = jsonData["accountTypeId"].Value(); licenseModel.InstitutionName = jsonData["institutionName"].Value(); licenseModel.Address1 = jsonData["address1"].Value(); licenseModel.Address2 = jsonData["address2"].Value(); licenseModel.City = jsonData["city"].Value(); licenseModel.Zip = jsonData["zip"].Value(); licenseModel.StateId = jsonData["stateId"].Value(); licenseModel.CountryId = jsonData["countryId"].Value(); licenseModel.Phone = jsonData["phone"].Value(); licenseModel.EmailId = jsonData["email"].Value(); licenseModel.TotalLogins = jsonData["totalLogins"].Value(); licenseModel.EditionLogins = jsonData["editionLogins"].Value(); licenseModel.Price = jsonData["price"].Value(); licenseModel.ProductKey = jsonData["productKey"].Value(); licenseModel.MasterSiteUrl = jsonData["masterSiteUrl"].Value(); licenseModel.SiteUrlFrom = jsonData["siteFromUrl"].Value(); licenseModel.SiteUrlTo = jsonData["siteToUrl"].Value(); licenseModel.NoOfImages = jsonData["noOfImages"].Value(); licenseModel.LoginId = jsonData["loginId"].Value(); licenseModel.Password = jsonData["password"].Value(); licenseModel.SubscriptionStartDate = jsonData["subscriptionStartDate"].Value(); licenseModel.SubscriptionEndDate = jsonData["subscriptionEndDate"].Value(); licenseModel.SecurityQuestionId = jsonData["securityQuestionId"].Value(); licenseModel.Answer = jsonData["answer"].Value(); licenseModel.TestLicenseEditionId = jsonData["testLicenseEditionId"].Value(); licenseModel.CreatorId = jsonData["creatorId"].Value(); 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(); licenseModel.AccountNumber = jsonData["accountNumber"].Value(); licenseModel.LicenseeFirstName = jsonData["licenseeFirstName"].Value(); licenseModel.LicenseeLastName = jsonData["licenseeLastName"].Value(); licenseModel.LicenseTypeId = jsonData["licenseTypeId"].Value(); licenseModel.AccountTypeId = jsonData["accountTypeId"].Value(); licenseModel.InstitutionName = jsonData["institutionName"].Value(); licenseModel.Address1 = jsonData["address1"].Value(); licenseModel.Address2 = jsonData["address2"].Value(); licenseModel.City = jsonData["city"].Value(); licenseModel.Zip = jsonData["zip"].Value(); licenseModel.StateId = jsonData["stateId"].Value(); licenseModel.CountryId = jsonData["countryId"].Value(); licenseModel.Phone = jsonData["phone"].Value(); licenseModel.EmailId = jsonData["email"].Value(); licenseModel.TotalLogins = jsonData["totalLogins"].Value(); licenseModel.EditionLogins = jsonData["editionLogins"].Value(); licenseModel.Price = jsonData["price"].Value(); licenseModel.ProductKey = jsonData["productKey"].Value(); licenseModel.MasterSiteUrl = jsonData["masterSiteUrl"].Value(); licenseModel.SiteUrlFrom = jsonData["siteUrlFrom"].Value(); licenseModel.SiteUrlTo = jsonData["siteUrlTo"].Value(); licenseModel.NoOfImages = jsonData["noOfImages"].Value(); licenseModel.LoginId = jsonData["loginId"].Value(); licenseModel.Password = jsonData["password"].Value(); licenseModel.SubscriptionStartDate = jsonData["subscriptionStartDate"].Value(); licenseModel.SubscriptionEndDate = jsonData["subscriptionEndDate"].Value(); licenseModel.RenewDate = jsonData["renewDate"].Value(); licenseModel.SecurityQuestionId = jsonData["securityQuestionId"].Value(); licenseModel.Answer = jsonData["answer"].Value(); licenseModel.TestLicenseEditionId = jsonData["testLicenseEditionId"].Value(); licenseModel.CreatorId = jsonData["creatorId"].Value(); licenseModel.IsActive = jsonData["isActive"].Value(); licenseModel.IsRenew = jsonData["renew"].Value(); 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); } } [Route("LicenseAccounts")] [HttpGet] public HttpResponseMessage GetLicenseAccounts(int LicenseType) { List> LicenseAccountList = new List>(); try { LicenseAccountList = LicenseModel.GetLicenseAccounts(dbContext, LicenseType); return Request.CreateResponse(HttpStatusCode.OK, LicenseAccountList); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("LicenseSites")] [HttpGet] public HttpResponseMessage GetLicenseSites(string AccountNo, string sortColumn, string sortOrder, int pageNo, int pageLength) { List LicenseSiteList; int recordCount = 0; try { LicenseSiteList = LicenseModel.GetLicenseSites(dbContext, AccountNo, sortColumn, sortOrder, pageNo, pageLength, out recordCount); return Request.CreateResponse(HttpStatusCode.OK, new { LicenseSiteList = LicenseSiteList, RecordCount = recordCount }); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("LicenseModestySettings")] [HttpGet] public HttpResponseMessage GetLicenseModestySettings(int LicenseId, int BuildingLevelId) { List> LicenseModestyList = new List>(); try { LicenseModestyList = LicenseModel.GetLicenseModestySettings(dbContext, LicenseId, BuildingLevelId); return Request.CreateResponse(HttpStatusCode.OK, LicenseModestyList); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("UpdateLicenseBasicSettings")] [HttpPost] public HttpResponseMessage UpdateLicenseBasicSettings(JObject jsonData) { bool Status = false; LicenseModel licenseModel = new LicenseModel(); licenseModel.LicenseId = jsonData["licenseId"].Value(); licenseModel.AccountNumber = jsonData["accountNumber"].Value(); licenseModel.LicenseeFirstName = jsonData["licenseeFirstName"].Value(); licenseModel.LicenseeLastName = jsonData["licenseeLastName"].Value(); licenseModel.InstitutionName = jsonData["institutionName"].Value(); licenseModel.Address1 = jsonData["address1"].Value(); licenseModel.Address2 = jsonData["address2"].Value(); licenseModel.City = jsonData["city"].Value(); licenseModel.Zip = jsonData["zip"].Value(); licenseModel.StateId = jsonData["stateId"].Value(); licenseModel.CountryId = jsonData["countryId"].Value(); licenseModel.Phone = jsonData["phone"].Value(); licenseModel.EmailId = jsonData["email"].Value(); try { Status = LicenseModel.UpdateLicenseBasicSettings(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("UpdateLicenseModestySettings")] [HttpPost] public HttpResponseMessage UpdateLicenseModestySettings(JObject jsonData) { bool Status = false; List> LicenseModestyList = new List>(); Tuple LicenseModesty; for (int i = 0; i < jsonData["obj"].Count(); i++) { LicenseModesty = new Tuple( ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["licenseEditionId"])).Value(), ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["siteId"])).Value(), ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["isModesty"])).Value(), ((Newtonsoft.Json.Linq.JValue)(jsonData["obj"][i]["isSiteUser"])).Value()); LicenseModestyList.Add(LicenseModesty); } try { Status = LicenseModel.UpdateLicenseModestySettings(dbContext, LicenseModestyList); 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("LicenseModulesStatus")] [HttpGet] public HttpResponseMessage GetLicenseModulesStatus(int LicenseId) { List> LicenseModulesStatusList = new List>(); try { LicenseModulesStatusList = LicenseModel.GetLicenseModulesStatus(dbContext, LicenseId); return Request.CreateResponse(HttpStatusCode.OK, LicenseModulesStatusList); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("UpdateLicenseModulesStatus")] [HttpPost] public HttpResponseMessage UpdateLicenseModulesStatus(JObject jsonData) { bool Status = false; Tuple LicenseModuleStatus = new Tuple( jsonData["licenseId"].Value(), jsonData["moduleStatusText"].Value(), jsonData["isAodOn"].Value(), jsonData["CourseListText"].Value()); try { Status = LicenseModel.UpdateLicenseModulesStatus(dbContext, LicenseModuleStatus); 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("GetLicenseAodCourse")] [HttpGet] public HttpResponseMessage GetLicenseAodCourse(int LicenseId) { List courseList; try { courseList = LicenseModel.GetLicenseAodCourse(dbContext, LicenseId); return Request.CreateResponse(HttpStatusCode.OK, courseList); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("CheckAccountNumber")] [HttpGet] public HttpResponseMessage CheckAccountNumber(string AccountNo) { bool Status = false; try { Status = LicenseModel.CheckAccountNumber(dbContext, AccountNo); return Request.CreateResponse(HttpStatusCode.OK, Status.ToString()); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("LicenseSiteAdmin")] [HttpGet] public HttpResponseMessage GetLicenseSiteAdmin(string AccountNo) { List> LicenseSiteAdminList = new List>(); try { LicenseSiteAdminList = LicenseModel.GetLicenseSiteAdmin(dbContext, AccountNo); return Request.CreateResponse(HttpStatusCode.OK, new { LicenseSiteAdminList = LicenseSiteAdminList }); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } } }