public List <SubscriptionDetails> GetSubscriptionList(string adminId, string userId = "") { List <SubscriptionDetails> lstSsubscriptionDetail = new List <SubscriptionDetails>(); var usersubList = userSubLogic.GetSubscription(adminId); SubscriptionBO psLogic = new SubscriptionBO(); var subList = psLogic.GetSubscriptionFromFile(); List <int> proList = new List <int>(); if (!String.IsNullOrEmpty(userId)) { bool isAdmin = adminId == userId; TeamBO teamBo = new TeamBO(); proList = teamBo.GetTeamProductByUserId(userId, isAdmin); } foreach (var userSub in usersubList) { var subType = subList.FirstOrDefault(s => s.Id == userSub.SubscriptionId); if (subType != null) { SubscriptionDetails model = new SubscriptionDetails() { Id = subType.Id, UserSubscriptionId = userSub.Id, Name = subType.Name }; LicenseLogic licDataLogic = new LicenseLogic(); var userlicList = licDataLogic.GetLicenseList(userSub.Id); foreach (var pro in subType.Products) { if (!proList.Contains(pro.Id)) { var licList = userlicList.Where(p => p.ProductId == pro.Id).ToList(); var proObj = new ProductDetails() { Id = pro.Id, Name = pro.Name, ProductCode = pro.ProductCode, TotalLicenseCount = licList.Count, UsedLicenseCount = licList.Where(l => l.IsMapped == true).Count() }; proObj.IsDisabled = proObj.TotalLicenseCount == proObj.UsedLicenseCount; model.Products.Add(proObj); } } lstSsubscriptionDetail.Add(model); } } if (!String.IsNullOrEmpty(userId)) { UserLicenseLogic logic = new UserLicenseLogic(); var data = logic.GetUserLicense(userId); if (data != null && data.Count > 0) { data = data.Where(p => p.IsTeamLicense == false).ToList(); } foreach (var obj in data) { var subObj = lstSsubscriptionDetail.FirstOrDefault(f => f.UserSubscriptionId == obj.License.UserSubscriptionId); if (subObj != null) { var pro = subObj.Products.FirstOrDefault(f => f.Id == obj.License.ProductId); if (pro != null) { pro.IsSelected = true; pro.InitialState = true; } } } } return(lstSsubscriptionDetail); }
public UserLicenseDetails GetUserLicenseSubscriptionDetails(FetchUserSubscription model) { UserLicenseDetails licDetails = new UserLicenseDetails(); var licenseMapModelList = new List <SubscriptionDetails>(); UserLicenseLogic logic = new UserLicenseLogic(); SubscriptionBO proSubLogic = new SubscriptionBO(); userLogic.UserManager = UserManager; userLogic.RoleManager = RoleManager; licDetails.User = userLogic.GetUserById(model.UserId); List <UserLicense> data = null; if (model.TeamId == 0) { data = logic.GetUserLicense(model.UserId); } else { data = logic.GetUserLicense(model.UserId, model.TeamId); } var dataList = proSubLogic.GetSubscriptionFromFile(); if (data.Count > 0) { var subsIdList = data.Select(l => l.License.Subscription.SubscriptionId); var subscriptionList = dataList.Where(s => subsIdList.Contains(s.Id)).ToList(); DateTime licExpireData = DateTime.MinValue; foreach (var subs in subscriptionList) { var userLicLicst = data.Where(ul => ul.License.Subscription.SubscriptionId == subs.Id).ToList(); var proList = userLicLicst.Select(u => u.License.ProductId).ToList(); SubscriptionDetails mapModel = new SubscriptionDetails() { Name = subs.Name, UserSubscriptionId = data.FirstOrDefault(us => us.License.Subscription.SubscriptionId == subs.Id).License.UserSubscriptionId }; foreach (var pro in subs.Products.Where(p => proList.Contains(p.Id))) { var objLic = userLicLicst.FirstOrDefault(f => f.License.ProductId == pro.Id); if (objLic != null) { string licenseKeydata = String.Empty; licenseKeydata = objLic.License.LicenseKey; var splitData = licenseKeydata.Split(new char[] { '-' }); var datakey = splitData[0]; var decryptObj = LicenseKey.LicenseKeyGen.CryptoEngine.Decrypt(datakey, true); var licdataList = decryptObj.Split(new char[] { '^' }); licExpireData = Convert.ToDateTime(licdataList[1]); } ProductDetails prod = new ProductDetails() { Id = pro.Id, Name = pro.Name, ExpireDate = licExpireData }; if (model.IsFeatureRequired) { foreach (var fet in pro.AssociatedFeatures) { var feature = new Feature() { Id = fet.Id, Name = fet.Name, Description = fet.Description, Version = fet.Version }; prod.Features.Add(feature); } } mapModel.Products.Add(prod); } licenseMapModelList.Add(mapModel); } } licDetails.SubscriptionDetails = licenseMapModelList; return(licDetails); }