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); } }
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; }
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; }
public Appointment(Appointment obj) { Copy(obj); }