Example #1
0
        public static void SubscribeToCustomerCalendar(int customerID, Guid calendarID)
        {
            // Check to ensure that the requested calendar exists
            var calendar = GetCalendars(new GetCalendarsRequest
            {
                CalendarIDs = new List <Guid>()
                {
                    calendarID
                }
            }).FirstOrDefault();

            if (calendar == null)
            {
                return;
            }

            // Next, ensure the customer is not subscribing to their own calendar
            if (calendar.CustomerID == customerID)
            {
                return;
            }

            // Next, check to ensure the provided customer is not already subscribed to this calendar
            var existingSubscription = GetCustomerCalendarSubscriptions(customerID)
                                       .Where(c => c.CalendarID == calendarID)
                                       .FirstOrDefault();

            if (existingSubscription != null)
            {
                return;
            }

            // If we got here, we can go ahead and subscribe
            var context         = Exigo.ODataCalendars();
            var newSubscription = new CalendarContext.CalendarSubscription();

            newSubscription.CustomerID = customerID;
            newSubscription.CalendarID = calendarID;

            context.AddToCalendarSubscriptions(newSubscription);
            context.SaveChanges();

            ClearCache("GetCalendars", customerID);
        }
Example #2
0
        public static void SubscribeToCustomerCalendar(int customerID, Guid calendarID)
        {
            // Check to ensure that the requested calendar exists
            var calendar = GetCalendars(new GetCalendarsRequest
            {
                CalendarIDs = new List<Guid>() { calendarID }
            }).FirstOrDefault();
            if (calendar == null) return;

            // Next, ensure the customer is not subscribing to their own calendar
            if (calendar.CustomerID == customerID) return;

            // Next, check to ensure the provided customer is not already subscribed to this calendar
            var existingSubscription = GetCustomerCalendarSubscriptions(customerID)
                .Where(c => c.CalendarID == calendarID)
                .FirstOrDefault();
            if (existingSubscription != null) return;

            // If we got here, we can go ahead and subscribe
            var context = Exigo.ODataCalendars();
            var newSubscription = new CalendarContext.CalendarSubscription();
            newSubscription.CustomerID = customerID;
            newSubscription.CalendarID = calendarID;

            context.AddToCalendarSubscriptions(newSubscription);
            context.SaveChanges();

            ClearCalendarCache("GetCalendars/{0}/{1}", customerID, true);
        }