public ActionResult TarihEkle(String dersAcmaBaslangic, String dersAcmaBitis, String dersSecmeBaslangic, String dersSecmeBitis) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); ObsDbContext ctx = new ObsDbContext(); DersTarihlers dt = new DersTarihlers(); dt.Id = (DateTime.Now.Ticks % 1200).ToString(); dt.Yil = DateTime.Now.Year.ToString(); dt.dersAcmaBaslangic = DateTime.ParseExact(dersAcmaBaslangic, "dd/MM/yyyy", CultureInfo.InvariantCulture); dt.dersAcmaBitis = DateTime.ParseExact(dersAcmaBitis, "dd/MM/yyyy", CultureInfo.InvariantCulture); dt.dersSecmeBaslangic = DateTime.ParseExact(dersSecmeBaslangic, "dd/MM/yyyy", CultureInfo.InvariantCulture); dt.dersSecmeBitis = DateTime.ParseExact(dersSecmeBitis, "dd/MM/yyyy", CultureInfo.InvariantCulture); ctx.DersTarihlers.Add(dt); ctx.SaveChanges(); ctx.Dispose(); return(RedirectToAction("TarihleriListele")); }
public ActionResult DersEklemeTalebi() { bool DersEklemeHaftasi = false; ObsDbContext ctx = new ObsDbContext(); DersTarihlers dt = null; try { dt = ctx.DersTarihlers.ToList().ElementAt(0); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("derstarihler tablosu boş"); } if (dt == null) //herhangi bir derstarih kaydı olmadığından. { return(RedirectToAction("Index")); } DersEklemeHaftasi = (DateTime.Now > dt.dersAcmaBaslangic && DateTime.Now < dt.dersAcmaBitis); List <Dersler> dersler = null; // if (DersEklemeHaftasi) { dersler = ctx.Dersler.ToList(); ctx.Dispose(); return(View(dersler)); } else { // ctx.Dispose(); return(RedirectToAction("DersEklemeTaleplerimiListele")); } }