protected void ScheduleService_Click(object sender, EventArgs e)
        {
            var availableResourceId = (Guid)AvailableTimes.SelectedDataKey.Values["AvailableResource"];
            var availableResource   = XrmContext.ResourceSet.First(r => r.ResourceId == availableResourceId);
            var selectedStart       = (DateTime)AvailableTimes.SelectedDataKey.Values["ScheduledStartUniversalTime"];
            var selectedEnd         = (DateTime)AvailableTimes.SelectedDataKey.Values["ScheduledEndUniversalTime"];

            var appointment = new ServiceAppointment
            {
                ServiceId      = Service.ToEntityReference(),
                Subject        = "Web Service Scheduler: " + ServiceType.SelectedItem,
                ScheduledStart = selectedStart,
                ScheduledEnd   = selectedEnd,
                Resources      = new[] { new ActivityParty {
                                             PartyId = new EntityReference(availableResource.ObjectTypeCode, availableResource.Id)
                                         } },
                Customers = new[] { new ActivityParty {
                                        PartyId = Contact.ToEntityReference()
                                    } }
            };

            XrmContext.AddObject(appointment);
            XrmContext.SaveChanges();
            XrmContext.SetState((int)Enums.ServiceAppointmentState.Scheduled, 4, appointment);

            var page = ServiceContext.GetPageBySiteMarkerName(Website, "Service Details");

            Response.Redirect(string.Format("{0}?serviceid={1}", ServiceContext.GetUrl(page), appointment.Id));
        }
Esempio n. 2
0
        protected void CancelService(Guid activityID)
        {
            var appointment =
                from serviceActivity in XrmContext.ServiceAppointmentSet.ToList()
                where serviceActivity.ActivityId == activityID
                select serviceActivity;
            var serviceApp = appointment.First();

            XrmContext.SetState((int)Enums.ServiceAppointmentState.Canceled, -1, serviceApp);

            Response.Redirect(Request.RawUrl);
        }
Esempio n. 3
0
        protected void CancelService(Guid activityID)
        {
            var appointment = XrmContext.CreateQuery("serviceappointment").FirstOrDefault(a => a.GetAttributeValue <Guid>("activityid") == activityID);

            if (appointment == null)
            {
                return;
            }

            XrmContext.SetState((int)ServiceAppointmentState.Canceled, -1, appointment);

            Response.Redirect(Request.RawUrl);
        }
Esempio n. 4
0
        protected void ScheduleService_Click(object sender, EventArgs e)
        {
            var availableResourceId = (Guid)AvailableTimes.SelectedDataKey.Values["AvailableResource"];
            var availableResource   = XrmContext.CreateQuery("resource").First(r => r.GetAttributeValue <Guid>("resourceid") == availableResourceId);
            var selectedStart       = (DateTime)AvailableTimes.SelectedDataKey.Values["ScheduledStartUniversalTime"];
            var selectedEnd         = (DateTime)AvailableTimes.SelectedDataKey.Values["ScheduledEndUniversalTime"];

            var appointment = new Entity("serviceappointment");

            appointment.SetAttributeValue("serviceid", Service.ToEntityReference());
            appointment.SetAttributeValue("subject", "Web Service Scheduler: " + ServiceType.SelectedItem);
            appointment.SetAttributeValue("scheduledstart", selectedStart);
            appointment.SetAttributeValue("scheduledend", selectedEnd);

            var resourcesActivityParty = new Entity("activityparty");

            resourcesActivityParty["partyid"] = new EntityReference(availableResource.GetAttributeValue <string>("objecttypecode"), availableResource.Id);
            var resources = new EntityCollection(new List <Entity> {
                resourcesActivityParty
            });

            appointment.SetAttributeValue("resources", resources);

            var customersActivityParty = new Entity("activityparty");

            customersActivityParty["partyid"] = Contact.ToEntityReference();
            var customers = new EntityCollection(new List <Entity> {
                customersActivityParty
            });

            appointment.SetAttributeValue("customers", customers);

            XrmContext.AddObject(appointment);
            XrmContext.SaveChanges();
            XrmContext.SetState((int)ServiceAppointmentState.Scheduled, 4, appointment);

            var page = ServiceContext.GetPageBySiteMarkerName(Website, "Service Details");

            Response.Redirect(string.Format("{0}?serviceid={1}", ServiceContext.GetUrl(page), appointment.Id));
        }
Esempio n. 5
0
 private void SetStateCanceled(Entity entity)
 {
     XrmContext.SetState((int)Enums.IncidentState.Canceled, -1, entity);
 }