// GET: Admin/Delete/5
        public ActionResult DeleteCourseTime(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CourseTimetable courseTimetable = db.CourseTimetables.SingleOrDefault(ct => ct.CourseTimetableId == id);
            Courses         courses         = db.Courses.SingleOrDefault(c => c.CoursesID == courseTimetable.CoursesID);

            if (courseTimetable == null)
            {
                return(HttpNotFound());
            }
            TimetableVM timetable = new TimetableVM
            {
                //CoursesID = courses.CoursesID,
                CourseName        = courses.CourseName,
                CourseTimetableId = courseTimetable.CourseTimetableId,
                //Programme = courses.Programme,
                StartTime = courseTimetable.StartTime.ToString(),
                EndTime   = courseTimetable.EndTime.ToString(),
            };

            return(View(timetable));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CourseTimetable courseTimetable = db.CourseTimetables.SingleOrDefault(ct => ct.CourseTimetableId == id);

            db.CourseTimetables.Remove(courseTimetable);
            db.SaveChanges();
            return(RedirectToAction("AttendanceList"));
        }
 public ActionResult EditCourseTime([Bind(Include = "CourseTimetableId,StartTime,EndTime")] CourseTimetable courseTimetable)
 {
     if (ModelState.IsValid)
     {
         db.Entry(courseTimetable).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("AttendanceList"));
     }
     return(View(courseTimetable));
 }
Ejemplo n.º 4
0
 public ActionResult EditCourseTime([Bind(Include = "CourseTimetableId,StartTime,EndTime")] CourseTimetable courseTimetable)
 {
     if (ModelState.IsValid)
     {
         var getdata = db.CourseTimetables.SingleOrDefault(ct => ct.CourseTimetableId == courseTimetable.CourseTimetableId);
         getdata.StartTime = courseTimetable.StartTime;
         getdata.EndTime   = courseTimetable.EndTime;
         db.SaveChanges();
         return(RedirectToAction("SelectProgramme"));
     }
     return(View(courseTimetable));
 }
Ejemplo n.º 5
0
        public ActionResult CreateCourse(string selectedProgramme, string CreateOption, string SelectedCourseId, string CourseName, string StartTime, string EndTime)
        {
            var programme       = (Programme)Enum.Parse(typeof(Programme), selectedProgramme);
            var CheckCourseName = db.Courses.SingleOrDefault(c => c.CourseName == CourseName && c.Programme == programme);

            if (CreateOption == "Course")
            {
                if (CheckCourseName != null)
                {
                    string Error = "This Course Name Already Exist";
                    return(Json(new { Error, SaveCourse = false }, JsonRequestBehavior.AllowGet));
                }
                Courses getCourseName = new Courses
                {
                    Programme  = programme,
                    CourseName = CourseName
                };
                db.Courses.Add(getCourseName);
                db.SaveChanges();
                return(Json(new { SaveCourse = true }, JsonRequestBehavior.AllowGet));
            }
            else
            //if (CreateOption == "Time")
            {
                DateTime getStartTime  = Convert.ToDateTime(StartTime);
                DateTime getEndTime    = Convert.ToDateTime(EndTime);
                var      id            = Convert.ToInt32(SelectedCourseId);
                var      getCourseName = db.Courses.SingleOrDefault(c => c.CoursesID == id && c.Programme == programme);
                if (getStartTime >= getEndTime)
                {
                    string Error = "Start Time must small than End Time";
                    return(Json(new { Error, Savetime = false }, JsonRequestBehavior.AllowGet));
                }
                var CheckTime = db.CourseTimetables.SingleOrDefault(ct => ct.CoursesID == getCourseName.CoursesID && getCourseName.Programme == programme && ct.StartTime == getStartTime);
                if (CheckTime != null)
                {
                    string Error = "You Already Have A Time For This Time";
                    return(Json(new { Error, Savetime = false }, JsonRequestBehavior.AllowGet));
                }
                CourseTimetable timetable = new CourseTimetable
                {
                    CoursesID = getCourseName.CoursesID,
                    StartTime = getStartTime,
                    EndTime   = getEndTime
                };
                db.CourseTimetables.Add(timetable);
                db.SaveChanges();
                return(Json(new { Savetime = true }, JsonRequestBehavior.AllowGet));
            }
        }