using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AlfredoLotar.Livro.Aspnet.SchoolModel;
using System.Data;
using System.Data.Objects;

public partial class StoredProcedures2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        using (SchoolEntities contexto = new SchoolEntities())
        {
            try
            {
                contexto.InsertPerson(txtNome.Text.Trim(), txtSobrenome.Text.Trim(), DateTime.Now, DateTime.Now.AddYears(1));                
                Preencher();
            }
            catch (EntitySqlException ex)
            {
                Response.Write("Erro EntitySqlException");
            }
            catch (EntityCommandExecutionException ex)
            {
                Response.Write("Erro EntityCommandExecutionException");
            }
        }
    }

    void Preencher()
    {
        using (SchoolEntities contexto = new SchoolEntities())
        {
            GridView1.DataSource = contexto.ExecuteStoreQuery<Person>
                    ("Select top 10 * from Person order by PersonID DESC");
            GridView1.DataBind();
        }
    }
}