コード例 #1
0
ファイル: UyeController.cs プロジェクト: zulalnb/blog-site
        public ActionResult Create(Uye uye, HttpPostedFileBase Foto)
        {
            if (ModelState.IsValid)
            {
                if (Foto != null)
                {
                    WebImage img      = new WebImage(Foto.InputStream);
                    FileInfo fotoinfo = new FileInfo(Foto.FileName);

                    string newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension;
                    img.Resize(800, 350);
                    img.Save("~/Uploads/UyeFoto/" + newfoto);
                    uye.Foto    = "/Uploads/UyeFoto/" + newfoto;
                    uye.YetkiId = 2;
                    db.Uyes.Add(uye);
                    db.SaveChanges();
                    Session["uyeId"]        = uye.UyeId;
                    Session["kullaniciadi"] = uye.KullaniciAdi;
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("Fotoğraf", "Fotoğraf Seçiniz");
                }
            }
            return(View(uye));
        }
コード例 #2
0
        public ActionResult Create(Makale makale, string etiketler, HttpPostedFileBase Foto)
        {
            if (ModelState.IsValid)
            {
                if (Foto != null)
                {
                    WebImage img      = new System.Web.Helpers.WebImage(Foto.InputStream);
                    FileInfo fotoinfo = new FileInfo(Foto.FileName);

                    string newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension;
                    img.Resize(800, 350);
                    img.Save("~/Uploads/MakaleFoto/" + newfoto);
                    makale.Foto = "/Uploads/MakaleFoto/" + newfoto;
                }
                if (etiketler != null)
                {
                    string[] etiketdizi = etiketler.Split(',');
                    foreach (var i in etiketdizi)
                    {
                        var yenietiket = new Etiket {
                            EtiketAdi = i
                        };
                        db.Etikets.Add(yenietiket);
                        makale.Etikets.Add(yenietiket);
                    }
                }
                makale.UyeId  = Convert.ToInt32(Session["uyeid"]);
                makale.Okunma = 1;
                db.Makales.Add(makale);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(makale));
        }
