public ActionResult Create([Bind(Include = "id,code,title,hours,class_length,have_final_exam,exam_length,program_id," +
                                                   "is_deleted,created_by,class_weekday,class_start_time,room_id,faculty_id,program_id")] course course)
        {
            if (ModelState.IsValid)
            {
                course.created_on = DateTime.Now;
                db.courses.Add(course);

                course_exam tempCE = new course_exam();
                tempCE.course_id             = course.id;
                tempCE.created_by            = course.created_by;
                tempCE.created_on            = course.created_on;
                tempCE.exam_length           = course.exam_length;
                tempCE.have_final_exam       = course.have_final_exam;
                tempCE.final_exam_note       = course.final_exam_note;
                tempCE.is_deleted            = false;
                tempCE.required_room_type_id = db.rooms.Find(course.room_id).room_type_id;
                db.course_exam.Add(tempCE);

                section tempS = new section();
                tempS.program_id       = course.program_id;
                tempS.course_id        = course.id;
                tempS.section_number   = 1;
                tempS.faculty_id       = course.faculty_id;
                tempS.class_weekday    = course.class_weekday;
                tempS.class_start_time = course.class_start_time;
                tempS.room_id          = course.room_id;
                tempS.student_enrolled = 30;
                tempS.is_deleted       = false;
                tempS.created_by       = course.created_by;
                tempS.created_on       = course.created_on;
                db.sections.Add(tempS);

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.required_room1_type_id = new SelectList(db.room_type, "id", "type", course.required_room1_type_id);
            ViewBag.required_room2_type_id = new SelectList(db.room_type, "id", "type", course.required_room2_type_id);

            ViewBag.required_room_type_id = new SelectList(db.room_type.Where(c => c.is_deleted == false), "id", "type");
            ViewBag.course_id             = new SelectList(db.courses.Where(p => !(db.course_exam.Any(p2 => p2.course_id == p.id)) &&
                                                                            p.is_deleted == false).OrderBy(o => o.code), "id", "courseDropdown");

            //ViewBag.course_id = new SelectList(db.courses.Where(p => p.is_deleted == false).OrderBy(o => o.code), "id", "courseDropdown");
            ViewBag.faculty_id = new SelectList(db.faculties.Where(c => c.is_deleted == false).OrderBy(o => o.first_name), "id", "fullName", 10015);
            ViewBag.program_id = new SelectList(db.programs.Where(c => c.is_deleted == false), "id", "title");
            ViewBag.room_id    = new SelectList(db.rooms.Where(p => p.is_deleted == false).OrderBy(o => o.name), "id", "name", 8);

            var weekDays = Enum.GetValues(typeof(DayOfWeek)).Cast <DayOfWeek>()
                           .Select(dow => new { Value = (int)dow - 1, Text = dow.ToString() })
                           .ToList();

            ViewBag.class_weekday = new SelectList(weekDays, "Value", "Text", 0);



            return(View(course));
        }
Beispiel #2
0
        // GET: CourseExam/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            course_exam course_exam = db.course_exam.Find(id);

            if (course_exam == null)
            {
                return(HttpNotFound());
            }
            return(View(course_exam));
        }
