protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Beer b = new PremiumBeer();
                b.Name = "Primator";
                b.Weight = b.InitialWeight = 645;
                b.Country = "CZECH";

                using (TweetBeerContainer dbContainer = new TweetBeerContainer())
                {
                    #region Inserting

                    dbContainer.AddToBeer(b);
                    dbContainer.SaveChanges();

                    #endregion

                    #region Updating

                    b.Name = "Corona";
                    dbContainer.SaveChanges();

                    #endregion

                    #region Delete

                    //dbContainer.DeleteObject(b);
                    //dbContainer.SaveChanges();

                    #endregion

                    #region LINQ Query

                    var coronas = from beer in dbContainer.Beer.ToList()
                                  where beer.Name == "Corona"
                                  select beer;

                    #endregion
                }

                #region Equivalent to using

                //TweetBeerContainer v = null;
                //try
                //{
                //    v = new TweetBeerContainer();
                //    // Fazer um monte de coisa
                //}
                //catch
                //{
                //}
                //finally
                //{
                //    v.Dispose();
                //}

                #endregion
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ViewState["S"] = "Test";
            ViewState["S1"] = "Test2";
            ViewState["S3"] = "Test3";
            ViewState["S4"] = "Test4";

            //ObjectCache memCache = new MemoryCache("beerCache");

            var favoriteList = new List<FavoriteBeer>();
            //if (Cache["favoriteBeers"] != null && memCache["favoriteBeers"] != null)
            //{
            //    favoriteList = Cache["favoriteBeers"] as List<FavoriteBeer>;
            //}
            //else
            //{
                using (TweetBeerContainer tbContainer = new TweetBeerContainer())
                {
                    favoriteList = tbContainer.FavoriteBeerSet.ToList();

                    foreach (FavoriteBeer fvBeer in favoriteList)
                    {
                        this.lbFavorites.Items.Add(new ListItem(fvBeer.Beer.Name, fvBeer.Beer.Id.ToString()));
                    }
                }
                //Cache["favoriteBeers"] = favoriteList;
                //memCache.Add("favoriteBeers", favoriteList, DateTime.Now.AddMonths(1));
            //}
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Exercício: Preencher DropDownList do controle
            // com as cervejas que estiverem no banco de dados TweetBeer!
            // Lembrem-se: cada item terá um value (Id) e um text (Name)
            // Lembrem-se 2: este carregamento deve ser executado apenas uma vez!

            if (!IsPostBack)
            {
                using (TweetBeerContainer dbContainer = new TweetBeerContainer())
                {
                    var listItems = (from b in dbContainer.Beer.ToList()
                                 select new ListItem(b.Name, b.Id.ToString())).ToArray();

                    foreach (var li in listItems)
                    {
                        if (this.ddlBeerList.Items
                            .Cast<ListItem>()
                            .Count(x => x.Text == li.Text) == 0)
                        {
                            this.ddlBeerList.Items.Add(li);
                        }
                    }
                }
            }
        }
        protected void btnAddToFavorites_Click(object sender, EventArgs e)
        {
            string v = ViewState["S"] as string;

            ListItem selectedBeer = this.ucBeerList.SelectedBeer;
            if (selectedBeer != null)
            {
                this.lbFavorites.Items.Add(new ListItem(selectedBeer.Text));

                #region Adding in Database

                using (TweetBeerContainer tweetBeerContainer = new TweetBeerContainer())
                {
                    long id = Int64.Parse(selectedBeer.Value);
                    Beer currentBeer = tweetBeerContainer.Beer
                        .Single(b => b.Id == id);

                    FavoriteBeer favoriteBeer = new FavoriteBeer();
                    favoriteBeer.Beer = currentBeer;
                    favoriteBeer.CreationDate = DateTime.Now;
                    favoriteBeer.User = Session["userName"] as string;

                    tweetBeerContainer.AddToFavoriteBeerSet(favoriteBeer);
                    tweetBeerContainer.SaveChanges();

                    // Twitter
                    currentBeer.Tweet(String.Format("{0} added to favorites by {1}",
                        currentBeer.Name, favoriteBeer.User
                    ));
                }

                #endregion
            }
            // Cleaning up Beer List
            this.ucBeerList.RemoveSelectedBeer();
        }