コード例 #3
0
 public ActionResult Create(Mesaj mesaj)
 {
     if (ModelState.IsValid)
     {
         db.Mesajs.Add(mesaj);
         db.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     return(View(mesaj));
 }
コード例 #4
0
        public ActionResult Create([Bind(Include = "KategoriId,KategoriAdi")] Kategori kategori)
        {
            if (ModelState.IsValid)
            {
                db.Kategoris.Add(kategori);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(kategori));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "UyeId,KullaniciAdi,Email,Sifre,AdSoyad,YetkiId")] Uye uye)
        {
            if (ModelState.IsValid)
            {
                db.Uye.Add(uye);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.YetkiId = new SelectList(db.Yetki, "YetkiId", "Yetki1", uye.YetkiId);
            return(View(uye));
        }
コード例 #6
0
        public ActionResult Create([Bind(Include = "YorumId,Icerik,UyeId,MakaleId,Tarih")] Yorum yorum)
        {
            if (ModelState.IsValid)
            {
                db.Yorums.Add(yorum);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UyeId = new SelectList(db.Uyes, "UyeId", "KullaniciAdi", yorum.UyeId);
            return(View(yorum));
        }
コード例 #7
0
ファイル: HomeController.cs プロジェクト: ygtalp/Mvc-Blog
        public JsonResult YorumYap(string yorum, int Makaleid)
        {
            var uyeid = Session["uyeid"];

            if (yorum != null)
            {
                db.Yorums.Add(new Yorum {
                    UyeId = Convert.ToInt32(uyeid), MakaleId = Makaleid, Icerik = yorum, Tarih = DateTime.Now
                });
                db.SaveChanges();
            }
            return(Json(false, JsonRequestBehavior.AllowGet));
        }
コード例 #8
0
        public JsonResult YorumYap(string yorum, int MakaleID)
        {
            var uyeid = Session["uyeid"];

            if (yorum == null)
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            db.Yorums.Add(new Yorum {
                UyeID = Convert.ToInt32(uyeid), MakaleID = MakaleID, Icerik = yorum, Tarih = "12/12/2017"
            });
            db.SaveChanges();
            return(Json(false, JsonRequestBehavior.AllowGet));
        }
コード例 #9
0
        public ActionResult Create(Uye uye, string Sifre, HttpPostedFileBase Foto)
        {
            var md5pass = Sifre;

            var login = db.Uyes.Where(u => u.KullaniciAdi == uye.KullaniciAdi).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (login == null)
                {
                    if (Foto != null)
                    {
                        WebImage img      = new WebImage(Foto.InputStream);
                        FileInfo fotoinfo = new FileInfo(Foto.FileName);

                        string newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension;
                        img.Resize(150, 150);
                        img.Save("~/Uploads/UyeFoto/" + newfoto);
                        uye.Foto    = "/Uploads/UyeFoto/" + newfoto;
                        uye.YetkiID = 2;
                        uye.Sifre   = Crypto.Hash(md5pass, "MD5");
                        db.Uyes.Add(uye);
                        db.SaveChanges();
                        Session["uyeId"]        = uye.UyeID;
                        Session["Kullaniciadi"] = uye.KullaniciAdi;
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ViewBag.Uyari = "Fotoğraf Seçiniz..!!!";

                        //uye.Foto = "/Uploads/UyeFoto/varsayilan.png";
                        //ModelState.AddModelError("Fotoğraf", "Fotoğraf Seçiniz..");

                        //WebImage img = new WebImage(uye.Foto);
                        //FileInfo fotoinfo = new FileInfo(uye.Foto);

                        //string newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension;
                        //img.Resize(150, 150);
                        //img.Save("~/Uploads/UyeFoto/varsayilan.png" + newfoto);
                    }
                }
                else
                {
                    ViewBag.Uyari = "Bu Kullanıcı Adı Kullanılmaktadır!!!";
                }
            }
            return(View(uye));
        }
コード例 #10
0
        public ActionResult Edit(Uye uye, string Sifre, int id, HttpPostedFileBase Foto)
        {
            mvcblogDB db = new mvcblogDB();

            if (ModelState.IsValid)
            {
                var uyes = db.Uyes.Where(u => u.UyeId == id).SingleOrDefault();
                if (Foto != null)
                {
                    if (System.IO.File.Exists(Server.MapPath(uye.Foto)))
                    {
                        System.IO.File.Delete(Server.MapPath(uyes.Foto));
                    }
                    WebImage img      = new WebImage(Foto.InputStream);
                    FileInfo fotoinfo = new FileInfo(Foto.FileName);

                    string newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension;
                    img.Resize(150, 150);
                    img.Save("~/Uploads/UyeFoto/" + newfoto);
                    uyes.Foto = "/Uploads/UyeFoto/" + newfoto;
                }
                uyes.AdSoyad      = uye.AdSoyad;
                uyes.KullaniciAdi = uye.KullaniciAdi;
                uyes.Email        = uye.Email;
                db.SaveChanges();
                Session["kullaniciadi"] = uye.KullaniciAdi;
                return(RedirectToAction("Index", "Home", new { id = uyes.UyeId }));
            }
            return(View());
        }
コード例 #11
0
        public ActionResult Create(Makale makale, string etiketler, HttpPostedFileBase foto)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (foto != null)
                    {
                        WebImage img      = new WebImage(foto.InputStream);
                        FileInfo fotoInfo = new FileInfo(foto.FileName);
                        string   newFoto  = Guid.NewGuid().ToString() + fotoInfo.Extension;

                        img.Resize(800, 3500);
                        img.Save("~/Uploads/MakaleFoto/" + newFoto);
                        makale.Foto = "~/Uploads/MakaleFoto/" + newFoto;
                    }

                    if (etiketler != null)
                    {
                        string[] etiketdizi = etiketler.Split(',');
                        foreach (var item in etiketdizi)
                        {
                            var yenietiket = new Etiket {
                                EtiketAdi = item
                            };
                            db.Etikets.Add(yenietiket);
                            makale.Etikets.Add(yenietiket);
                        }
                    }
                    db.Makales.Add(makale);
                    db.SaveChanges();

                    // TODO: Add insert logic here

                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(View(makale));
            }
            return(View(makale));
        }
コード例 #12
0
 public ActionResult Create(Makale makale, string etiketler, HttpPostedFileBase Fotograf)
 {
     try
     {
         if (Fotograf != null)
         {
             WebImage img          = new WebImage(Fotograf.InputStream);
             FileInfo fotografinfo = new FileInfo(Fotograf.FileName);
             string   newfotograf  = Guid.NewGuid().ToString() + fotografinfo.Extension;
             img.Resize(600, 300);
             img.Save("~/Uploads/MakaleFotograf/" + newfotograf);
             makale.Fotograf = "/Uploads/MakaleFotograf/" + newfotograf;
         }
         if (etiketler != null)
         {
             string[] etiketdizi = etiketler.Split(',');
             foreach (var i in etiketdizi)
             {
                 var yenietiket = new Etiket {
                     EtiketAdi = i
                 };
                 db.Etikets.Add(yenietiket);
                 makale.Etikets.Add(yenietiket);
             }
         }
         makale.UyeId  = Convert.ToInt32(Session["uyeid"]);
         makale.Okunma = 1;
         db.Makales.Add(makale);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(makale));
     }
 }