protected void Button1_Click(object sender, EventArgs e) { string url; url = "/Page/Adminka/NewDishPage.aspx"; if (stage == 0) { url = "/Page/Adminka/NewDishPage.aspx?stage=1"; Dish tempd = new Dish(); tempd.Name = Name.Text; tempd.Base = Base.Text; tempd.KindId = Repository.Kinds.Where(p => p.Name == Kind.Text).FirstOrDefault().KindId; tempd.Difficult = Difficult.Text; Session["OpisDish"] = MText.Text; Session["DishAdd"] = tempd; } if (stage == 1) { url = "/Page/Adminka/NewDishPage.aspx?stage=2"; } if (stage == 2) { url = "/Page/Adminka/NewDishPage.aspx?stage=3"; if (Session["DishAdd"] != null) { Dish temp = (Dish)Session["DishAdd"]; temp.Price = Convert.ToDecimal(price.Text); Session["DishAdd"] = temp; } } if (stage == 3) { url = "/Page/Adminka/DishsAd.aspx"; List <Portion> pAdd = (List <Portion>)Session["ListPortion"]; int dishid1 = 0; if (Session["DishAdd"] != null && pAdd != null) { Dish temp = (Dish)Session["DishAdd"]; Repository.CreateDish(temp); int id = Repository.Dishs.Where(p => (p.Name == temp.Name && p.KindId == temp.KindId)).FirstOrDefault().DishId; foreach (Portion asd in pAdd) { Portion tempp = asd; tempp.DishId = id; dishid1 = id; Repository.CreatePortion(tempp); } Recept nrec = new Recept(); nrec.DishId = id; nrec.Specific = (String)Session["OpisDish"]; Repository.CreateRecept(nrec); } Session.Remove("ListPortion"); Session.Remove("DishAdd"); Session.Remove("OpisDish"); List <String> _extentions = new List <string> { ".jpg", ".bmp", ".png" }; if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName); string SaveLocation = Server.MapPath("/PictureDish") + "\\" + fn; string SaveInDb = "~/PictureDish/" + fn; ImageForDish img = new ImageForDish(); img.DishId = dishid1; img.Image = SaveInDb; try { File1.PostedFile.SaveAs(SaveLocation); Repository.CreateImageForDish(img); } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } else { Response.Write("Файл не загружен."); } } Response.Redirect(url); }