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);
        }
示例#2
0
    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);
    }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HtmlLink lnk = new HtmlLink()
            {
                Href = VirtualPathUtility.ToAbsolute("~/Public/CSS/mfbheader.css")
            };

            Page.Header.Controls.Add(lnk);
            lnk.Attributes["type"] = "text/css";
            lnk.Attributes["rel"]  = "stylesheet";

            if (!IsPostBack)
            {
                // fix up the appropriate app name
                lnkDownload.Text        = Branding.ReBrand(Resources.LocalizedText.HeaderDownload);
                lnkDownloadIPhone.Text  = Branding.ReBrand(Resources.LocalizedText.HeaderDownloadIOS);
                lnkDownloadAndroid.Text = Branding.ReBrand(Resources.LocalizedText.HeaderDownloadAndroid);
                lnkLogo.ImageUrl        = Branding.CurrentBrand.LogoHRef;
                pnlDonate.Visible       = Page.User.Identity.IsAuthenticated;
                lnkDonate.Text          = Branding.ReBrand(Resources.LocalizedText.DonateSolicitation);

                if (Request != null && Request.UserAgent != null)
                {
                    string s = Request.UserAgent.ToUpperInvariant();

                    if (s.Contains("IPAD") || s.Contains("IPHONE"))
                    {
                        mvXSell.SetActiveView(vwIOS);
                    }

                    if (s.Contains("DROID"))
                    {
                        mvXSell.SetActiveView(vwDroid);
                    }
                }

                mvCrossSellOrEvents.SetActiveView(vwMobileCrossSell);

                mvLoginStatus.SetActiveView(Page.User.Identity.IsAuthenticated ? vwSignedIn : vwNotSignedIn);

                if (Page.User.Identity.IsAuthenticated)
                {
                    Refresh();
                    // see if we need to show an upcoming event; we repurpose a known GUID for this.
                    // If it's in the database AND in the future, we show it.
                    // Since header is loaded on every page load, cache it, using a dummy expired one if there was none.
                    ScheduledEvent se = (ScheduledEvent)Cache["upcomingWebinar"];
                    if (se == null)
                    {
                        se = ScheduledEvent.AppointmentByID("00000000-fe32-5932-bef8-000000000001", TimeZoneInfo.Utc);
                        if (se == null)
                        {
                            se = new ScheduledEvent()
                            {
                                EndUtc = DateTime.Now.AddDays(-2)
                            }
                        }
                        ;
                        Cache.Add("upcomingWebinar", se, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0), System.Web.Caching.CacheItemPriority.Default, null);
                    }
                    if (se != null && DateTime.UtcNow.CompareTo(se.EndUtc) < 0)
                    {
                        string[] rgLines = se.Body.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                        litWebinar.Text = String.Format(CultureInfo.CurrentCulture, "Join \"{0}\" on {1}", (rgLines == null || rgLines.Length == 0) ? string.Empty : rgLines[0], se.EndUtc.ToShortDateString()).Linkify();
                        mvCrossSellOrEvents.SetActiveView(vwUpcomingEvent);
                        lblWebinarDetails.Text = se.Body.Linkify(true);
                    }
                }
                else
                {
                    imgHdSht.Visible = false;
                }
            }
        }
