コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            var serviceContext = PortalCrmConfigurationManager.CreateServiceContext();

            var scheduledActivity = serviceContext.CreateQuery("serviceappointment").FirstOrDefault(s => s.GetAttributeValue <Guid>("activityid") == Id);

            if (scheduledActivity == null)
            {
                NotFound(context.Response, string.Format(ResourceManager.GetString("Service_Appointment_Not_Found"), Id));

                return;
            }

            var vevent = new VEvent
            {
                Created = scheduledActivity.GetAttributeValue <DateTime>("createdon"),
                Summary = scheduledActivity.GetRelatedEntity(serviceContext, new Relationship("service_service_appointments")).GetAttributeValue <string>("name"),
                Start   = scheduledActivity.GetAttributeValue <DateTime?>("scheduledstart").GetValueOrDefault(),
                End     = scheduledActivity.GetAttributeValue <DateTime?>("scheduledend").GetValueOrDefault()
            };

            context.Response.ContentType = "text/calendar";

            context.Response.Write(vevent.ToString());
        }
コード例 #2
0
ファイル: EventHandler.cs プロジェクト: bhushanawhad/OpenLan
        public void ProcessRequest(HttpContext context)
        {
            Guid id;

            if (!Guid.TryParse(context.Request.QueryString["id"], out id))
            {
                NotFound(context.Response, string.Format(@"Query string parameter ""id"" with value ""{0}"" is not a valid event ID.", context.Request.QueryString["id"]));

                return;
            }

            var serviceContext = (XrmServiceContext)PortalCrmConfigurationManager.CreateServiceContext();

            if (string.Equals(context.Request.QueryString["type"], "registration", StringComparison.OrdinalIgnoreCase))
            {
                var campaign = serviceContext.CampaignSet.FirstOrDefault(c => c.CampaignId == id);

                if (campaign == null)
                {
                    NotFound(context.Response, string.Format(@"Campaign with ID ""{0}"" not found.", id));

                    return;
                }

                var vevent = new VEvent
                {
                    Created     = campaign.CreatedOn,
                    Start       = campaign.MSA_StartDateTime,
                    End         = campaign.MSA_EndDateTime,
                    Summary     = campaign.MSA_EventName,
                    Description = campaign.MSA_EventDetails,
                    Location    = string.Format("{0} {1} {2} {3} {4}", campaign.MSA_Street1, campaign.MSA_City, campaign.MSA_StateProvince, campaign.MSA_ZipPostalCode, campaign.MSA_CountryRegion),
                    Organizer   = campaign.MSA_EventContact,
                    Url         = campaign.MSA_EventBrochureURL,
                };

                context.Response.ContentType = "text/calendar";

                context.Response.Write(vevent.ToString());

                return;
            }

            if (string.Equals(context.Request.QueryString["type"], "service", StringComparison.OrdinalIgnoreCase))
            {
                var scheduledActivity = serviceContext.ServiceAppointmentSet.FirstOrDefault(s => s.ActivityId == id);

                if (scheduledActivity == null)
                {
                    NotFound(context.Response, string.Format(@"Service appointment with ID ""{0}"" not found.", id));

                    return;
                }

                var vevent = new VEvent
                {
                    Created = scheduledActivity.CreatedOn,
                    Summary = scheduledActivity.service_service_appointments.Name,
                    Start   = scheduledActivity.ScheduledStart,
                    End     = scheduledActivity.ScheduledEnd
                };

                context.Response.ContentType = "text/calendar";

                context.Response.Write(vevent.ToString());

                return;
            }

            NotFound(context.Response, string.Format(@"Specified type ""{0}"" is not a recognized event type.", context.Request.QueryString["type"]));
        }