public HttpResponseMessage Post(Guid taskId)
        {
            CrmConnection connection = CrmConnection.Parse(Strings.urlCreds);
            var ctx = new CrmServiceContext(new OrganizationService(connection));

            var taskReference = new EntityReference("task", taskId);

            try
            {
                var req = new SetStateRequest();
                req.State = new OptionSetValue(1);
                req.Status = new OptionSetValue(5);
                req.EntityMoniker = taskReference;

                var res = (SetStateResponse)ctx.Execute(req);
            }
            catch (Exception e)
            {
                return this.Request.CreateResponse(
                    HttpStatusCode.InternalServerError, e);
            }

            return this.Request.CreateResponse(
                HttpStatusCode.Created);
        }
        // GET api/appointment/[Guid.ToString()]
        public HttpResponseMessage Get()
        {
            CrmConnection connection = CrmConnection.Parse(Strings.urlCreds);
            var ctx = new CrmServiceContext(new OrganizationService(connection));

            WhoAmIRequest who = new WhoAmIRequest();
            var userId = ctx.Execute(who).Results["UserId"];

            var query = from a in ctx.AppointmentSet join i in ctx.IncidentSet on a.RegardingObjectId.Id equals i.Id join c in ctx.ContactSet on i.CustomerId.Id equals c.Id
                        where a.OwnerId.Id == new Guid(userId.ToString())
                        select new TestAppointmentObject
                        {
                            Id = a.Id,
                            ScheduledStart = a.ScheduledStart,
                            ScheduledEnd = a.ScheduledEnd,
                            RegardingObjectId = a.RegardingObjectId.Id,
                            Subject = a.Subject,
                            ContactId = i.CustomerId.Id,
                            FirstName = c.FirstName,
                            LastName = c.LastName,
                            MobilePhone = c.MobilePhone,
                            Address1_Line1 = c.Address1_Line1,
                            Address1_Line2 = c.Address1_Line2,
                            Address1_City = c.Address1_City,
                            Address1_StateOrProvince = c.Address1_StateOrProvince,
                            Address1_PostalCode = c.Address1_PostalCode,
                            ImageName = c.new_SienaImageName,
                            EnteredBuilding = a.new_EnteredBuilding,
                            LeftBuilding = a.new_LeftBuilding,
                            DistressCallReceived = a.new_DistressCallReceived
                        };

            var queryResults = query.ToList();

            foreach (TestAppointmentObject x in queryResults)
            {
                var today = DateTime.Today;
                if (((DateTime)x.ScheduledStart).Date == today.Date)
                {
                    x.RelativeDay = "Today";
                }
                else if (((DateTime)x.ScheduledStart).Date == today.Add(new System.TimeSpan(1, 0, 0, 0)).Date)
                {
                    x.RelativeDay = "Tomorrow";
                }
                else if (((DateTime)x.ScheduledStart).Date == today.Add(new System.TimeSpan(2, 0, 0, 0)).Date)
                {
                    x.RelativeDay = "2 Days";
                }
                else if (((DateTime)x.ScheduledStart).Date < today.Date)
                {
                    x.RelativeDay = "Previous";
                }
                else
                {
                    x.RelativeDay = "Later";
                }
            }

            var configuration = GlobalConfiguration.Configuration;
            configuration.Formatters.Remove(configuration.Formatters.XmlFormatter);

            //return listReturn;
            return this.Request.CreateResponse(
                HttpStatusCode.OK,
                queryResults);
        }