コード例 #1
0
        public static void SyncAttendee(string apiUrl)
        {
            var eb          = new EBApi(Settings.GetAccessToken(), Settings.GetOrganizationId().ToLong(0));
            var attendee    = eb.GetAttendee(apiUrl, "event,order");
            var order       = attendee.Order;
            var rockContext = new RockContext();
            var group       = GetGroupByEBEventId(attendee.Event_Id, rockContext);
            var ebEvent     = attendee.Event;

            if (group != null && ebEvent != null)
            {
                var gmPersonAttributeKey = GetPersonAttributeKey(rockContext, group);

                var groupMemberService = new GroupMemberService(rockContext);
                var personAliasService = new PersonAliasService(rockContext);

                AttendanceOccurrence occ = GetOrAddOccurrence(rockContext, group, ebEvent);

                SyncAttendee(rockContext, attendee, order, group, groupMemberService, personAliasService, occ, attendee.Event_Id, ebEvent.IsRSVPEvent(eb), gmPersonAttributeKey, false);
                rockContext.SaveChanges();
            }
            else
            {
                HttpContext httpContext  = HttpContext.Current;
                var         logException = new Exception(string.Format("Eventbrite SyncAttendee, Group not found for Event: {0}", attendee.Event_Id), new Exception(string.Format("Sync api request: {0}", apiUrl)));
                ExceptionLogService.LogException(logException, httpContext);
            }
        }
コード例 #2
0
        public static bool EBoAuthCheck()
        {
            var retVar  = false;
            var getUser = new EBApi(Settings.GetAccessToken()).GetUser();

            if (getUser != null && getUser.Id != 0)
            {
                retVar = true;
            }
            return(retVar);
        }
コード例 #3
0
ファイル: Event.cs プロジェクト: KingdomFirst/RockAssemblies
        public bool IsRSVPEvent(EBApi eb)
        {
            var retVar = false;
            var cq     = eb.GetEventCannedQuestionsById(Id);
            var test   = cq.Questions.FirstOrDefault(q => q.Respondent.Equals("attendee", StringComparison.CurrentCultureIgnoreCase));

            if (test == null)
            {
                retVar = true;
            }
            return(retVar);
        }
コード例 #4
0
 private void LoadEventbriteEvent()
 {
     if (_rockGroup == null)
     {
         return;
     }
     if (_evntId > 0)
     {
         _eb      = new EBApi(Settings.GetAccessToken(), Settings.GetOrganizationId().ToLong(0));
         _ebevent = _eb.GetEventById(_evntId);
     }
 }
コード例 #5
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = value;
            var    splitVal       = value.SplitDelimitedValues("^");
            long?  longVal        = (splitVal.Count() > 0) ? splitVal[0].AsLongOrNull() : null;

            if (longVal.HasValue)
            {
                var eb = new EBApi(Settings.GetAccessToken(), Settings.GetOrganizationId().ToLong(0));
                var eventbriteEvent    = eb.GetEventById(longVal.Value);
                var linkedEventTickets = eb.GetTicketsById(longVal.Value);
                var sold  = 0;
                var total = 0;
                foreach (var ticket in linkedEventTickets.Ticket_Classes)
                {
                    sold  += ticket.QuantitySold;
                    total += ticket.QuantityTotal;
                }
                var available = total - sold;

                if (eventbriteEvent != null)
                {
                    if (condensed)
                    {
                        formattedValue = string.Format("{0} - {1} ({2})", eventbriteEvent.Name.Text, eventbriteEvent.Start.Local, eventbriteEvent.Status);
                    }
                    else
                    {
                        var eventbriteStatus = new StringBuilder();
                        eventbriteStatus.Append("<dl>");
                        eventbriteStatus.AppendFormat("<dd>{0} - {1} ({2})</dd>", eventbriteEvent.Name.Html, eventbriteEvent.Start.Local, eventbriteEvent.Status);
                        eventbriteStatus.AppendFormat("<dt>Link</dt><dd><a href={0}>{0}</a></dd>", eventbriteEvent.Url);
                        eventbriteStatus.AppendFormat("<dt>Capacity</dt><dd>{0}</dd>", eventbriteEvent.Capacity.ToString());
                        eventbriteStatus.AppendFormat("<dt>Tickets</dt><dd>{0} Available + {1} Sold = {2} Total</dd>", available, sold, total);
                        eventbriteStatus.AppendFormat("<dt>Synced</dt><dd>{0}</dd>", (splitVal.Length > 1) ? splitVal[1] : "Never");
                        eventbriteStatus.Append("</dl>");

                        formattedValue = eventbriteStatus.ToString();
                    }
                }
            }

            return(base.FormatValue(parentControl, formattedValue, configurationValues, condensed));
        }
