public ActionResult Create(SemSchoolYear semschoolyear)
        {
            var db = DAL.DbContext.Create();

            if (ModelState.IsValid)
            {
                if (IsValidDate(semschoolyear))
                {
                    db.SemSchoolYears.Insert(semschoolyear);
                    return RedirectToAction("Index");

                }
            }

            ViewBag.SchoolYearID = new SelectList(db.SchoolYears.All(), "Id", "SchoolYearRange", semschoolyear.SchoolYearID);
            ViewBag.SemesterID = new SelectList(db.Semesters.All(), "Id", "SemesterName", semschoolyear.SemesterID);
            return View(semschoolyear);
        }
Esempio n. 2
0
        private bool ValidateEnrollmentDate(Student student, SemSchoolYear semschoolyear)
        {
            var db = DAL.DbContext.Create();

            DateTime? a = student.EnrollmentDate;
            DateTime? b = semschoolyear.EnrollmentDateStart;
            DateTime? c = semschoolyear.SemesterDateEnd;

            if (a >= b && a <= c)
            {
                return true;
            }
            return false;
        }
        private bool IsValidDate(SemSchoolYear semschoolyear)
        {
            var db = DAL.DbContext.Create();

            var date1 = Convert.ToDateTime(semschoolyear.EnrollmentDateStart);
            var date2 = Convert.ToDateTime(semschoolyear.SemesterDateEnd);

            if (date1 >= date2)
            {
                ModelState.AddModelError("", "Unable to save changes. Semester Date End needs to be greater than Enrollment Date Start.");
                return false;
            }
            return true;
        }
        public ActionResult EditPost(SemSchoolYear semschoolyear)
        {
            var db = DAL.DbContext.Create();

            if (ModelState.IsValid)
            {
                var date1 = Convert.ToDateTime(semschoolyear.EnrollmentDateStart);
                var date2 = Convert.ToDateTime(semschoolyear.SemesterDateEnd);

                if (date1 >= date2)
                {
                    ModelState.AddModelError("", "Unable to save changes. Semester Date End needs to be greater than Enrollment Date Start.");

                }

                db.SemSchoolYears.Update(semschoolyear.Id, semschoolyear);
                return RedirectToAction("Index");

            }
            ViewBag.SchoolYearID = new SelectList(db.SchoolYears.All(), "Id", "SchoolYearRange", semschoolyear.SchoolYearID);
            ViewBag.SemesterID = new SelectList(db.Semesters.All(), "Id", "SemesterName", semschoolyear.SemesterID);
            return View(semschoolyear);
        }