/// <summary> /// Des the activate subscription. /// </summary> /// <param name="subscriptionId">The subscription identifier.</param> /// <param name="planId">The plan identifier.</param> /// <param name="operation">The operation.</param> /// <returns> The <see cref="IActionResult" />.</returns> public IActionResult DeActivateSubscription(Guid subscriptionId, string planId, string operation) { this.logger.LogInformation("Home Controller / ActivateSubscription subscriptionId:{0} :: planId:{1} :: operation:{2}", subscriptionId, planId, operation); try { SubscriptionResultExtension subscriptionDetail = new SubscriptionResultExtension(); if (this.User.Identity.IsAuthenticated) { var userId = this.userService.AddUser(this.GetCurrentUserDetail()); var currentUserId = this.userService.GetUserIdFromEmailAddress(this.CurrentUserEmailAddress); this.subscriptionService = new SubscriptionService(this.subscriptionRepository, this.planRepository, userId); this.logger.LogInformation("GetSubscriptionByIdAsync SubscriptionID :{0} :: planID:{1}:: operation:{2}", JsonSerializer.Serialize(subscriptionId), JsonSerializer.Serialize(operation)); this.TempData["ShowWelcomeScreen"] = false; var oldValue = this.subscriptionService.GetSubscriptionsBySubscriptionId(subscriptionId); var plandetails = this.planRepository.GetById(oldValue.PlanId); subscriptionDetail = this.subscriptionService.GetSubscriptionsBySubscriptionId(subscriptionId); subscriptionDetail.ShowWelcomeScreen = false; subscriptionDetail.CustomerEmailAddress = this.CurrentUserEmailAddress; subscriptionDetail.CustomerName = this.CurrentUserName; subscriptionDetail.SubscriptionParameters = this.subscriptionService.GetSubscriptionsParametersById(subscriptionId, plandetails.PlanGuid); } return(this.View("ActivateSubscription", subscriptionDetail)); } catch (Exception ex) { this.logger.LogError(ex, "Error while deactivating subscription"); return(this.View("Error", ex)); } }
/// <summary> /// Subscriptions the details. /// </summary> /// <param name="subscriptionId">The subscription identifier.</param> /// <param name="planId">The plan identifier.</param> /// <returns> The <see cref="IActionResult" />.</returns> public IActionResult SubscriptionDetails(Guid subscriptionId, string planId) { this.logger.LogInformation("Home Controller / ActivateSubscription subscriptionId:{0} :: planId:{1}", subscriptionId, planId); SubscriptionResultExtension subscriptionDetail = new SubscriptionResultExtension(); if (this.User.Identity.IsAuthenticated) { var userId = this.userService.AddUser(this.GetCurrentUserDetail()); var currentUserId = this.userService.GetUserIdFromEmailAddress(this.CurrentUserEmailAddress); this.subscriptionService = new SubscriptionService(this.subscriptionRepo, this.planRepository, userId); this.logger.LogInformation("User authenticate successfully & GetSubscriptionByIdAsync SubscriptionID :{0}", JsonSerializer.Serialize(subscriptionId)); this.TempData["ShowWelcomeScreen"] = false; var oldValue = this.subscriptionService.GetSubscriptionsBySubscriptionId(subscriptionId); var serializedParent = JsonSerializer.Serialize(oldValue); subscriptionDetail = JsonSerializer.Deserialize <SubscriptionResultExtension>(serializedParent); this.logger.LogInformation("serializedParent :{0}", serializedParent); subscriptionDetail.ShowWelcomeScreen = false; subscriptionDetail.SubscriptionStatus = oldValue.SubscriptionStatus; subscriptionDetail.CustomerEmailAddress = oldValue.CustomerEmailAddress; subscriptionDetail.CustomerName = oldValue.CustomerName; var plandetails = this.planRepository.GetById(oldValue.PlanId); subscriptionDetail = this.subscriptionService.GetSubscriptionsBySubscriptionId(subscriptionId); subscriptionDetail.SubscriptionParameters = this.subscriptionService.GetSubscriptionsParametersById(subscriptionId, plandetails.PlanGuid); subscriptionDetail.SubscriptionParameters = this.subscriptionService.GetSubscriptionsParametersById(subscriptionId, plandetails.PlanGuid); } return(this.View(subscriptionDetail)); }
/// <summary> /// Gets the subscriptions for subscription identifier. /// </summary> /// <param name="subscriptionId">The subscription identifier.</param> /// <param name="includeUnsubscribed">if set to <c>true</c> [include unsubscribed].</param> /// <returns> Subscription ResultExtension.</returns> public SubscriptionResultExtension GetSubscriptionsBySubscriptionId(Guid subscriptionId, bool includeUnsubscribed = true) { var subscriptionDetail = this.subscriptionRepository.GetById(subscriptionId, includeUnsubscribed); if (subscriptionDetail != null) { SubscriptionResultExtension subscritpionDetail = this.PrepareSubscriptionResponse(subscriptionDetail); if (subscritpionDetail != null) { return(subscritpionDetail); } } return(new SubscriptionResultExtension()); }
/// <summary> /// Gets the subscriptions for partner. /// </summary> /// <param name="partnerEmailAddress">The partner email address.</param> /// <param name="subscriptionId">The subscription identifier.</param> /// <param name="includeUnsubscribed">if set to <c>true</c> [include unsubscribed].</param> /// <returns></returns> public List <SubscriptionResultExtension> GetPartnerSubscription(string partnerEmailAddress, Guid subscriptionId, bool includeUnsubscribed = false) { List <SubscriptionResultExtension> allSubscriptions = new List <SubscriptionResultExtension>(); var allSubscriptionsForEmail = SubscriptionRepository.GetSubscriptionsByEmailAddress(partnerEmailAddress, subscriptionId, includeUnsubscribed).OrderByDescending(s => s.CreateDate).ToList(); foreach (var subscription in allSubscriptionsForEmail) { SubscriptionResultExtension subscritpionDetail = PrepareSubscriptionResponse(subscription); if (subscritpionDetail != null && subscritpionDetail.SubscribeId > 0) { allSubscriptions.Add(subscritpionDetail); } } return(allSubscriptions); }
/// <summary> /// Subscriptionses this instance. /// </summary> /// <returns></returns> public IActionResult Subscriptions() { this.logger.LogInformation("Home Controller / Subscriptions "); try { if (Convert.ToBoolean(applicationConfigRepository.GetValuefromApplicationConfig(MainMenuStatusEnum.IsLicenseManagementEnabled.ToString())) == true) { this.TempData["ShowLicensesMenu"] = true; } SubscriptionViewModel subscriptionDetail = new SubscriptionViewModel(); if (User.Identity.IsAuthenticated) { this.TempData["ShowWelcomeScreen"] = "True"; List <SubscriptionResultExtension> allSubscriptions = new List <SubscriptionResultExtension>(); var allSubscriptionDetails = subscriptionRepo.Get().ToList(); var allPlans = planRepository.Get().ToList(); foreach (var subscription in allSubscriptionDetails) { SubscriptionResultExtension subscritpionDetail = PrepareSubscriptionResponse(subscription, allPlans); Plans PlanDetail = this.planRepository.GetPlanDetailByPlanId(subscritpionDetail.PlanId); subscritpionDetail.IsPerUserPlan = PlanDetail.IsPerUser.HasValue ? PlanDetail.IsPerUser.Value : false; subscriptionDetail.IsAutomaticProvisioningSupported = Convert.ToBoolean(applicationConfigRepository.GetValuefromApplicationConfig("IsAutomaticProvisioningSupported")); if (subscritpionDetail != null && subscritpionDetail.SubscribeId > 0) { allSubscriptions.Add(subscritpionDetail); } } subscriptionDetail.Subscriptions = allSubscriptions; if (this.TempData["ErrorMsg"] != null) { subscriptionDetail.IsSuccess = false; subscriptionDetail.ErrorMessage = Convert.ToString(this.TempData["ErrorMsg"]); } } else { return(RedirectToAction(nameof(Index))); } return(this.View(subscriptionDetail)); } catch (Exception ex) { logger.LogError("Message:{0} :: {1} ", ex.Message, ex.InnerException); return(View("Error")); } }
/// <summary> /// Prepares the subscription response. /// </summary> /// <param name="subscription">The subscription.</param> /// <returns></returns> private SubscriptionResultExtension PrepareSubscriptionResponse(Subscriptions subscription) { SubscriptionResultExtension subscritpionDetail = new SubscriptionResultExtension { Id = subscription.AmpsubscriptionId, SubscribeId = subscription.Id, PlanId = string.IsNullOrEmpty(subscription.AmpplanId) ? string.Empty : subscription.AmpplanId, Name = subscription.Name, SaasSubscriptionStatus = GetSubscriptionStatus(subscription.SubscriptionStatus), IsActiveSubscription = subscription.IsActive ?? false, CustomerEmailAddress = subscription.User?.EmailAddress, CustomerName = subscription.User?.FullName }; return(subscritpionDetail); }
/// <summary> /// Subscriptionses this instance. /// </summary> /// <returns> The <see cref="IActionResult" />.</returns> public IActionResult Subscriptions() { this.logger.LogInformation("Home Controller / Subscriptions "); try { SubscriptionViewModel subscriptionDetail = new SubscriptionViewModel(); if (this.User.Identity.IsAuthenticated) { this.TempData["ShowWelcomeScreen"] = "True"; List <SubscriptionResultExtension> allSubscriptions = new List <SubscriptionResultExtension>(); var allSubscriptionDetails = this.subscriptionRepo.Get().ToList(); var allPlans = this.planRepository.Get().ToList(); foreach (var subscription in allSubscriptionDetails) { SubscriptionResultExtension subscriptionDetailExtension = this.subscriptionService.PrepareSubscriptionResponse(subscription); Plans planDetail = this.planRepository.GetById(subscriptionDetailExtension.PlanId); subscriptionDetailExtension.IsPerUserPlan = planDetail.IsPerUser.HasValue ? planDetail.IsPerUser.Value : false; subscriptionDetail.IsAutomaticProvisioningSupported = Convert.ToBoolean(this.applicationConfigRepository.GetValueByName("IsAutomaticProvisioningSupported")); if (subscriptionDetailExtension != null && subscriptionDetailExtension.SubscribeId > 0) { allSubscriptions.Add(subscriptionDetailExtension); } } subscriptionDetail.Subscriptions = allSubscriptions; if (this.TempData["ErrorMsg"] != null) { subscriptionDetail.IsSuccess = false; subscriptionDetail.ErrorMessage = Convert.ToString(this.TempData["ErrorMsg"]); } } else { return(this.RedirectToAction(nameof(this.Index))); } return(this.View(subscriptionDetail)); } catch (Exception ex) { this.logger.LogError("Message:{0} :: {1} ", ex.Message, ex.InnerException); return(this.View("Error", ex)); } }
/// <summary> /// Prepares the subscription response. /// </summary> /// <param name="subscription">The subscription.</param> /// <param name="allPlanDetails">All plan details.</param> /// <returns></returns> private SubscriptionResultExtension PrepareSubscriptionResponse(Subscriptions subscription, List <Plans> allPlanDetails) { SubscriptionResultExtension subscritpionDetail = new SubscriptionResultExtension(); subscritpionDetail.Id = subscription.AmpsubscriptionId; subscritpionDetail.SubscribeId = subscription.Id; subscritpionDetail.PlanId = string.IsNullOrEmpty(subscription.AmpplanId) ? string.Empty : subscription.AmpplanId; subscritpionDetail.Quantity = subscription.Ampquantity; subscritpionDetail.Name = subscription.Name; subscritpionDetail.SaasSubscriptionStatus = GetSubscriptionStatus(subscription.SubscriptionStatus); subscritpionDetail.IsActiveSubscription = subscription.IsActive ?? false; subscritpionDetail.CustomerName = subscription.User?.FullName; subscritpionDetail.CustomerEmailAddress = subscription.User?.EmailAddress; var existingPlanDetail = allPlanDetails.Where(s => s.PlanId == subscritpionDetail.PlanId).FirstOrDefault(); subscritpionDetail.IsMeteringSupported = existingPlanDetail != null ? (existingPlanDetail.IsmeteringSupported ?? false) : false; return(subscritpionDetail); }
public IActionResult DeActivateSubscription(Guid subscriptionId, string planId, string operation) { this.logger.LogInformation("Home Controller / ActivateSubscription subscriptionId:{0} :: planId:{1} :: operation:{2}", subscriptionId, planId, operation); try { if (Convert.ToBoolean(applicationConfigRepository.GetValuefromApplicationConfig(MainMenuStatusEnum.IsLicenseManagementEnabled.ToString())) == true) { this.TempData["ShowLicensesMenu"] = true; } SubscriptionResultExtension subscriptionDetail = new SubscriptionResultExtension(); if (User.Identity.IsAuthenticated) { var userId = this.userService.AddPartnerDetail(GetCurrentUserDetail()); var currentUserId = this.userService.GetUserIdFromEmailAddress(this.CurrentUserEmailAddress); this.subscriptionService = new SubscriptionService(this.subscriptionRepository, this.planRepository, userId); this.logger.LogInformation("GetSubscriptionByIdAsync SubscriptionID :{0} :: planID:{1}:: operation:{2}", JsonConvert.SerializeObject(subscriptionId), JsonConvert.SerializeObject(operation)); this.TempData["ShowWelcomeScreen"] = false; var subscriptionData = this.fulfillApiClient.GetSubscriptionByIdAsync(subscriptionId).ConfigureAwait(false).GetAwaiter().GetResult(); var subscribeId = this.subscriptionService.AddUpdatePartnerSubscriptions(subscriptionData); var oldValue = this.subscriptionService.GetPartnerSubscriptions(CurrentUserEmailAddress, subscriptionId).FirstOrDefault(); var serializedParent = JsonConvert.SerializeObject(subscriptionData); subscriptionDetail = JsonConvert.DeserializeObject <SubscriptionResultExtension>(serializedParent); //subscriptionDetail = (SubscriptionResult)subscriptionData; subscriptionDetail.ShowWelcomeScreen = false; subscriptionDetail.SaasSubscriptionStatus = SubscriptionStatusEnum.Subscribed; subscriptionDetail.CustomerEmailAddress = this.CurrentUserEmailAddress; subscriptionDetail.CustomerName = this.CurrentUserName; } return(this.View("ActivateSubscription", subscriptionDetail)); } catch (Exception ex) { this.logger.LogError(ex, "Error while deactivating subscription"); return(View("Error")); } }
/// <summary> /// Prepares the subscription response. /// </summary> /// <param name="subscription">The subscription.</param> /// <returns> Subscription.</returns> public SubscriptionResultExtension PrepareSubscriptionResponse(Subscriptions subscription) { var existingPlanDetail = this.planRepository.GetById(subscription.AmpplanId); SubscriptionResultExtension subscritpionDetail = new SubscriptionResultExtension { Id = subscription.AmpsubscriptionId, SubscribeId = subscription.Id, PlanId = string.IsNullOrEmpty(subscription.AmpplanId) ? string.Empty : subscription.AmpplanId, Quantity = subscription.Ampquantity, Name = subscription.Name, SubscriptionStatus = this.GetSubscriptionStatus(subscription.SubscriptionStatus), IsActiveSubscription = subscription.IsActive ?? false, CustomerEmailAddress = subscription.User?.EmailAddress, CustomerName = subscription.User?.FullName, IsMeteringSupported = existingPlanDetail != null ? (existingPlanDetail.IsmeteringSupported ?? false) : false, }; subscritpionDetail.Purchaser = new PurchaserResult(); subscritpionDetail.Purchaser.EmailId = subscription.PurchaserEmail; subscritpionDetail.Purchaser.TenantId = subscription.PurchaserTenantId ?? default; return(subscritpionDetail); }
/// <summary> /// Get All Subscription List for Current Logged in User. /// </summary> /// <param name="token">The MS Token<see cref="string" />..</param> /// <returns> /// The <see cref="IActionResult" />. /// </returns> public IActionResult Index(string token = null) { try { this.logger.LogInformation($"Landing page with token {token}"); SubscriptionResult subscriptionDetail = new SaasKitModels.SubscriptionResult(); SubscriptionResultExtension subscriptionExtension = new SubscriptionResultExtension(); if (this.User.Identity.IsAuthenticated) { var userId = this.userService.AddUser(this.GetCurrentUserDetail()); var currentUserId = this.userService.GetUserIdFromEmailAddress(this.CurrentUserEmailAddress); this.subscriptionService = new SubscriptionService(this.subscriptionRepository, this.planRepository, userId); this.logger.LogInformation("User authenticated successfully"); if (!string.IsNullOrEmpty(token)) { this.TempData["ShowWelcomeScreen"] = null; token = token.Replace(' ', '+'); var newSubscription = this.apiClient.ResolveAsync(token).ConfigureAwait(false).GetAwaiter().GetResult(); if (newSubscription != null && newSubscription.SubscriptionId != default) { var subscriptionPlanDetail = this.apiClient.GetAllPlansForSubscriptionAsync(newSubscription.SubscriptionId).ConfigureAwait(false).GetAwaiter().GetResult(); Offers offers = new Offers() { OfferId = newSubscription.OfferId, OfferName = newSubscription.OfferId, UserId = currentUserId, CreateDate = DateTime.Now, OfferGuid = Guid.NewGuid(), }; Guid newOfferId = this.offersRepository.Add(offers); List <PlanDetailResultExtension> planList = new List <PlanDetailResultExtension>(); var serializedPlans = JsonSerializer.Serialize(subscriptionPlanDetail); planList = JsonSerializer.Deserialize <List <PlanDetailResultExtension> >(serializedPlans); planList.ForEach(x => { x.OfferId = newOfferId; x.PlanGUID = Guid.NewGuid(); }); this.subscriptionService.AddPlanDetailsForSubscription(planList); var currentPlan = this.planRepository.GetById(newSubscription.PlanId); var subscriptionData = this.apiClient.GetSubscriptionByIdAsync(newSubscription.SubscriptionId).ConfigureAwait(false).GetAwaiter().GetResult(); var subscribeId = this.subscriptionService.AddOrUpdatePartnerSubscriptions(subscriptionData); if (subscribeId > 0 && subscriptionData.SaasSubscriptionStatus == SubscriptionStatusEnum.PendingFulfillmentStart) { SubscriptionAuditLogs auditLog = new SubscriptionAuditLogs() { Attribute = Convert.ToString(SubscriptionLogAttributes.Status), SubscriptionId = subscribeId, NewValue = SubscriptionStatusEnum.PendingFulfillmentStart.ToString(), OldValue = "None", CreateBy = currentUserId, CreateDate = DateTime.Now, }; this.subscriptionLogRepository.Save(auditLog); } subscriptionExtension = this.subscriptionService.GetSubscriptionsBySubscriptionId(newSubscription.SubscriptionId, true); subscriptionExtension.ShowWelcomeScreen = false; subscriptionExtension.CustomerEmailAddress = this.CurrentUserEmailAddress; subscriptionExtension.CustomerName = this.CurrentUserName; subscriptionExtension.SubscriptionParameters = this.subscriptionService.GetSubscriptionsParametersById(newSubscription.SubscriptionId, currentPlan.PlanGuid); } } else { this.TempData["ShowWelcomeScreen"] = "True"; subscriptionExtension.ShowWelcomeScreen = true; return(this.View(subscriptionExtension)); } } else { if (!string.IsNullOrEmpty(token)) { return(this.Challenge( new AuthenticationProperties { RedirectUri = "/?token=" + token, }, OpenIdConnectDefaults.AuthenticationScheme)); } else { this.TempData["ShowWelcomeScreen"] = "True"; subscriptionExtension.ShowWelcomeScreen = true; return(this.View(subscriptionExtension)); } } return(this.View(subscriptionExtension)); } catch (Exception ex) { this.logger.LogError("Message:{0} :: {1} ", ex.Message, ex.InnerException); return(this.View("Error", ex)); } }
/// <summary> /// Get All Subscription List for Current Logged in User /// </summary> /// <param name="token">The MS Token<see cref="string" /></param> /// <returns> /// The <see cref="IActionResult" /> /// </returns> public IActionResult Index(string token = null) { try { this.logger.LogInformation($"Landing page with token {token}"); SubscriptionResultExtension subscriptionDetail = new SubscriptionResultExtension(); if (User.Identity.IsAuthenticated) { if (Convert.ToBoolean(applicationConfigRepository.GetValuefromApplicationConfig(MainMenuStatusEnum.IsLicenseManagementEnabled.ToString())) == true) { this.TempData["ShowLicensesMenu"] = true; } var userId = this.userService.AddPartnerDetail(GetCurrentUserDetail()); var currentUserId = this.userService.GetUserIdFromEmailAddress(this.CurrentUserEmailAddress); this.subscriptionService = new SubscriptionService(this.subscriptionRepository, this.planRepository, userId); this.logger.LogInformation("User authenticated successfully"); if (!string.IsNullOrEmpty(token)) { this.TempData["ShowWelcomeScreen"] = null; token = token.Replace(' ', '+'); var newSubscription = this.apiClient.ResolveAsync(token).ConfigureAwait(false).GetAwaiter().GetResult(); if (newSubscription != null && newSubscription.SubscriptionId != default) { var subscriptionPlanDetail = this.apiClient.GetAllPlansForSubscriptionAsync(newSubscription.SubscriptionId).ConfigureAwait(false).GetAwaiter().GetResult(); this.subscriptionService.AddPlanDetailsForSubscription(subscriptionPlanDetail); // GetSubscriptionBy SubscriptionId var subscriptionData = this.apiClient.GetSubscriptionByIdAsync(newSubscription.SubscriptionId).ConfigureAwait(false).GetAwaiter().GetResult(); subscriptionData.Quantity = 0; var subscribeId = this.subscriptionService.AddUpdatePartnerSubscriptions(subscriptionData); if (subscribeId > 0 && subscriptionData.SaasSubscriptionStatus == SubscriptionStatusEnum.PendingFulfillmentStart) { SubscriptionAuditLogs auditLog = new SubscriptionAuditLogs() { Attribute = Convert.ToString(SubscriptionLogAttributes.Status), SubscriptionId = subscribeId, NewValue = SubscriptionStatusEnum.PendingFulfillmentStart.ToString(), OldValue = "None", CreateBy = currentUserId, CreateDate = DateTime.Now }; this.subscriptionLogRepository.Add(auditLog); } var serializedParent = JsonConvert.SerializeObject(subscriptionData); subscriptionDetail = JsonConvert.DeserializeObject <SubscriptionResultExtension>(serializedParent); subscriptionDetail.ShowWelcomeScreen = false; subscriptionDetail.CustomerEmailAddress = this.CurrentUserEmailAddress; subscriptionDetail.CustomerName = this.CurrentUserName; } } else { this.TempData["ShowWelcomeScreen"] = "True"; subscriptionDetail.ShowWelcomeScreen = true; return(this.View(subscriptionDetail)); } } else { if (!string.IsNullOrEmpty(token)) { return(this.Challenge(new AuthenticationProperties { RedirectUri = "/?token=" + token }, OpenIdConnectDefaults.AuthenticationScheme)); } else { this.TempData["ShowWelcomeScreen"] = "True"; subscriptionDetail.ShowWelcomeScreen = true; return(this.View(subscriptionDetail)); } } return(this.View(subscriptionDetail)); } catch (Exception ex) { logger.LogInformation("Message:{0} :: {1} ", ex.Message, ex.InnerException); return(View("Error")); } }