protected void Button1_Click(object sender, EventArgs e) { string url; url = "/Page/Adminka/NewMenusPage.aspx"; if (stage == 0) { url = "/Page/Adminka/NewMenusPage.aspx?stage=1"; DbClassesBell.Menu tempd = new DbClassesBell.Menu(); tempd.Name = Name.Text; tempd.Text = MText.Text; Session["MenusAdd"] = tempd; } if (stage == 1) { url = "/Page/Adminka/NewMenusPage.aspx?stage=2"; MenuDish tempP = new MenuDish(); tempP.DishId = Repository.Dishs.Where(p => p.Name == Recept.Text).FirstOrDefault().DishId; tempP.RepastId = Repository.Repasts.Where(p => p.Name == Repast.Text).FirstOrDefault().RepastId; List <MenuDish> tempLP = new List <MenuDish>(); if (Session["ListMenuDish"] != null) { tempLP = (List <MenuDish>)Session["ListMenuDish"]; } tempLP.Add(tempP); Session["ListMenuDish"] = tempLP; } if (stage == 2) { url = "/Page/Adminka/NewMenusPage.aspx?stage=3"; if (Session["MenusAdd"] != null) { DbClassesBell.Menu temp = (DbClassesBell.Menu)Session["MenusAdd"]; temp.Price = Convert.ToDecimal(price.Text); Session["MenusAdd"] = temp; } } if (stage == 3) { url = "/Page/Adminka/MenusAd.aspx"; List <MenuDish> pAdd = (List <MenuDish>)Session["ListMenuDish"]; if (Session["MenusAdd"] != null && pAdd != null) { DbClassesBell.Menu temp = (DbClassesBell.Menu)Session["MenusAdd"]; Repository.CreateMenu(temp); int id = Repository.Menus.Where(p => p.Name == temp.Name).FirstOrDefault().MenuId; foreach (MenuDish asd in pAdd) { MenuDish tempp = asd; tempp.MenuId = id; Repository.CreateMenuDish(tempp); } } Session.Remove("ListMenuDish"); Session.Remove("MenusAdd"); } Response.Redirect(url); }