public ActionResult Subscriptions() { var model = new SubscriptionsViewModel(); // Get the calendars we are subscribed to var calendars = Exigo.GetCustomerCalendarSubscriptions(Identity.Current.CustomerID); // Get the customers for each of the calendar subscriptions var customerIDs = calendars.Select(c => c.CustomerID).Distinct().ToList(); var apiCustomers = Exigo.OData().Customers .Where(customerIDs.ToOrExpression <Common.Api.ExigoOData.Customer, int>("CustomerID")) .Select(c => new Common.Api.ExigoOData.Customer() { CustomerID = c.CustomerID, FirstName = c.FirstName, LastName = c.LastName }) .ToList(); // Pair the data together to create our models var customers = new List <CalendarSubscriptionCustomer>(); foreach (var apiCustomer in apiCustomers) { // Create the special customer first var customer = new CalendarSubscriptionCustomer() { CustomerID = apiCustomer.CustomerID, FirstName = apiCustomer.FirstName, LastName = apiCustomer.LastName }; // Add their calendars customer.Calendars = calendars.Where(c => c.CustomerID == customer.CustomerID).ToList(); // Add our model to the collection model.CalendarSubscriptionCustomers.Add(customer); } return(View(model)); }
public ActionResult GetSubscriptions() { var subscriptions = Exigo.GetCustomerCalendarSubscriptions(Identity.Current.CustomerID); var ids = new List <string>(); foreach (var sub in subscriptions) { var id = sub.CalendarID.ToString(); ids.Add(id); } return(new JsonNetResult(new { success = true, subscriptions = ids.ToArray() })); }
public ActionResult Subscriptions() { var model = new SubscriptionsViewModel(); // Get the Calendar Subscriptions for the provided Customer ID var calendars = Exigo.GetCustomerCalendarSubscriptions(Identity.Current.CustomerID); // Get the CustomerIDs for each of the Calendar Subscriptions var customerIDs = calendars.Select(c => c.CustomerID).Distinct().ToList(); var customerCalendarSubscription = new List <CalendarSubscriptionCustomer>(); using (var context = Exigo.Sql()) { customerCalendarSubscription = context.Query <CalendarSubscriptionCustomer>(@" SELECT c.CustomerID ,c.FirstName ,c.LastName FROM Customers c WHERE c.CustomerID IN @customerids", new { customerids = customerIDs }).ToList(); //Apply the correct calendars to the customers foreach (var customer in customerCalendarSubscription) { customer.Calendars = calendars.Where(c => c.CustomerID == customer.CustomerID).ToList(); } model.CustomerCalendarSubscriptions = customerCalendarSubscription; } return(View(model)); }