示例#4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // fix up the appropriate app name
            lnkDownload.Text             = Branding.ReBrand(Resources.LocalizedText.HeaderDownload);
            lnkDownloadIPhone.Text       = Branding.ReBrand(Resources.LocalizedText.HeaderDownloadIOS);
            lnkDownloadAndroid.Text      = Branding.ReBrand(Resources.LocalizedText.HeaderDownloadAndroid);
            lnkDownloadWindowsPhone.Text = Branding.ReBrand(Resources.LocalizedText.HeaderDownloadWP7);
            lnkLogo.ImageUrl             = Branding.CurrentBrand.LogoHRef;
            pnlDonate.Visible            = Page.User.Identity.IsAuthenticated;
            lnkDonate.Text = Branding.ReBrand(Resources.LocalizedText.DonateSolicitation);

            if (Request != null && Request.UserAgent != null)
            {
                string s = Request.UserAgent.ToUpperInvariant();

                if (s.Contains("IPAD") || s.Contains("IPHONE"))
                {
                    mvXSell.SetActiveView(vwIOS);
                }

                if (s.Contains("DROID"))
                {
                    mvXSell.SetActiveView(vwDroid);
                }

                if (s.Contains("WINDOWS PHONE"))
                {
                    mvXSell.SetActiveView(vwW7Phone);
                }
            }

            mvCrossSellOrEvents.SetActiveView(vwMobileCrossSell);

            mvLoginStatus.SetActiveView(Page.User.Identity.IsAuthenticated ? vwSignedIn : vwNotSignedIn);
            if (Page.User.Identity.IsAuthenticated)
            {
                Profile pf = MyFlightbook.Profile.GetUser(Page.User.Identity.Name);
                lblUser.Text             = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.LoginStatusWelcome, pf.UserFirstName);
                lblMemberSince.Text      = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.MemberSinceShort, pf.CreationDate);
                lblLastLogin.Text        = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.MemberLastLogonShort, pf.LastLogon);
                lblLastActivity.Text     = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.MemberLastActivityShort, pf.LastActivity);
                itemLastActivity.Visible = pf.LastActivity.Date.CompareTo(pf.LastLogon.Date) != 0;

                // see if we need to show an upcoming event; we repurpose a known GUID for this.
                // If it's in the database AND in the future, we show it.
                // Since header is loaded on every page load, cache it, using a dummy expired one if there was none.
                ScheduledEvent se = (ScheduledEvent)Cache["upcomingWebinar"];
                if (se == null)
                {
                    se = ScheduledEvent.AppointmentByID("00000000-fe32-5932-bef8-000000000001", TimeZoneInfo.Utc);
                    if (se == null)
                    {
                        se = new ScheduledEvent()
                        {
                            EndUtc = DateTime.Now.AddDays(-2)
                        }
                    }
                    ;
                    Cache.Add("upcomingWebinar", se, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0), System.Web.Caching.CacheItemPriority.Default, null);
                }
                if (se != null && DateTime.UtcNow.CompareTo(se.EndUtc) < 0)
                {
                    string[] rgLines = se.Body.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    litWebinar.Text = String.Format(CultureInfo.CurrentCulture, "Join \"{0}\" on {1}", (rgLines == null || rgLines.Length == 0) ? string.Empty : rgLines[0], se.EndUtc.ToShortDateString()).Linkify();
                    mvCrossSellOrEvents.SetActiveView(vwUpcomingEvent);
                    lblWebinarDetails.Text = se.Body.Linkify(true);
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!Page.User.Identity.IsAuthenticated)
            {
                throw new MyFlightbookException("Unauthorized!");
            }

            int idClub = util.GetIntParam(Request, "c", 0);
            if (idClub == 0)
            {
                throw new MyFlightbookException("Invalid club");
            }

            Club c = Club.ClubWithID(idClub);

            if (c == null)
            {
                throw new MyFlightbookException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid club: {0}", idClub));
            }

            string   szIDs  = util.GetStringParam(Request, "sid");
            string[] rgSIDs = szIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (rgSIDs.Length == 0)
            {
                throw new MyFlightbookException("No scheduled events to download specified");
            }

            bool fIsAdmin = c.HasAdmin(Page.User.Identity.Name);

            using (Ical.Net.Calendar ic = new Ical.Net.Calendar())
            {
                ic.AddTimeZone(new VTimeZone(c.TimeZone.Id));

                string szTitle = string.Empty;

                foreach (string sid in rgSIDs)
                {
                    ScheduledEvent se = ScheduledEvent.AppointmentByID(sid, c.TimeZone);

                    if (se == null)
                    {
                        throw new MyFlightbookException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid scheduled event ID: {0}", sid));
                    }

                    if (!fIsAdmin && Page.User.Identity.Name.CompareOrdinal(se.OwningUser) != 0)
                    {
                        throw new MyFlightbookException("Attempt to download appointment that you don't own!");
                    }

                    ClubAircraft ca = c.MemberAircraft.FirstOrDefault(ca2 => ca2.AircraftID.ToString(System.Globalization.CultureInfo.InvariantCulture).CompareOrdinal(se.ResourceID) == 0);

                    Event ev = ic.Create <Event>();
                    ev.Uid           = se.ID;
                    ev.IsAllDay      = false;
                    ev.Start         = new CalDateTime(se.StartUtc, TimeZoneInfo.Utc.Id);
                    ev.End           = new CalDateTime(se.EndUtc, TimeZoneInfo.Utc.Id);
                    ev.Start.HasTime = ev.End.HasTime = true;   // has time is false if the ultimate time is midnight.
                    szTitle          = ev.Description = ev.Summary = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}{1}", ca == null ? string.Empty : String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} - ", ca.DisplayTailnumber), se.Body);
                    ev.Location      = c.HomeAirport == null ? c.HomeAirportCode : String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} - {1}", c.HomeAirportCode, c.HomeAirport.Name);

                    Alarm a = new Alarm();
                    a.Action           = AlarmAction.Display;
                    a.Description      = ev.Summary;
                    a.Trigger          = new Trigger();
                    a.Trigger.DateTime = ev.Start.AddMinutes(-30);
                    ev.Alarms.Add(a);

                    ic.Method = "PUBLISH";
                }

                CalendarSerializer s = new CalendarSerializer();

                string output = s.SerializeToString(ic);
                Page.Response.Clear();
                Page.Response.ContentType = "text/calendar";
                Response.AddHeader("Content-Disposition", String.Format(System.Globalization.CultureInfo.InvariantCulture, "inline;filename={0}", Branding.ReBrand(String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}appt.ics", szTitle)).Replace(" ", "-")));
                Response.Write(output);
                Response.Flush();
                Response.End();
            }
        }
    }
