Exemplo n.º 1
0
        public ActionResult Subscriptions()
        {
            var model = new SubscriptionsViewModel();

            // Get the Calendar Subscriptions for the provided Customer ID
            var calendars = ExigoDAL.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 = ExigoDAL.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));
        }