예제 #1
0
        public void Copy(Appointment obj)
        {
            if (obj == null)
                return;

            // copy all of the properties
            foreach (PropertyInfo pi in this.GetType().GetProperties())
            {
                var val = pi.GetValue(obj, null);
                pi.SetValue(this, val, null);
            }
        }
예제 #2
0
        public ActionResult CreateAppointment(Appointment appointment)
        {
            GoogleClient client = new GoogleClient(CurrentUser, StorageContext);
            var item = client.AddCalendarEvent(appointment);
            var appointmentResult = new JsAppointmentResult();
            if (item != null)
                appointmentResult.Result = item;
            else
                appointmentResult.StatusCode = HttpStatusCode.InternalServerError;

            JsonResult result = new JsonResult();
            result.Data = appointmentResult;
            return result;
        }
예제 #3
0
        public Item AddCalendarEvent(Appointment appt)
        {
            DateTime utcStartTime, utcEndTime;
            if (DateTime.TryParse(appt.StartTime, out utcStartTime) &&
                DateTime.TryParse(appt.EndTime, out utcEndTime))
            {
                var item = storage.GetItem(this.user, appt.ItemID);

                Event calEvent = new Event()
                {
                    Summary = appt.Name,
                    Start = new EventDateTime() { DateTime = XmlConvert.ToString(utcStartTime, XmlDateTimeSerializationMode.Utc) },
                    End = new EventDateTime() { DateTime = XmlConvert.ToString(utcEndTime, XmlDateTimeSerializationMode.Utc) },
                    Description = appt.Notes,
                    Location = appt.Location,
                    ExtendedProperties = new Event.ExtendedPropertiesData(),
                };
                // add item id as private extended property for event
                if (item != null)
                {
                    calEvent.ExtendedProperties.Private = new Event.ExtendedPropertiesData.PrivateData();
                    calEvent.ExtendedProperties.Private.Add(ExtensionItemID, item.ID.ToString());
                }

                // TODO: investigate using Gadget to support link back to product

                try
                {
                    EventsResource.InsertRequest eventInsertReq = this.CalendarService.Events.Insert(calEvent, UserCalendar);
                    Event result = eventInsertReq.Fetch();

                    if (result.HtmlLink != null && item != null)
                    {   // add event HtmlLink as a WebLink in item

                        FieldValue fvWebLinks = item.GetFieldValue(FieldNames.WebLinks, true);
                        JsonWebLink webLink = new JsonWebLink() { Name = "Calendar Event", Url = result.HtmlLink };
                        List<JsonWebLink> webLinks = (string.IsNullOrEmpty(fvWebLinks.Value)) ?
                            new List<JsonWebLink>() : JsonSerializer.Deserialize<List<JsonWebLink>>(fvWebLinks.Value);
                        //var webLink = new { Name = "Calendar Event", Url = result.HtmlLink };
                        //var webLinks = (string.IsNullOrEmpty(fvWebLinks.Value)) ?
                        //    new List<object>() : JsonSerializer.Deserialize<List<object>>(fvWebLinks.Value);
                        webLinks.Add(webLink);
                        fvWebLinks.Value = JsonSerializer.Serialize(webLinks);
                    }

                    // add event id to UserFolder EntityRefs for item
                    //Item metaItem = storage.UserFolder.GetEntityRef(user, item);
                    //FieldValue fvCalEventID = metaItem.GetFieldValue(ExtendedFieldNames.CalEventID, true);
                    //fvCalEventID.Value = result.Id;
                    storage.SaveChanges();
                    return item;
                }
                catch (Exception e)
                {
                    TraceLog.TraceException("Could not add appointment to Calendar", e);
                }
            }
            return null;
        }
예제 #4
0
 public Appointment(Appointment obj)
 {
     Copy(obj);
 }