コード例 #1
0
        public ActionResult Duzenle(Makale k, HttpPostedFileBase MakaleURL, List <int> SecilenKonular)
        {
            if (SecilenKonular == null || SecilenKonular.Count == 0)
            {
                ModelState.AddModelError(string.Empty, "Bir konu seciniz.");
            }

            if (ModelState.IsValid)
            {
                MakaleRep er = new MakaleRep();

                Makale kitap = er.GetById(k.MakaleID);

                kitap.Baslik       = k.Baslik;
                kitap.Description  = k.Description;
                kitap.MakaleIcerik = k.MakaleIcerik;
                kitap.Keywords     = k.Keywords;
                kitap.KisaAciklama = k.KisaAciklama;
                KonuRep kr = new KonuRep();
                kitap.Konular = new List <Konu>();
                kitap.Konular.AddRange(kr.GetAll().Where(x => SecilenKonular.Any(a => a == x.KonuID)).ToList());
                kitap.Title = k.Title;
                er.Update(kitap);
                return(RedirectToAction("Index"));
            }
            return(View());
        }
コード例 #2
0
ファイル: KonuController.cs プロジェクト: duyguogunc/egitim5
        public ActionResult Index()
        {
            KonuRep kr         = new KonuRep();
            var     konular    = kr.GetAll();
            var     ustKonular = konular.Where(x => x.UstKonuID == null).ToList();

            ustKonular.ForEach(x => x.AltKonular = konular.Where(a => a.UstKonuID == x.KonuID).ToList());
            return(View(ustKonular));
        }
コード例 #3
0
        public ActionResult KonuSelect(IEnumerable <int> secilenler = null)
        {
            KonuRep kr = new KonuRep();

            return(View(kr.GetAll().Select(x => new KonuViewModel()
            {
                KonuBaslik = x.KonuBaslik,
                KonuID = x.KonuID,
                SeciliMi = secilenler == null ? false :secilenler.Any(a => a == x.KonuID)
            }).ToList()));
        }
コード例 #4
0
ファイル: KonuController.cs プロジェクト: duyguogunc/egitim5
        public ActionResult KonuEkle()
        {
            KonuRep     kr    = new KonuRep();
            List <Konu> liste = kr.GetAll();

            liste.Insert(0, new Konu {
                KonuID = 0, KonuBaslik = "Seçiniz"
            });
            ViewBag.Konular = liste;
            return(View());
        }
コード例 #5
0
ファイル: KonuController.cs プロジェクト: duyguogunc/egitim5
        public ActionResult KonuEkle(Konu konu)
        {
            KonuRep kr = new KonuRep();

            if (ModelState.IsValid)
            {
                if (konu.UstKonuID == 0)
                {
                    konu.UstKonuID = null;
                }
                kr.Insert(konu);
                ViewBag.EklendiMi = true;
            }
            return(View());
        }
コード例 #6
0
        public ActionResult MakaleEkle(Makale k, List <int> SecilenKonular, HttpPostedFileBase resim)
        {
            var klasor = Server.MapPath("/Content/Upload/");

            if (resim != null && resim.ContentLength != 0)
            {
                if (resim.ContentLength > 2 * 1024 * 1024)
                {
                    ModelState.AddModelError(null, "Resim boyutu max 2MB olabilir.");
                }
                else
                {
                    try
                    {
                        FileInfo fi       = new FileInfo(resim.FileName);
                        var      rastgele = Guid.NewGuid().ToString().Substring(0, 5);
                        var      dosyaAdi = fi.Name + rastgele + fi.Extension;

                        resim.SaveAs(klasor + dosyaAdi);
                        k.ResimURL = dosyaAdi;
                    }
                    catch { }
                }
            }
            if (SecilenKonular != null && SecilenKonular.Count == 0)
            {
                ModelState.AddModelError(string.Empty, "Bir konu seciniz.");
            }
            try
            {
                KonuRep kr = new KonuRep();
                k.Konular = kr.GetAll().Where(x => SecilenKonular.Any(a => a == x.KonuID)).ToList();
            }
            catch { }
            if (ModelState.IsValid)
            {
                new MakaleRep().Insert(k);
                ViewBag.EklendiMi = true;
            }
            return(View());
        }
コード例 #7
0
        public ActionResult Duzenle(EKitap k, HttpPostedFileBase EKitapURL, List <int> SecilenKonular)
        {
            string kaydedilecekIsim = "";
            var    klasor           = "/Content/EkitapUpload/";

            try
            {
                #region dosyayiKaydet
                if (k.EKitapURL != null)
                {
                    var kitapAdi = EKitapURL.FileName;
                    kaydedilecekIsim = kitapAdi;
                    if (System.IO.File.Exists(klasor + kitapAdi))
                    {
                        System.IO.FileInfo bilgi = new System.IO.FileInfo(klasor + kitapAdi);

                        var sadeceDosyaAdi = bilgi.Name.Replace(bilgi.Extension, "");

                        string[] bulunanlar = System.IO.Directory.GetFiles(klasor, sadeceDosyaAdi + ".*", System.IO.SearchOption.AllDirectories);

                        var kacTane = bulunanlar.Length;

                        kaydedilecekIsim = sadeceDosyaAdi + "-" + kacTane + "." + bilgi.Extension;
                    }

                    var path = Server.MapPath(klasor);
                    EKitapURL.SaveAs(path + kaydedilecekIsim);
                }
                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex);
                ModelState.AddModelError(string.Empty, ex.Message);
            }

            if (SecilenKonular == null || SecilenKonular.Count == 0)
            {
                ModelState.AddModelError(string.Empty, "Bir konu seciniz.");
            }

            if (ModelState.IsValid)
            {
                EkitapRep er    = new EkitapRep();
                EKitap    kitap = er.GetById(k.EKitapID);

                if (!string.IsNullOrEmpty(kaydedilecekIsim))
                {
                    try
                    {
                        if (System.IO.File.Exists(klasor + kitap.EKitapURL))
                        {
                            System.IO.File.Delete(klasor + kitap.EKitapURL);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Log(ex);
                    }
                    kitap.EKitapURL = kaydedilecekIsim;
                }

                kitap.Baslik       = k.Baslik;
                kitap.Description  = k.Description;
                kitap.EKitapIcerik = k.EKitapIcerik;
                kitap.Keywords     = k.Keywords;
                kitap.KisaAciklama = k.KisaAciklama;
                KonuRep kr = new KonuRep();
                kitap.Konular = kr.GetAll().Where(x => SecilenKonular.Any(a => a == x.KonuID)).ToList();
                kitap.Title   = k.Title;
                er.Update(kitap);
                return(RedirectToAction("Index"));
            }
            return(View());
        }