コード例 #6
0
        /// <summary>
        /// Creates the control(s) necessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id)
        {
            var parentControl = new Panel();
            var editControl   = new RockDropDownList {
                ID = id
            };

            editControl.Items.Add(new ListItem());
            var eb = new EBApi(Settings.GetAccessToken(), Settings.GetOrganizationId().ToLong(0));

            var organizationEvents = eb.GetOrganizationEvents("all", 500);

            if (organizationEvents.Pagination.Has_More_Items)
            {
                var looper = new OrganizationEventsResponse();
                for (int i = 2; i <= organizationEvents.Pagination.PageCount; i++)
                {
                    looper = eb.GetOrganizationEvents(i, "all", 500);
                    organizationEvents.Events.AddRange(looper.Events);
                }
            }

            if (organizationEvents != null && organizationEvents.Events != null)
            {
                foreach (var template in organizationEvents.Events)
                {
                    editControl.Items.Add(new ListItem(string.Format("{0} - {1} ({2})", template.Name.Text.ToString(), template.Start.Local, template.Status), template.Id.ToString()));
                }
                editControl.Attributes["data-syncdate"] = "";
                parentControl.Controls.Add(editControl);

                return(parentControl);
            }

            return(null);
        }
コード例 #7
0
        public static void SyncEvent(
            int groupid,
            bool updatePrimaryEmail = false,
            string userid           = "Eventbrite",
            int recordStatusId      = 5,
            int connectionStatusId  = 66,
            bool EnableLogging      = false,
            bool ThrottleSync       = false)
        {
            //Setup
            var rockContext = new RockContext();

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("GroupId:{0}", groupid), "Started");
            }

            var group = new GroupService(rockContext).Get(groupid);
            var eb    = new EBApi(Settings.GetAccessToken(), Settings.GetOrganizationId().ToLong(0));
            var groupEBEventIDAttr    = GetGroupEBEventId(group);
            var groupEBEventAttrSplit = groupEBEventIDAttr.Value.SplitDelimitedValues("^");
            var evntid = long.Parse(groupEBEventIDAttr != null ? groupEBEventAttrSplit[0] : "0");

            if (ThrottleSync && groupEBEventAttrSplit.Length > 1 && groupEBEventAttrSplit[1].AsDateTime() > RockDateTime.Now.Date.AddMinutes(-30))
            {
                return;
            }

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("Group: {0}", group), "Got Group and EBEventId from Group.");
            }

            var ebOrders             = new List <Order>();
            var ebEvent              = eb.GetEventById(evntid);
            var IsRSVPEvent          = ebEvent.IsRSVPEvent(eb);
            var gmPersonAttributeKey = GetPersonAttributeKey(rockContext, group);

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("eb.GetEventById({0})", evntid), "eb.GetEventById and get Person Attribute Key");
            }

            //Get Eventbrite Attendees
            var ebOrderGet = eb.GetExpandedOrdersById(evntid);

            ebOrders.AddRange(ebOrderGet.Orders);
            if (ebOrderGet.Pagination.PageCount > 1)
            {
                var looper = new EventOrders();
                for (int i = 2; i <= ebOrderGet.Pagination.PageCount; i++)
                {
                    looper = eb.GetExpandedOrdersById(evntid, i);
                    ebOrders.AddRange(looper.Orders);
                }
            }

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("GetExpandedOrdersById:{0}", evntid), string.Format("Result count: {0}", ebOrders.Count));
            }

            var groupMemberService = new GroupMemberService(rockContext);
            var personAliasService = new PersonAliasService(rockContext);

            AttendanceOccurrence occ = GetOrAddOccurrence(rockContext, group, ebEvent);

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("GroupId: {0} Evntid: {1}", groupid, evntid), "Begin For each order in ebOrders");
            }
            foreach (var order in ebOrders)
            {
                foreach (var attendee in order.Attendees)
                {
                    HttpContext.Current.Server.ScriptTimeout = HttpContext.Current.Server.ScriptTimeout + 2;
                    SyncAttendee(rockContext, attendee, order, group, groupMemberService, personAliasService, occ, evntid, IsRSVPEvent, gmPersonAttributeKey, updatePrimaryEmail, recordStatusId, connectionStatusId, EnableLogging);
                }
            }

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("End Sync for Group: {0}", groupid), "End Sync and Write SyncTime to Group");
            }
            rockContext.SaveChanges();

            // Write the Sync Time
            group.SetAttributeValue(groupEBEventIDAttr.AttributeKey, string.Format("{0}^{1}", groupEBEventIDAttr.Value.SplitDelimitedValues("^")[0], RockDateTime.Now.ToString("g", CultureInfo.CreateSpecificCulture("en-us"))));
            group.SaveAttributeValue(groupEBEventIDAttr.AttributeKey, rockContext);
        }