示例#1
0
    public static string CreateEvent(DateTime start, DateTime end, string id, string text, string resource, int clubID = Club.ClubIDNew)
    {
        try
        {
            if (IsValidCaller(clubID))
            {
                if (clubID == Club.ClubIDNew)
                {
                    throw new MyFlightbookException("Attempt to schedule with a non-existant club");
                }

                TimeZoneInfo tzi = Club.ClubWithID(clubID).TimeZone;

                // timezoneOffset is UTC time minus local time, so in Seattle it is 420 or 480 (depending on time of year)
                ScheduledEvent se = new ScheduledEvent(ScheduledEvent.ToUTC(start, tzi), ScheduledEvent.ToUTC(end, tzi), text, id, HttpContext.Current.User.Identity.Name, resource, clubID, tzi);
                if (!se.FCommit())
                {
                    throw new MyFlightbookException(se.LastError);
                }

                Club.ClubWithID(se.ClubID).NotifyAdd(se, HttpContext.Current.User.Identity.Name);
            }
        }
        catch (MyFlightbookException ex)
        {
            return(ex.Message);
        }
        return(string.Empty);
    }
        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);
        }