예제 #1
0
        public ActionResult Edit(int id, HttpPostedFileBase resim, TBL_HAZIRLADIKLARIM hazir)
        {
            try
            {
                var hazirs = db.TBL_HAZIRLADIKLARIM.Where(p => p.ID == id).SingleOrDefault();
                if (resim != null)
                {
                    if (System.IO.File.Exists(Server.MapPath(hazirs.FOTOGRAF)))
                    {
                        System.IO.File.Delete(Server.MapPath(hazirs.FOTOGRAF));
                    }
                    WebImage img      = new WebImage(resim.InputStream);
                    FileInfo fotoInfo = new FileInfo(resim.FileName);

                    string newFoto = Guid.NewGuid().ToString() + fotoInfo.Extension;
                    img.Resize(350, 200);
                    img.Save("~/Uploads/HazirladiklarimResim/" + newFoto);
                    hazirs.FOTOGRAF = "/Uploads/HazirladiklarimResim/" + newFoto;
                    hazirs.AD       = hazir.AD;
                    hazirs.TANITIM  = hazir.TANITIM;
                    hazirs.ACIKLAMA = hazir.ACIKLAMA;
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #2
0
        public ActionResult Create(TBL_HAZIRLADIKLARIM tbl, HttpPostedFileBase resim)
        {
            if (ModelState.IsValid)
            {
                if (resim != null)
                {
                    WebImage img      = new WebImage(resim.InputStream);
                    FileInfo fotoInfo = new FileInfo(resim.FileName);

                    string newFoto = Guid.NewGuid().ToString() + fotoInfo.Extension;
                    img.Resize(350, 200);
                    img.Save("~/Uploads/HazirladiklarimResim/" + newFoto);
                    tbl.FOTOGRAF = "/Uploads/HazirladiklarimResim/" + newFoto;
                }
                db.TBL_HAZIRLADIKLARIM.Add(tbl);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(tbl));
        }