コード例 #1
0
        public async Task <IActionResult> Edit(Yayin yayin, IFormFile image)
        {
            if (image != null)
            {
                if (System.IO.File.Exists(_env.WebRootPath + yayin.ImageUrl))
                {
                    System.IO.File.Delete(_env.WebRootPath + yayin.ImageUrl);
                }
                if (image == null || image.Length == 0)
                {
                    return(Content("not image selected"));
                }

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/image/Yayincilar", image.FileName);

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await image.CopyToAsync(stream);
                }

                yayin.ImageUrl = "/image/Yayincilar/" + image.FileName;
            }

            _yayinService.Update(yayin);
            return(RedirectToAction("Index"));
        }
コード例 #2
0
ファイル: AdminController.cs プロジェクト: SerhatKOLCU/pesar
 public ActionResult YayinDeleteConfirmed(int id)
 {
     if (Session["UserSession"] == null)
     {
         return(RedirectToAction("PermissionDenied", "Admin"));
     }
     else
     {
         Yayin yayin = db.Yayin.Find(id);
         db.Yayin.Remove(yayin);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
コード例 #3
0
        // GET: Yayinlar/Details/5
        public ActionResult YayinDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Yayin yayin = db.Yayin.Find(id);

            if (yayin == null)
            {
                return(HttpNotFound());
            }
            return(View(yayin));
        }
コード例 #4
0
ファイル: AdminController.cs プロジェクト: SerhatKOLCU/pesar
        public ActionResult YayinEdit([Bind(Include = "Yayin_ID,YayinTip_ID,Yayin_Baslik,Yayin_Foto,Yayin_Icerik,Yayin_Ozet,YayinEtiket,Yayin_Yazar,Yayin_Dosya,Yayin_Tarih")] Yayin yayin, HttpPostedFileBase YayinFoto, HttpPostedFileBase YayinDosya)
        {
            if (Session["UserSession"] == null)
            {
                return(RedirectToAction("PermissionDenied", "Admin"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    if (YayinFoto.FileName != null && YayinDosya.FileName != null)
                    {
                        FileInfo fotoBilgisi     = new FileInfo(YayinFoto.FileName);
                        string   yeniFotoBilgisi = Guid.NewGuid().ToString("n") + fotoBilgisi.Extension;



                        FileInfo dosyaBilgisi     = new FileInfo(YayinDosya.FileName);
                        string   yeniDosyaBilgisi = Guid.NewGuid().ToString("n") + dosyaBilgisi.Extension;

                        YayinFoto.SaveAs(Server.MapPath("~/Content/Upload/Yayin/Foto/" + yeniFotoBilgisi));
                        YayinDosya.SaveAs(Server.MapPath("~/Content/Upload/Yayin/Dosya/" + yeniDosyaBilgisi));

                        yayin.Yayin_Foto  = yeniFotoBilgisi;
                        yayin.Yayin_Dosya = yeniDosyaBilgisi;


                        db.Entry(yayin).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Lütfen yayin için düzgün veri girin.");
                        return(View(yayin));
                    }
                    //db.Entry(yayin).State = EntityState.Modified;
                    //db.SaveChanges();
                    //return RedirectToAction("Index");
                }
                ViewBag.YayinTip_ID = new SelectList(db.YayinTip, "YayinTip_ID", "YayinTip_Adi", yayin.YayinTip_ID);
                return(View(yayin));
            }
        }
コード例 #5
0
        public async Task <IActionResult> Create(IFormFile image, Yayin yayin)
        {
            if (image == null || image.Length == 0)
            {
                return(Content("not image selected"));
            }

            var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/image/Yayincilar", image.FileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await image.CopyToAsync(stream);
            }

            yayin.ImageUrl = "/image/Yayincilar/" + image.FileName;
            _yayinService.Add(yayin);

            return(RedirectToAction("Index"));
        }
コード例 #6
0
ファイル: AdminController.cs プロジェクト: SerhatKOLCU/pesar
 // GET: Yayins/Details/5
 public ActionResult YayinDetails(int?id)
 {
     if (Session["UserSession"] == null)
     {
         return(RedirectToAction("PermissionDenied", "Admin"));
     }
     else
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         Yayin yayin = db.Yayin.Find(id);
         if (yayin == null)
         {
             return(HttpNotFound());
         }
         return(View(yayin));
     }
 }
コード例 #7
0
ファイル: AdminController.cs プロジェクト: SerhatKOLCU/pesar
 // GET: Yayins/Edit/5
 public ActionResult YayinEdit(int?id)
 {
     if (Session["UserSession"] == null)
     {
         return(RedirectToAction("PermissionDenied", "Admin"));
     }
     else
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         Yayin yayin = db.Yayin.Find(id);
         if (yayin == null)
         {
             return(HttpNotFound());
         }
         ViewBag.YayinTip_ID = new SelectList(db.YayinTip, "YayinTip_ID", "YayinTip_Adi", yayin.YayinTip_ID);
         return(View(yayin));
     }
 }
コード例 #8
0
 public void Update(Yayin yayin)
 {
     _yayinDal.Update(yayin);
 }
コード例 #9
0
 public void Add(Yayin yayin)
 {
     _yayinDal.Add(yayin);
 }