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) { List LicenseList = new List(); 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(); 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); } } } }