Ejemplo n.º 1
0
 public bool CreateImageForDish(ImageForDish instance)
 {
     if (instance.ImageId == 0)
     {
         Db.ImageForDishs.InsertOnSubmit(instance);
         Db.ImageForDishs.Context.SubmitChanges();
         return(true);
     }
     return(false);
 }
        protected String GetImageUrl(int DishId)
        {
            ImageForDish re = Repository.ImageForDishs.Where(p => p.DishId == DishId).FirstOrDefault();

            if (re != null)
            {
                return(Repository.ImageForDishs.Where(p => p.DishId == DishId).FirstOrDefault().Image);
            }
            else
            {
                return("~/PictureDish/null_image.png");
            }
        }
Ejemplo n.º 3
0
        public bool RemoveImageForDish(int ImageId)
        {
            ImageForDish instance = Db.ImageForDishs.FirstOrDefault(p => p.ImageId == ImageId);

            if (instance != null)
            {
                Db.ImageForDishs.DeleteOnSubmit(instance);
                Db.ImageForDishs.Context.SubmitChanges();
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public bool UpdateImageForDish(ImageForDish instance)
        {
            ImageForDish cache = Db.ImageForDishs.FirstOrDefault(p => p.ImageId == instance.ImageId);

            if (instance.ImageId != 0)
            {
                cache.DishId = instance.DishId;
                cache.Image  = instance.Image;
                Db.ImageForDishs.Context.SubmitChanges();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        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);
        }