public ActionResult Refresh() { try { // get all organizations and their respective subscription for a given tenant var orgs = AzureResourceManagerUtil.GetUserOrganizations(); Dictionary <Organization, List <Subscription> > dictionary = new Dictionary <Organization, List <Subscription> >(); foreach (var item in orgs) { if (!dictionary.ContainsKey(item)) { var subscriptions = AzureResourceManagerUtil.GetUserSubscriptions(item.Id); dictionary.Add(item, subscriptions); } } // check if these subscriptions are already added in the storage var repo = new EntityRepo <UserSubscription>(); var list = repo.Get(USER_SUBSCRIPTION_TABLE_PARTITION_KEY, null, ""); var existingSubscriptions = new Dictionary <string, string>(); foreach (var item in list) { existingSubscriptions.Add(item.SubscriptionId, item.SubscriptionId); } // list of new subscription to add var listOfUserSubscription = new List <UserSubscription>(); foreach (var subscriptions in dictionary.Values) { foreach (var subscription in subscriptions) { UserSubscription userSubscription = new UserSubscription(subscription.Id, subscription.OrganizationId); userSubscription.DisplayName = subscription.DisplayName; // if the subscription is not already in the storage add them // otherwise the one in the storage should have latest info if (!existingSubscriptions.ContainsKey(userSubscription.SubscriptionId)) { listOfUserSubscription.Add(userSubscription); } } } // if one or more subscriptions are discovered, add them if (listOfUserSubscription.Count > 0) { repo.Insert(listOfUserSubscription); } return(Json(dictionary.ToList(), JsonRequestBehavior.AllowGet)); } catch (Exception exp) { Logger.Log("Subscription-Web-API", "Error", exp.Message, exp.ToString()); return(new HttpStatusCodeResult(500, exp.Message)); } }
public ActionResult Index() { HomeIndexViewModel model = null; if (ClaimsPrincipal.Current.Identity.IsAuthenticated) { model = new HomeIndexViewModel(); model.UserOrganizations = new Dictionary <string, Organization>(); model.UserSubscriptions = new Dictionary <string, Subscription>(); model.UserCanManageAccessForSubscriptions = new List <string>(); model.DisconnectedUserOrganizations = new List <string>(); var orgnaizations = AzureResourceManagerUtil.GetUserOrganizations(); foreach (Organization org in orgnaizations) { model.UserOrganizations.Add(org.Id, org); var subscriptions = AzureResourceManagerUtil.GetUserSubscriptions(org.Id); if (subscriptions != null) { foreach (var subscription in subscriptions) { Subscription s = db.Subscriptions.Find(subscription.Id); if (s != null) { subscription.IsConnected = true; subscription.ConnectedOn = s.ConnectedOn; subscription.ConnectedBy = s.ConnectedBy; subscription.AzureAccessNeedsToBeRepaired = AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription(subscription.Id, org.Id); subscription.UsageString = AzureResourceManagerUtil.GetUsage(s.Id, org.Id); //Deserialize the usage response into the usagePayload object subscription.usagePayload = JsonConvert.DeserializeObject <UsagePayload>(subscription.UsageString); List <UsageAggregate> UsageAggregateList = subscription.usagePayload.value; } else { subscription.IsConnected = false; } model.UserSubscriptions.Add(subscription.Id, subscription); if (AzureResourceManagerUtil.UserCanManageAccessForSubscription(subscription.Id, org.Id)) { model.UserCanManageAccessForSubscriptions.Add(subscription.Id); } } } else { model.DisconnectedUserOrganizations.Add(org.Id); } } } return(View(model)); }
public ActionResult Index() { HomeIndexViewModel model = null; if (ClaimsPrincipal.Current.Identity.IsAuthenticated) { model = new HomeIndexViewModel(); model.UserOrganizations = new Dictionary <Guid, Organization>(); model.UserSubscriptions = new Dictionary <Guid, Subscription>(); model.UserCanManageAccessForSubscriptions = new List <Guid>(); model.DisconnectedUserOrganizations = new List <Guid>(); var organizations = AzureResourceManagerUtil.GetUserOrganizations(); foreach (Organization org in organizations) { model.UserOrganizations.Add(org.Id, org); var subscriptions = AzureResourceManagerUtil.GetUserSubscriptions(org.Id); if (subscriptions != null) { foreach (var subscription in subscriptions) { Subscription s = db.Subscriptions.Find(subscription.Id); if (s != null) { subscription.IsConnected = true; subscription.ConnectedOn = s.ConnectedOn; subscription.ConnectedBy = s.ConnectedBy; subscription.DisplayTag = s.DisplayTag; subscription.AzureAccessNeedsToBeRepaired = !AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription(subscription.Id, org.Id); } else { subscription.IsConnected = false; } model.UserSubscriptions.Add(subscription.Id, subscription); if (AzureResourceManagerUtil.UserCanManageAccessForSubscription(subscription.Id, org.Id)) { model.UserCanManageAccessForSubscriptions.Add(subscription.Id); } } } else { model.DisconnectedUserOrganizations.Add(org.Id); } } } return(View(model)); }