private void LoadFounderData(int founderId)
    {
        FoundersTableAdapter founders = new FoundersTableAdapter();

        CoreDataObjects.FoundersRow r = (CoreDataObjects.FoundersRow)founders.GetFounderById(founderId).Rows[0];

        //display image if available
        string imageUrl = string.Format("/images/founders/thumbs/{0}_thumb.jpg", r.FullName.Replace(' ', '-'));

        if (!File.Exists(Server.MapPath(@"~" + imageUrl)))
        {
            imgFounder.Visible = false;
        }

        //add the image and meta tag data for social networks
        imgFounder.ImageUrl      = imageUrl;
        imgFounder.AlternateText = "Image of Founder " + r.FullName;
        imgFounder.ToolTip       = r.FullName;
        imgFounder.Width         = 83;
        imgFounder.Height        = 110;
        Page.AddMetaInfo(OpenGraphMetaTags.Image, imageUrl);
        Page.AddMetaInfo(MetaTags.ImageThumbnail, imageUrl);

        //populate the founder information fields
        lblFounderName.InnerText     = r.FullName;
        lblFounderLifeSpan.InnerText = string.Format("{0} - {1}", r.DateBorn.ToString("MMMM dd, yyyy"), r.DateDied.ToString("MMMM dd, yyyy"));
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FoundersTableAdapter foundersAdpt = new FoundersTableAdapter();
            this.ddFounders.AppendDataBoundItems = true;
            this.ddFounders.Items.Add("");
            this.ddFounders.DataSource     = foundersAdpt.GetData().OrderBy(n => n.FirstName);
            this.ddFounders.DataTextField  = "FullName";
            this.ddFounders.DataValueField = "FounderID";
            this.ddFounders.DataBind();

            try
            {
                if (Request["Founder"] != null)
                {
                    this.ddFounders.Items.FindByValue(Request["Founder"]).Selected = true;
                }
            }
            catch
            {
                //do nothing
            }
        }
    }
    protected void btnAddFounder_Click(object sender, EventArgs e)
    {
        int id = 0;

        try
        {
            FoundersTableAdapter foundersAdpt = new FoundersTableAdapter();

            string firstName, lastName, middleName, suffix;
            firstName  = txtFirstName.Text.Trim();
            middleName = txtMiddleName.Text.Trim() == "" ? null : txtMiddleName.Text.Trim();
            lastName   = txtLastName.Text.Trim();
            suffix     = txtSuffix.Text.Trim() == "" ? null : txtSuffix.Text.Trim();

            //query the addition against the database and confirm if the
            if (foundersAdpt.GetData().Count(
                    row =>
                    row.FirstName == firstName &&
                    row.LastName == lastName &&
                    middleName == (row.IsMiddleNameNull() ? null : row.MiddleName) &&
                    suffix == (row.IsSuffixNull() ? null : row.Suffix)) != 0)
            {
                throw new ApplicationException("The Founder that you attempted to enter already exists.");
            }

            //insert the new record
            foundersAdpt.InsertQuick(firstName, middleName, lastName, suffix);

            //get the new identity
            id = (int)foundersAdpt.GetIdentity();

            //kick the user to the add quote page
            Response.Redirect("add-quote.aspx?Founder=" + id.ToString());
        }
        catch (Exception ex)
        {
            this.ShowError(ex);
            txtFirstName.Text  = "";
            txtLastName.Text   = "";
            txtMiddleName.Text = "";
            txtSuffix.Text     = "";
        }
    }
