using System; using System.Collections.Generic; using System.Linq; using System.Web; using AIAHTML5.ADMIN.API.Entity; namespace AIAHTML5.ADMIN.API.Models { public class LicenseModel { public int LicenseId { get; set; } public string AccountNumber { get; set; } public byte AccountTypeId { get; set; } public string AccountTypeName { get; set; } public string LicenseeFirstName { get; set; } public string LicenseeLastName { get; set; } public string LicenseeName { get; set; } public byte LicenseTypeId { get; set; } public string LicenseTypeName { get; set; } public string InstitutionName { get; set; } public int? StateId { get; set; } public int? CountryId { get; set; } public string LicenseState { get; set; } public string Address { get; set; } public string Address1 { get; set; } public string Address2 { get; set; } public string City { get; set; } public string Zip { get; set; } public string Phone { get; set; } public string LicenseCountry { get; set; } public string EmailId { get; set; } public int? NoOfImages { get; set; } public string ClientAdmin { get; set; } public string ProductKey { get; set; } public int? CardNumber { get; set; } public DateTime SubscriptionStartDate { get; set; } public DateTime SubscriptionEndDate { get; set; } public DateTime EntryDate { get; set; } public DateTime RenewDate { get; set; } public DateTime ModifyDate { get; set; } public bool IsActive { get; set; } public int? TotalLogins { get; set; } public string EditionLogins { get; set; } public decimal Price { get; set; } public string LoginId { get; set; } public string Password { get; set; } public byte? SecurityQuestionId { get; set; } public string Answer { get; set; } public int CreatorId { get; set; } public int TotalRenewals { get; set; } public string MasterSiteUrl { get; set; } public string SiteUrlTo { get; set; } public string SiteUrlFrom { get; set; } public byte? TestLicenseEditionId { get; set; } public bool IsRenew { get; set; } public static List GetLicenses(AIADatabaseV5Entities dbContext, 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(); LicenseModel LicenseObj = new LicenseModel(); int i = 0; try { var result = dbContext.usp_GetLicenses( (subscriptionStartDate > DateTime.MinValue ? subscriptionStartDate.ToShortDateString() : "01/01/01"), (subscriptionEndDate > DateTime.MinValue ? subscriptionEndDate.ToShortDateString() : "01/01/01"), (accountNumber == null ? "" : accountNumber), (licenseeFirstName == null ? "" : licenseeFirstName), (licenseeLastName == null ? "" : licenseeLastName), licenseTypeId, (institutionName == null ? "" : institutionName), (emailId == null ? "" : emailId), stateId, countryId, isActive).ToList(); if (result.Count > 0) { foreach (var item in result) { LicenseObj = new LicenseModel(); LicenseObj.LicenseId = item.LicenseId; LicenseObj.AccountNumber = item.AccountNumber; LicenseObj.AccountTypeName = item.AccountType; LicenseObj.LicenseeName = item.LicenseeName; LicenseObj.LicenseState = item.LicenseState; LicenseObj.LicenseCountry = item.LicenseCountry; LicenseObj.Address = item.ContactAddress; LicenseObj.InstitutionName = item.InstitutionName; LicenseObj.LicenseTypeName = item.LicenseType; LicenseObj.EmailId = item.EmailId; LicenseObj.NoOfImages = item.NoofImages; LicenseObj.ClientAdmin = item.ClientAdmin; LicenseObj.CardNumber = item.CardNumber; LicenseObj.ProductKey = item.ProductKey; LicenseObj.SubscriptionStartDate = DateTime.ParseExact(item.StartDate, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture); LicenseObj.SubscriptionEndDate = DateTime.ParseExact(item.EndDate, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture); LicenseObj.EntryDate = DateTime.ParseExact(item.EntryDate, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture); LicenseObj.RenewDate = DateTime.ParseExact((item.RenewDate == "" ? "01/01/0001" : item.RenewDate), "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture); LicenseObj.ModifyDate = DateTime.ParseExact((item.ModifyDate == "" ? "01/01/0001" : item.ModifyDate), "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture); LicenseObj.IsActive = (item.LicenseStatus == "Active" ? true : false); LicenseList.Add(LicenseObj); i++; if (i >= 100) break; } } } catch (Exception ex) { } return LicenseList; } public static LicenseModel GetLicenseById(AIADatabaseV5Entities dbContext, int LicenseId) { LicenseModel LicenseObj = new LicenseModel(); try { var result = dbContext.usp_GetLicenseById(LicenseId).ToList(); if (result.Count > 0) { LicenseObj.LicenseId = result[0].Id; LicenseObj.LicenseTypeId = result[0].LicenseTypeId; LicenseObj.AccountNumber = result[0].AccountNumber; LicenseObj.AccountTypeId = result[0].AccountTypeId; LicenseObj.LicenseeFirstName = result[0].LicenseeFirstName; LicenseObj.LicenseeLastName = result[0].LicenseeLastName; LicenseObj.EditionLogins = result[0].EditionLogins; LicenseObj.TotalLogins = result[0].TotalLogins; LicenseObj.Address1 = result[0].Address1; LicenseObj.Address2 = result[0].Address2; LicenseObj.City = result[0].City; LicenseObj.CountryId = result[0].CountryId; LicenseObj.StateId = result[0].StateId; LicenseObj.InstitutionName = result[0].InstitutionName; LicenseObj.EmailId = result[0].EmailId; LicenseObj.Zip = result[0].Zip; LicenseObj.Phone = result[0].Phone; LicenseObj.TotalLogins = result[0].TotalLogins; LicenseObj.ProductKey = result[0].ProductId; LicenseObj.Price = result[0].Price.Value; LicenseObj.NoOfImages = result[0].NoOfImages; LicenseObj.MasterSiteUrl = result[0].SiteUrl; LicenseObj.SiteUrlTo = result[0].SitToUrl; LicenseObj.SiteUrlFrom = result[0].SiteMasterUrl; LicenseObj.LoginId = result[0].Login; LicenseObj.Password = result[0].Password; LicenseObj.SecurityQuestionId = (byte?)result[0].SecurityQuestionId; LicenseObj.Answer = result[0].Answer; LicenseObj.IsActive = result[0].IsActive; LicenseObj.TotalRenewals = result[0].TotalRenewals; LicenseObj.SubscriptionStartDate = (result[0].SubscriptionStartDate == null ? DateTime.MinValue : result[0].SubscriptionStartDate.Value); LicenseObj.SubscriptionEndDate = (result[0].SubscriptionEndDate == null ? DateTime.MinValue : result[0].SubscriptionEndDate.Value); LicenseObj.RenewDate = (result[0].RenewalDate == null ? DateTime.MinValue : result[0].RenewalDate.Value); } } catch (Exception ex) { } return LicenseObj; } public static bool InsertLicense(AIADatabaseV5Entities dbContext, LicenseModel licenseModel) { bool status = false; try { switch (licenseModel.LicenseTypeId) { case 1: var result = dbContext.InsertNewLicenseAccount(licenseModel.AccountNumber, licenseModel.LicenseeFirstName, licenseModel.LicenseeLastName, licenseModel.LicenseTypeId, licenseModel.AccountTypeId, licenseModel.InstitutionName, licenseModel.Address1, licenseModel.Address2, licenseModel.City, licenseModel.Zip, licenseModel.StateId, licenseModel.CountryId, licenseModel.Phone, licenseModel.EmailId, licenseModel.TotalLogins, licenseModel.SubscriptionStartDate.ToString("MM/dd/yyyy"), licenseModel.SubscriptionEndDate.ToString("MM/dd/yyyy"), licenseModel.MasterSiteUrl, licenseModel.EditionLogins, licenseModel.Price, licenseModel.ProductKey, licenseModel.SiteUrlTo, licenseModel.SiteUrlFrom, licenseModel.NoOfImages); if (result.Count() > 0) { status = true; } break; case 2: result = dbContext.InsertSingleLicenseAccount(licenseModel.AccountNumber, licenseModel.LicenseeFirstName, licenseModel.LicenseeLastName, licenseModel.AccountTypeId, licenseModel.InstitutionName, licenseModel.Address1, licenseModel.Address2, licenseModel.City, licenseModel.Zip, licenseModel.StateId, licenseModel.CountryId, licenseModel.Phone, licenseModel.EmailId, licenseModel.TotalLogins, licenseModel.SubscriptionStartDate.ToString("MM/dd/yyyy"), licenseModel.SubscriptionEndDate.ToString("MM/dd/yyyy"), licenseModel.EditionLogins, licenseModel.Price, licenseModel.ProductKey, licenseModel.LoginId, licenseModel.Password, licenseModel.SecurityQuestionId, licenseModel.Answer, licenseModel.CreatorId, licenseModel.NoOfImages); if (result.Count() > 0) { status = true; } break; case 3: result = dbContext.InsertNewLicenseAccount(licenseModel.AccountNumber, licenseModel.LicenseeFirstName, licenseModel.LicenseeLastName, licenseModel.LicenseTypeId, licenseModel.AccountTypeId, licenseModel.InstitutionName, licenseModel.Address1, licenseModel.Address2, licenseModel.City, licenseModel.Zip, licenseModel.StateId, licenseModel.CountryId, licenseModel.Phone, licenseModel.EmailId, licenseModel.TotalLogins, licenseModel.SubscriptionStartDate.ToString("MM/dd/yyyy"), licenseModel.SubscriptionEndDate.ToString("MM/dd/yyyy"), licenseModel.MasterSiteUrl, licenseModel.EditionLogins, licenseModel.Price, licenseModel.ProductKey, licenseModel.SiteUrlTo, licenseModel.SiteUrlFrom, licenseModel.NoOfImages); if (result.Count() > 0) { status = true; } break; case 4: var result1 = dbContext.InsertResellerLicenseAccount(licenseModel.LicenseeFirstName, licenseModel.LicenseeLastName, licenseModel.LicenseTypeId, licenseModel.AccountTypeId, licenseModel.InstitutionName, licenseModel.Address1, licenseModel.Address2, licenseModel.City, licenseModel.Zip, licenseModel.StateId, licenseModel.CountryId, licenseModel.Phone, licenseModel.EmailId, licenseModel.TotalLogins, licenseModel.SubscriptionStartDate.ToString("MM/dd/yyyy"), licenseModel.SubscriptionEndDate.ToString("MM/dd/yyyy"), licenseModel.EditionLogins, licenseModel.Price, licenseModel.CreatorId, licenseModel.ProductKey, licenseModel.NoOfImages); if (result1.Count() > 0) { status = true; } break; case 5: result = dbContext.InsertTestLicenseAccount(licenseModel.AccountNumber, licenseModel.LicenseeFirstName, licenseModel.LicenseeLastName, licenseModel.LoginId, licenseModel.Password, licenseModel.EmailId, licenseModel.AccountTypeId, licenseModel.TestLicenseEditionId, licenseModel.Address1, licenseModel.City, licenseModel.Zip, licenseModel.StateId, licenseModel.CountryId, licenseModel.Phone, licenseModel.SubscriptionStartDate.ToString("MM/dd/yyyy"), licenseModel.SubscriptionEndDate.ToString("MM/dd/yyyy"), licenseModel.CreatorId, licenseModel.NoOfImages); if (result.Count() > 0) { status = true; } break; } return status; } catch (Exception ex) { return false; } } public static bool UpdateLicense(AIADatabaseV5Entities dbContext, LicenseModel licenseModel) { bool status = false; try { var result = dbContext.UpdateLicenseAccount(licenseModel.LicenseId, licenseModel.LicenseeFirstName, licenseModel.LicenseeLastName, licenseModel.LicenseTypeId, licenseModel.AccountTypeId, licenseModel.InstitutionName, licenseModel.Address1, licenseModel.Address2, licenseModel.City, licenseModel.Zip, licenseModel.StateId, licenseModel.CountryId, licenseModel.Phone, licenseModel.EmailId, (byte)(licenseModel.IsActive == false ? 0 : 1), licenseModel.TotalLogins, (byte)(licenseModel.IsRenew == false ? 0 : 1), licenseModel.SubscriptionStartDate.ToString("MM/dd/yyyy"), licenseModel.SubscriptionEndDate.ToString("MM/dd/yyyy"), licenseModel.RenewDate.ToString("MM/dd/yyyy"), licenseModel.MasterSiteUrl, licenseModel.EditionLogins, licenseModel.Price, licenseModel.ProductKey, licenseModel.SiteUrlTo, licenseModel.SiteUrlFrom, licenseModel.NoOfImages); if (result.Count() > 0) { status = true; } return status; } catch (Exception ex) { return false; } } public static bool DeleteLicense(AIADatabaseV5Entities dbContext, int LicenseId) { try { var spStatus = dbContext.DeleteLicense(LicenseId); if (spStatus.Count() > 0) { return true; } else { return false; } } catch (Exception ex) { return false; } } } public class LicenseTypeModel { public int Id { get; set; } public string Title { get; set; } public bool IsActive { get; set; } public static List GetLicenseTypes(AIADatabaseV5Entities dbContext) { List LicenseTypeList = new List(); LicenseTypeModel LicenseTypeModelObj = new LicenseTypeModel(); try { var result = dbContext.usp_GetLicenseTypes().ToList(); if (result.Count > 0) { foreach (var item in result) { LicenseTypeModelObj = new LicenseTypeModel(); LicenseTypeModelObj.Id = item.Id; LicenseTypeModelObj.Title = item.Title; LicenseTypeModelObj.IsActive = item.IsActive; LicenseTypeList.Add(LicenseTypeModelObj); } } } catch (Exception ex) { } return LicenseTypeList; } } }