public static string UpdateEvent(DateTime start, DateTime end, string id, string text, string resource, int clubID) { try { if (IsValidCaller(clubID)) { Club c = Club.ClubWithID(clubID); TimeZoneInfo tzi = c.TimeZone; ScheduledEvent scheduledevent = ScheduledEvent.AppointmentByID(id, tzi); ScheduledEvent scheduledeventOrig = new ScheduledEvent(); if (!scheduledevent.CanEdit(HttpContext.Current.User.Identity.Name)) { throw new MyFlightbookException(Resources.Schedule.ErrUnauthorizedEdit); } if (scheduledevent != null) { util.CopyObject(scheduledevent, scheduledeventOrig); // hold on to the original version, at least for now. scheduledevent.StartUtc = ScheduledEvent.ToUTC(start, tzi); scheduledevent.EndUtc = ScheduledEvent.ToUTC(end, tzi); text = HttpUtility.HtmlDecode(text); scheduledevent.Body = (String.IsNullOrWhiteSpace(text) && c.PrependsScheduleWithOwnerName) ? MyFlightbook.Profile.GetUser(scheduledevent.OwningUser).UserFullName : text; if (!String.IsNullOrEmpty(resource)) { scheduledevent.ResourceID = resource; } if (!scheduledevent.FCommit()) { throw new MyFlightbookException(scheduledevent.LastError); } Club.ClubWithID(scheduledevent.ClubID).NotifyOfChange(scheduledeventOrig, scheduledevent, HttpContext.Current.User.Identity.Name); } } } catch (MyFlightbookException ex) { return(ex.Message); } return(string.Empty); }
public static string DeleteEvent(string id) { try { ScheduledEvent scheduledevent = ScheduledEvent.AppointmentByID(id, TimeZoneInfo.Utc); if (scheduledevent == null) { return(Resources.Schedule.errItemNotFound); } string szUser = HttpContext.Current.User.Identity.Name; if (!scheduledevent.CanEdit(szUser)) { throw new MyFlightbookException(Resources.Schedule.ErrUnauthorizedEdit); } if (scheduledevent.FDelete()) { // Send any notifications - but do it on a background thread so that we can return quickly new Thread(() => { Club c = Club.ClubWithID(scheduledevent.ClubID); c.NotifyOfDelete(scheduledevent, szUser); }).Start(); } else { throw new MyFlightbookException(scheduledevent.LastError); } } catch (MyFlightbookException ex) { return(ex.Message); } return(string.Empty); }