Beispiel #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        FoundersTableAdapter          founders     = new FoundersTableAdapter();
        ContributionsViewTableAdapter contributors = new ContributionsViewTableAdapter();
        QuotesViewTableAdapter        quotes       = new QuotesViewTableAdapter();

        Contributor c = Authenticator.GetUser();

        int tquotes = (int)quotes.GetCount();;
        int cquotes = (int)quotes.GetCountByContributor(c.ContributorId);

        lblTotalFounders.Text     = founders.GetCount().ToString();
        lblTotalQuotes.Text       = tquotes.ToString();
        lblQuotesContributed.Text = cquotes.ToString();
        lblContributionRatio.Text = Math.Round(((double)cquotes / (double)tquotes) * 100, 2).ToString();

        //popluate grids
        GridView1.DataSource = contributors.GetData();
        GridView1.DataBind();

        GridView2.DataSource = quotes.GetTop15ByContributorId(c.ContributorId);
        GridView2.DataBind();
    }
    private void LoadSingleQuote(int quoteId)
    {
        CoreDataObjects.QuotesViewRow r;

        if (quoteId == 0)
        {
            //load the quote of the day
            r = (CoreDataObjects.QuotesViewRow)quotesAdpt.GetQuoteOfTheDay().Rows[0];
        }
        else
        {
            //get quote that is requested
            r = (CoreDataObjects.QuotesViewRow)quotesAdpt.GetByQuoteID(quoteId).Rows[0];
        }

        //setup page meta data title
        Page.Title = string.Format("{0} Quote #{1}", r.FullName, r.QuoteID);

        //change meta title on the quote of the day request
        if (_qotd)
        {
            Page.AddMetaInfo(OpenGraphMetaTags.Title, string.Format("Quote of the Day: {0} Quote #{1}", r.FullName, r.QuoteID));
        }
        else
        {
            Page.AddMetaInfo(OpenGraphMetaTags.Title, string.Format("{0} Quote #{1}", r.FullName, r.QuoteID));
        }

        Page.AddMetaInfo(OpenGraphMetaTags.Type, "article");
        Page.AddMetaInfo(OpenGraphMetaTags.Site_Name, "WhatWouldTheFoundersDo.org");
        Page.AddMetaInfo(OpenGraphMetaTags.URL, string.Format("http://www.whatwouldthefoundersdo.org/showquote.aspx?q={0}", r.QuoteID));
        Page.AddMetaInfo(OpenGraphMetaTags.Description, string.Format("{0}", r.QuoteText));

        LoadFounderData(r.FounderID);

        try
        {
            if (Request.QueryString["Edit"] != null)
            {
                if (Authenticator.GetUser().Role == ContributorRoles.Admin)
                {
                    if (!IsPostBack)
                    {
                        FoundersTableAdapter foundersAdpt = new FoundersTableAdapter();
                        this.ddFounders.DataSource     = foundersAdpt.GetData().OrderBy(n => n.FirstName);
                        this.ddFounders.DataTextField  = "FullName";
                        this.ddFounders.DataValueField = "FounderID";
                        this.ddFounders.DataBind();
                    }


                    //show the quote in a text box
                    QuoteText.Text     = r.QuoteText;
                    QuoteText.Width    = 580;
                    QuoteText.Rows     = (r.QuoteText.Length / 118) + 1;
                    QuoteText.CssClass = "transparent";
                    QuoteText.ToolTip  = "Click to modify.";
                    QuoteText.Attributes.Add("onclick", "this.className = 'selected';");
                    QuoteText.Attributes.Add("onblur", "this.className = 'transparent';");

                    ddFounders.ClearSelection();
                    //ddFounders.SelectedValue = r.FounderID.ToString();
                    ddFounders.Items.FindByValue(r.FounderID.ToString()).Attributes.Add("selected", "true");

                    PanelAdmin.Visible = true;
                    QuoteId.Value      = r.QuoteID.ToString();
                }
            }
            else
            {
                QuoteHelper.LoadQuote(PanelQuote, "", r.QuoteText, 0, r.ReferenceInfo, r.Keywords, false);
            }
        }
        catch
        {
            QuoteHelper.LoadQuote(PanelQuote, "", r.QuoteText, 0, r.ReferenceInfo, r.Keywords, false);
        }
    }