Beispiel #3
0
        // GET: CourseExam/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            course_exam course_exam = db.course_exam.Find(id);

            if (course_exam == null)
            {
                return(HttpNotFound());
            }
            ViewBag.required_room_type_id = new SelectList(db.room_type.Where(c => c.is_deleted == false), "id", "type", course_exam.required_room_type_id);
            ViewBag.course_id             = new SelectList(db.courses.Where(c => c.is_deleted == false || c.id == course_exam.course_id).OrderBy(o => o.code),
                                                           "id", "courseDropdown", course_exam.course_id);
            return(View(course_exam));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "id,course_id,have_final_exam,exam_length,required_room_type_id,final_exam_note,is_deleted,created_by,created_on,modified_by,modified_on")] course_exam course_exam)
        {
            if (ModelState.IsValid)
            {
                course_exam.created_on = DateTime.Now;
                db.course_exam.Add(course_exam);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.required_room_type_id = new SelectList(db.room_type.Where(r => r.is_deleted == false),
                                                           "id", "type", course_exam.required_room_type_id);
            ViewBag.course_id = new SelectList(db.courses.Where(p => !(db.course_exam.Any(p2 => p2.course_id == p.id)) &&
                                                                p.is_deleted == false).OrderBy(o => o.code),
                                               "id", "courseDropdown", course_exam.course_id);
            return(View(course_exam));
        }
Beispiel #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            course_exam course_exam = db.course_exam.Find(id);

            //course_exam.is_deleted = true;

            //// set all related course to deleted = true
            //var tempC = db.courses.Where(e => e.id == course_exam.course_id);
            //if (tempC.ToList().Count > 0)
            //{
            //    foreach (var item in tempC)
            //    {
            //        item.is_deleted = true;
            //    }
            //}

            //// set all related sections deleted = true
            //var tempS = db.sections.Where(e => e.course_id == course_exam.course_id);
            //if (tempS.ToList().Count > 0)
            //{
            //    foreach (var item in tempS)
            //    {
            //        item.is_deleted = true;
            //    }
            //}

            //course_exam.modified_on = DateTime.Now;

            foreach (var item in db.sections.Where(s => s.course_id == course_exam.course_id))
            {
                db.sections.Remove(item);
            }

            foreach (var c in db.courses.Where(c => c.id == course_exam.course_id))
            {
                db.courses.Remove(c);
            }

            db.course_exam.Remove(course_exam);

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #6
0
        public ActionResult Edit([Bind(Include = "id,course_id,have_final_exam,exam_length,required_room_type_id,final_exam_note,is_deleted,created_by,created_on,modified_by,modified_on")] course_exam course_exam)
        {
            if (ModelState.IsValid)
            {
                db.Entry(course_exam).State = EntityState.Modified;

                if (course_exam.is_deleted == true)
                {
                    // set all related course to deleted = true
                    var tempC = db.courses.Where(e => e.id == course_exam.course_id);
                    if (tempC.ToList().Count > 0)
                    {
                        foreach (var item in tempC)
                        {
                            item.is_deleted = true;
                        }
                    }

                    // set all related sections deleted = true
                    var tempS = db.sections.Where(e => e.course_id == course_exam.course_id);
                    if (tempS.ToList().Count > 0)
                    {
                        foreach (var item in tempS)
                        {
                            item.is_deleted = true;
                        }
                    }
                }
                else
                {
                    // set all related course to deleted = false
                    var tempC = db.courses.Where(e => e.id == course_exam.course_id);
                    if (tempC.ToList().Count > 0)
                    {
                        foreach (var item in tempC)
                        {
                            item.is_deleted = false;
                        }
                    }

                    // set all related sections deleted = false
                    var tempS = db.sections.Where(e => e.course_id == course_exam.course_id);
                    if (tempS.ToList().Count > 0)
                    {
                        foreach (var item in tempS)
                        {
                            item.is_deleted = false;
                        }
                    }
                }



                course_exam.modified_on = DateTime.Now;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.required_room_type_id = new SelectList(db.room_type.Where(c => c.is_deleted == false), "id", "type", course_exam.required_room_type_id);
            ViewBag.course_id             = new SelectList(db.courses.Where(c => c.is_deleted == false || c.id == course_exam.course_id).OrderBy(o => o.code), "id", "courseDropdown", course_exam.course_id);
            return(View(course_exam));
        }
        public ActionResult Edit([Bind(Include = "id,code,title,hours,class_length,have_final_exam,exam_length,program_id," +
                                                 "is_deleted,created_by,class_weekday,class_start_time,room_id,faculty_id,program_id")] course course)
        {
            if (ModelState.IsValid)
            {
                db.Entry(course).State = EntityState.Modified;

                course.modified_on = DateTime.Now;

                course_exam tempCEX = db.course_exam.Where(w => w.course_id == course.id).First();
                tempCEX.exam_length     = course.exam_length;
                tempCEX.final_exam_note = course.final_exam_note;
                tempCEX.modified_on     = DateTime.Now;


                section tempS = db.sections.Where(w => w.course_id == course.id).First();
                tempS.program_id       = course.program_id;
                tempS.faculty_id       = course.faculty_id;
                tempS.class_weekday    = course.class_weekday;
                tempS.class_start_time = course.class_start_time;
                tempS.room_id          = course.room_id;
                tempS.modified_on      = DateTime.Now;


                if (course.is_deleted == true)
                {
                    // set this course-exam is_deleted = true
                    var tempCE = db.course_exam.Where(e => e.course_id == course.id);
                    if (tempCE.ToList().Count > 0)
                    {
                        foreach (var item in tempCE)
                        {
                            item.is_deleted = true;
                        }
                    }

                    // set this course - section is_deleted = true
                    var tempCS = db.sections.Where(e => e.course_id == course.id);
                    if (tempCS.ToList().Count > 0)
                    {
                        foreach (var item in tempCS)
                        {
                            item.is_deleted = true;
                        }
                    }
                }
                else
                {
                    // set this course-exam is_deleted = false
                    var tempCE = db.course_exam.Where(e => e.course_id == course.id);
                    if (tempCE.ToList().Count > 0)
                    {
                        foreach (var item in tempCE)
                        {
                            item.is_deleted = false;
                        }
                    }

                    // set this course - section is_deleted = false
                    var tempCS = db.sections.Where(e => e.course_id == course.id);
                    if (tempCS.ToList().Count > 0)
                    {
                        foreach (var item in tempCS)
                        {
                            item.is_deleted = false;
                        }
                    }
                }

                course.modified_on = DateTime.Now.AddHours(1);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            ViewBag.required_room_type_id = new SelectList(db.room_type.Where(c => c.is_deleted == false), "id", "type", db.course_exam.Where(w => w.course_id == course.id).First().required_room_type_id);
            ViewBag.course_id             = new SelectList(db.courses.Where(p => !(db.course_exam.Any(p2 => p2.course_id == p.id)) &&
                                                                            p.is_deleted == false).OrderBy(o => o.code), "id", "courseDropdown", course.id);

            ViewBag.faculty_id = new SelectList(db.faculties.Where(c => c.is_deleted == false).OrderBy(o => o.first_name), "id", "fullName", db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().faculty.id);
            ViewBag.program_id = new SelectList(db.programs.Where(c => c.is_deleted == false), "id", "title", db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().program.id);
            ViewBag.room_id    = new SelectList(db.rooms.Where(p => p.is_deleted == false).OrderBy(o => o.name), "id", "name", db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().room.id);

            var weekDays = Enum.GetValues(typeof(DayOfWeek)).Cast <DayOfWeek>()
                           .Select(dow => new { Value = (int)dow - 1, Text = dow.ToString() })
                           .ToList();

            ViewBag.class_weekday    = new SelectList(weekDays, "Value", "Text", db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().class_weekday);
            ViewBag.class_start_time = db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().class_start_time;
            ViewBag.exam_length      = db.course_exam.Where(w => w.course_id == course.id).First().exam_length;
            ViewBag.note             = db.course_exam.Where(w => w.course_id == course.id).First().final_exam_note;
            ViewBag.has_exam         = db.course_exam.Where(w => w.course_id == course.id).First().have_final_exam;

            return(View(course));
        }