Esempio n. 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);
    }
Esempio n. 2
0
    public static ScheduledEvent[] ReadEvents(DateTime dtStart, DateTime dtEnd, int clubID = Club.ClubIDNew, string resourceName = null)
    {
        if (!IsValidCaller(clubID, PrivilegeLevel.ReadOnly))
        {
            return(null);
        }

        Club                  c   = Club.ClubWithID(clubID);
        TimeZoneInfo          tzi = c.TimeZone;
        List <ScheduledEvent> lst = ScheduledEvent.AppointmentsInTimeRange(ScheduledEvent.ToUTC(dtStart, tzi), ScheduledEvent.ToUTC(dtEnd, tzi), resourceName, clubID, tzi);

        // Fix up the owner's name
        lst.ForEach((se) => {
            se.OwnerProfile = c.PrependsScheduleWithOwnerName ? c.Members.FirstOrDefault(cm => cm.UserName.CompareTo(se.OwningUser) == 0) : null;
            se.ReadOnly     = !se.CanEdit(HttpContext.Current.User.Identity.Name, c);
        });
        return(lst.ToArray());
    }
        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);
        }