public ActionResult ClassSchedule(Department aDepartment)
        {
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "DepartmentName");
            List<Course> courses =
                (from c in db.Courses where c.Department.DepartmentId == aDepartment.DepartmentId select c).ToList();
            List<AllocateRoom> allocations = db.AllocateRooms.ToList();

            List<string> code = new List<string>();
            List<string> name = new List<string>();
            List<string> schdule = new List<string>();

            foreach (Course course in courses)
            {
                string message = "";
                foreach (AllocateRoom allocation in allocations)
                {
                    int flag = 0;
                    if (course.CourseId == allocation.CourseId)
                    {
                        if (flag == 0)
                        {
                            message += "R-No: ";
                            flag = 1;
                        }

                        Room aRoom = (from r in db.Rooms where r.RoomId == allocation.RoomId select r).SingleOrDefault();
                        Day day = (from d in db.Days where d.DayId == allocation.DayId select d).SingleOrDefault();

                        allocation.Room = aRoom;
                        allocation.Day = day;

                        message += aRoom.RoomNo + ", " + day.DayName + ", " + allocation.StartingTime + " - " +
                                   allocation.EndingTime + ";";
                    }
                }

                if (message == "") message += "Couse Yet not Scheduled";

                schdule.Add(message);
                code.Add(course.CourseCode);
                name.Add(course.CourseName);
            }

            ViewBag.CourseCode = code;
            ViewBag.CourseName = name;
            ViewBag.Schedules = schdule;

            return View();
        }
 private string ValidationForDepartment(Department department)
 {
     string message = "";
     if (department.DepartmentCode == "")
     {
         message += "Code not given";
     }
     if (department.DepartmentCode != "" && db.Departments.Count(d => d.DepartmentCode == department.DepartmentCode) != 0)
     {
         message += "Code already exists" + "\n";
     }
     if (department.DepartmentName == "")
     {
         message += "Name not given";
     }
     if (department.DepartmentName != "" && db.Departments.Count(d => d.DepartmentName == department.DepartmentName) != 0)
     {
         message += "Name already exists" + "\n";
     }
     return message;
 }
        public ActionResult Create(Department department)
        {
            department.DepartmentCode = department.DepartmentCode.ToUpper();
            department.DepartmentName = department.DepartmentName.ToUpper();

            // check validation
            string message = ValidationForDepartment(department);
            if (message != "")
            {
                ViewBag.Message = message;
                return View(department);
            }

            // save it to the database
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();

                return RedirectToAction("Index");
            }

            return View(department);
        }
Пример #4
0
        public ActionResult CourseAssign(Department aDepartment, Course aCourse, Teacher aTeacher)
        {
            string message = ValidationForCourseAssign(aDepartment, aCourse, aTeacher);
            if (message != "")
            {
                ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "DepartmentName");
                ViewBag.TeacherId = new SelectList("", "", "TeacherName");
                ViewBag.CourseId = new SelectList("", "", "CourseName");

                ViewBag.Message = message;
                return View();
            }

            aTeacher = db.Teachers.Find(aTeacher.TeacherId);
            aCourse = db.Courses.Find(aCourse.CourseId);

            // assiging teacher to this course
            aCourse.Teacher = aTeacher;

            // update remaining credit for teacher
            aTeacher.TeacherRemainingCredit -= aCourse.CourseCredit;

            //save data to database
            if (!ModelState.IsValid)
            {
                db.Entry(aCourse).State = EntityState.Modified;
                db.SaveChanges();

                db.Entry(aTeacher).State = EntityState.Modified;
                db.SaveChanges();

                return RedirectToAction("Index");
            }

            return View();
        }
Пример #5
0
        private string ValidationForCourseAssign(Department aDepartment, Course aCourse, Teacher aTeacher)
        {
            string message = "";

            if (aDepartment.DepartmentId == 0 || aCourse.CourseId == 0 || aTeacher.TeacherId == 0)
            {
                message += "Incomplete form submit, any field is not yet set ";
            }

            // is teacher and course is not from the same department

            aDepartment = db.Departments.Find(aDepartment.DepartmentId);
            aTeacher = db.Teachers.Find(aTeacher.TeacherId);
            aCourse = db.Courses.Find(aCourse.CourseId);

            if (aDepartment.DepartmentId != aTeacher.DepartmentId || aCourse.DepartmentId != aTeacher.DepartmentId)
            {
                ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "DepartmentName");
                ViewBag.TeacherId = new SelectList(db.Teachers, "TeacherId", "TeacherName");
                ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "CourseName");

                if (aDepartment.DepartmentId != aCourse.DepartmentId)
                {
                    message += "Your Course is not from the selected department";

                }
                else if (aCourse.DepartmentId != aTeacher.DepartmentId)
                {
                    message += "Your Teacher is not from the selected department";
                }

            }

            // if course is already assigned

            if (aCourse.Teacher != null)
            {
                message += "Course Already Assigned";
            }

            return message;
        }