示例#6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!Page.User.Identity.IsAuthenticated)
            {
                throw new MyFlightbookException("Unauthorized!");
            }

            int idClub = util.GetIntParam(Request, "c", 0);
            if (idClub == 0)
            {
                throw new MyFlightbookException("Invalid club");
            }

            Club c = Club.ClubWithID(idClub);

            if (c == null)
            {
                throw new MyFlightbookException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid club: {0}", idClub));
            }

            string   szIDs  = util.GetStringParam(Request, "sid");
            string[] rgSIDs = szIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (rgSIDs.Length == 0)
            {
                throw new MyFlightbookException("No scheduled events to download specified");
            }

            bool fIsAdmin = c.HasAdmin(Page.User.Identity.Name);

            Calendar ic = new Calendar();
            ic.Calendar.AddTimeZone(c.TimeZone);

            string szTitle = string.Empty;

            foreach (string sid in rgSIDs)
            {
                ScheduledEvent se = ScheduledEvent.AppointmentByID(sid, c.TimeZone);

                if (se == null)
                {
                    throw new MyFlightbookException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid scheduled event ID: {0}", sid));
                }

                if (!fIsAdmin && Page.User.Identity.Name.CompareOrdinal(se.OwningUser) != 0)
                {
                    throw new MyFlightbookException("Attempt to download appointment that you don't own!");
                }

                ClubAircraft ca = c.MemberAircraft.FirstOrDefault(ca2 => ca2.AircraftID.ToString(System.Globalization.CultureInfo.InvariantCulture).CompareOrdinal(se.ResourceID) == 0);

                szTitle = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}{1}", ca == null ? string.Empty : String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} - ", ca.DisplayTailnumber), se.Body);
                CalendarEvent ev = new CalendarEvent()
                {
                    Uid         = se.ID,
                    IsAllDay    = false,
                    Start       = new CalDateTime(se.StartUtc, TimeZoneInfo.Utc.Id),
                    End         = new CalDateTime(se.EndUtc, TimeZoneInfo.Utc.Id),
                    Description = szTitle,
                    Summary     = szTitle,
                    Location    = c.HomeAirport == null ? c.HomeAirportCode : String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} - {1}", c.HomeAirportCode, c.HomeAirport.Name)
                };
                ev.Start.HasTime = ev.End.HasTime = true;  // has time is false if the ultimate time is midnight.

                Alarm a = new Alarm()
                {
                    Action      = AlarmAction.Display,
                    Description = ev.Summary,
                    Trigger     = new Trigger()
                    {
                        DateTime         = ev.Start.AddMinutes(-30),
                        AssociatedObject = ic
                    }
                };
                ev.Alarms.Add(a);
                ic.Calendar.Events.Add(ev);
                ic.Calendar.Method = "PUBLISH";
            }

            string szFormat = util.GetStringParam(Request, "fmt");

            switch (szFormat.ToUpperInvariant())
            {
            case "ICAL":
            default:
                WriteICal(ic);
                break;

            case "G":
                WriteGoogle(ic, c.TimeZone);
                break;

            case "Y":
                WriteYahoo(ic, c.TimeZone);
                break;
            }
        }
    }