Beispiel #1
0
        public ActionResult Create(List <Ta_Wishes> ta_Wishes)
        {
            Ta_Wishes TA   = new Ta_Wishes();
            var       TAId = User.Identity.GetUserId();

            // ta_Wishes.Ta_Id = TAId;

            if (ModelState.IsValid)
            {
                foreach (var i in ta_Wishes)
                {
                    i.Ta_Id = TAId;


                    if (i.Priority != 0)
                    {
                        db.Ta_Wishes.Add(i);
                    }
                }

                db.SaveChanges();

                return(View(ta_Wishes));
            }
            ViewBag.Year_id = new SelectList(db.Years, "ID", "Year1", TA.Year_id);
            // ViewBag.Course_Id2 = new SelectList(db.Courses, "ID", "Name", TA.Course_Id);
            ViewBag.Course_Id = new SelectList(db.Courses, "ID", "Name", TA.Course_Id);


            return(View(ta_Wishes));
        }
Beispiel #2
0
        // GET: Home
        //public ActionResult profile()
        //{
        //    //AspNetUser  Aspuser =new
        //    //    (from c in db.AspNetUsers
        //    //            where c.Id == User.Identity.GetUserId()
        //    //            select c).ToList();
        //    return View();
        //}

        public ActionResult About()
        {
            ViewBag.Message = "The generation done successfully";
            CollegeDatabaseEntities10 _db = new CollegeDatabaseEntities10();

            var del = (from x in db.LectureTimes
                       select x);

            db.LectureTimes.RemoveRange(del);

            var dell = (from x in db.SectionTimes
                        select x);

            db.SectionTimes.RemoveRange(dell);
            // var res = functions.Generatelecandsec()
            List <GroupModel> GrpList = new List <GroupModel>();
            functions         func    = new functions();
            var res          = func.Generate_lect(ref GrpList);
            var assin        = func.generatesecs(GrpList);
            var lecTimeTable = new LectureTime();

            foreach (var item in res)
            {
                var crs_id = _db.Courses.Where(x => x.Name == item.CourseName).Select(x => x.ID).Single();
                lecTimeTable = new LectureTime()
                {
                    Course_id = crs_id, Room_id = item.RoomId, DayOfWeek = item.Day, Grp_id = item.GrpId, StartHour = item.StartHour
                };
                _db.LectureTimes.Add(lecTimeTable);
                _db.SaveChanges();
                Console.WriteLine("{0} : {1} : {2}", item.CourseName, item.StartHour, item.Day.ToString());
            }
            foreach (var item in assin)
            {
                if (item.RoomId != -1)

                {
                    SectionTime x = new SectionTime();
                    x.Course_id  = item.CourseId;
                    x.Section_id = item.SectionId;
                    x.Room_id    = item.RoomId;
                    x.DayOfWeek  = item.Day;
                    x.StartHour  = item.Start;
                    x.isLab      = item.IsLab;
                    x.isSection  = item.IsSection;
                    // if(item.Tasids)
                    x.Ta_id = item.Tasids[0];
                    _db.SectionTimes.Add(x);
                    _db.SaveChanges();
                }
            }


            return(View());
        }
Beispiel #3
0
 public ActionResult Edit([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName,Department_id,Experience,isExternal")] AspNetUser aspNetUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Department_id = new SelectList(db.Departments, "ID", "Name", aspNetUser.Department);
     return(View(aspNetUser));
 }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "ID,Year_id,StudentsCount,GroupCount,SectionCount,AcademicYear1,DayWorkHours,AllowedGapHours")] AcademicYear academicYear)
        {
            if (ModelState.IsValid)
            {
                db.AcademicYears.Add(academicYear);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Year_id = new SelectList(db.Years, "ID", "Year1", academicYear.Year_id);
            return(View(academicYear));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Capacity,AcademicYear_id,WorkHoursPerDay,AllowedGapHours")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AcademicYear_id = new SelectList(db.AcademicYears, "ID", "AcademicYear1", department.AcademicYear_id);
            return(View(department));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Capacity,RoomType_id,isActive,Year_id")] Room room)
        {
            if (ModelState.IsValid)
            {
                db.Rooms.Add(room);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RoomType_id = new SelectList(db.RoomTypes, "ID", "Name", room.RoomType_id);
            ViewBag.Year_id     = new SelectList(db.Years, "ID", "Year1", room.Year_id);
            return(View(room));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Count,AcadmicYear_id,Department_id")] Group group)
        {
            if (ModelState.IsValid)
            {
                db.Groups.Add(group);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AcadmicYear_id = new SelectList(db.AcademicYears, "ID", "AcademicYear1", group.AcadmicYear_id);
            ViewBag.Department_id  = new SelectList(db.Departments, "ID", "Name", group.Department_id);
            return(View(group));
        }
        public ActionResult Create([Bind(Include = "ID,Course_id,Department_id")] LinkCourseDept linkCourseDept)
        {
            if (ModelState.IsValid)
            {
                db.LinkCourseDepts.Add(linkCourseDept);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Course_id     = new SelectList(db.Courses, "ID", "Name", linkCourseDept.Course_id);
            ViewBag.Department_id = new SelectList(db.Departments, "ID", "Name", linkCourseDept.Department_id);
            return(View(linkCourseDept));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Hours,HaveLab,HaveSection,LabHours,SectionHours,RoomType_id,AcademicYear_id,StaffCount")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Courses.Add(course);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AcademicYear_id = new SelectList(db.AcademicYears, "ID", "AcademicYear1", course.AcademicYear_id);
            ViewBag.RoomType_id     = new SelectList(db.RoomTypes, "ID", "Name", course.RoomType_id);
            return(View(course));
        }
        public ActionResult Create([Bind(Include = "ID,Doctor_id,Course_id,hours")] LinkDoctorCourse linkDoctorCourse)
        {
            if (ModelState.IsValid)
            {
                db.LinkDoctorCourses.Add(linkDoctorCourse);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Doctor_id = new SelectList(db.AspNetUsers, "Id", "Email", linkDoctorCourse.Doctor_id);
            ViewBag.Course_id = new SelectList(db.Courses, "ID", "Name", linkDoctorCourse.Course_id);
            return(View(linkDoctorCourse));
        }
Beispiel #11
0
        public ActionResult Create([Bind(Include = "ID,Year_id,Ta_id,HoursPerWeek")] VictimHistory victimHistory)
        {
            if (ModelState.IsValid)
            {
                db.VictimHistories.Add(victimHistory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Ta_id   = new SelectList(db.AspNetUsers, "Id", "Email", victimHistory.Ta_id);
            ViewBag.Year_id = new SelectList(db.Years, "ID", "Year1", victimHistory.Year_id);
            return(View(victimHistory));
        }
        public ActionResult Create([Bind(Include = "ID,Course_Id,Priority,Ta_Id,isAccepted,Year_id")] Ta_Wishes ta_Wishes)
        {
            if (ModelState.IsValid)
            {
                db.Ta_Wishes.Add(ta_Wishes);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Ta_Id     = new SelectList(db.AspNetUsers, "Id", "Email", ta_Wishes.Ta_Id);
            ViewBag.Course_Id = new SelectList(db.Courses, "ID", "Name", ta_Wishes.Course_Id);
            ViewBag.Year_id   = new SelectList(db.Years, "ID", "Year1", ta_Wishes.Year_id);
            return(View(ta_Wishes));
        }
        public ActionResult Create([Bind(Include = "ID,Ta_Id,Start_Date,End_Date,Description,Year_id")] Ta_Constraints ta_Constraints)
        {
            var TAId = User.Identity.GetUserId();

            ta_Constraints.Ta_Id = TAId;
            db.Ta_Constraints.Add(ta_Constraints);
            db.SaveChanges();
            return(RedirectToAction("Index"));


            ViewBag.Ta_Id   = new SelectList(db.AspNetUsers, "Id", "Email", ta_Constraints.Ta_Id);
            ViewBag.Year_id = new SelectList(db.Years, "ID", "Year1", ta_Constraints.Year_id);
            return(View(ta_Constraints));
        }
        public ActionResult Index(List <Doctor_Available_Time> Doctor_Available_Time)
        {
            Doctor_Available_Time doctor_Available_Time = new Doctor_Available_Time();


            //var docId = (from c in db.AspNetUsers
            //             where
            //             c.Email == s
            //             select c.Id).Single();

            var docId = User.Identity.GetUserId();

            if (ModelState.IsValid) // m7tgen l dcotor id
            {
                foreach (var i in Doctor_Available_Time)
                {
                    if (i.DayOfWeek != 0)
                    {
                        db.Doctor_Available_Time.Add(i);
                    }
                }
                db.SaveChanges();
                // ModelState.Clear();

                Doctor_Available_Time = new List <Doctor_Available_Time>();
                for (int i = 0; i < 98; i++)
                {
                    Doctor_Available_Time.Add(new Doctor_Available_Time {
                        ID = 0, Course_id = 0, StartHour = 0, DayOfWeek = 0
                    });
                }
            }
            var courses = (from c in db.Courses
                           join doc in db.LinkDoctorCourses on c.ID equals doc.Course_id
                           where doc.Doctor_id == docId
                           select c).ToList();

            //   ViewBag.Doctor_Id = new SelectList(db.AspNetUsers, "Id", "Email", doctor_Available_Time.Doctor_Id);
            ViewBag.Doctor_Id   = new SelectList(db.AspNetUsers, "Id", "Email");
            ViewBag.Course_id   = new SelectList(courses, "ID", "Name");
            ViewBag.course_hour = db.Courses.OrderBy(x => x.ID).Select(x => x.Hours).ToArray();
            ViewBag.course_name = db.Courses.OrderBy(x => x.ID).Select(x => x.Name).ToArray();

            ViewBag.course__id = db.Courses.OrderBy(x => x.ID).Select(x => x.ID).ToArray();
            return(View(Doctor_Available_Time));
        }
Beispiel #15
0
        public static void MainAlgo()
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();
            // Declare lists
            List <course>      courseList  = new List <course>();
            List <ta>          taList      = new List <ta>();
            List <TaForCourse> taForCourse = new List <TaForCourse>();
            // load data from database in course List
            var courseListdb = (from x in db.Courses
                                select new { x.ID, x.LabHours, x.SectionHours, x.AcademicYear_id }).ToList();

            for (int i = 0; i < courseListdb.Count(); i++)
            {
                if (courseListdb[i].LabHours != null || courseListdb[i].SectionHours != null)
                {
                    int courseHour = Convert.ToInt32(courseListdb[i].SectionHours);
                    int labHour    = Convert.ToInt32(courseListdb[i].LabHours);
                    int total      = totalHoursForCourse(courseListdb[i].AcademicYear_id, courseHour, labHour);
                    courseList.Add(new course((Convert.ToInt32(courseListdb[i].ID)), courseHour, total, labHour));
                }
            }

            // load data from database in ta list
            var taInfo = (from x in db.AspNetUsers
                          where x.type == "Ta"
                          select new { x.Id, x.Experience }).ToList();

            var tawishesList = (from x in db.Ta_Wishes
                                select new { x.Ta_Id, x.Course_Id, x.Priority }).ToList();

            for (int i = 0; i < taInfo.Count(); i++)
            {
                int wish1 = 0;
                int wish2 = 0;
                for (int j = 0; j < tawishesList.Count(); j++)
                {
                    string ta_info_id  = Convert.ToString(taInfo[i].Id);
                    string ta_wish_id  = Convert.ToString(tawishesList[j].Ta_Id);
                    int    ta_wish_pri = Convert.ToInt32(tawishesList[j].Priority);
                    if (ta_info_id == ta_wish_id)
                    {
                        if (ta_wish_pri == 1)
                        {
                            wish1 = Convert.ToInt32(tawishesList[j].Course_Id);
                        }
                        else if (ta_wish_pri == 2)
                        {
                            //if (wish1 == 0)
                            //{
                            //    j = 0;
                            //    continue;
                            //}
                            wish2 = Convert.ToInt32(tawishesList[j].Course_Id);
                        }
                        else if (ta_wish_pri == 3)
                        {
                            //if (wish2 == 0)
                            //{
                            //    j = 0;
                            //    continue;
                            //}
                            taList.Add(new ta(tawishesList[j].Ta_Id, wish1, wish2, Convert.ToInt32(tawishesList[j].Course_Id), totalHoursForEachTa(), (Convert.ToInt32(taInfo[i].Experience))));
                            break;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            // choose victim from list
            List <ta>     victimList    = new List <ta>();
            List <ta>     nonVictimList = new List <ta>();
            List <string> temp          = Victims();

            for (int i = 0; i < taList.Count(); i++)
            {
                bool check = false;
                for (int j = 0; j < temp.Count(); j++)
                {
                    if (temp[j] == taList[i].id)
                    {
                        victimList.Add(new ta(taList[i].id, taList[i].wish1, taList[i].wish2, taList[i].wish3, taList[i].remain_hours, taList[i].experiance));
                        check = true;
                        break;
                    }
                }
                if (check == false)
                {
                    nonVictimList.Add(new ta(taList[i].id, taList[i].wish1, taList[i].wish2, taList[i].wish3, taList[i].remain_hours, taList[i].experiance));
                }
            }
            // sort taList by experiance
            List <ta> sortedTAList = new List <ta>();

            sortedTAList = sortList(victimList);
            // algorithm elawl ll victim
            TaForEachCourse(sortedTAList, courseList, taForCourse);
            // algorithm l sana 4
            List <ta>     remain_ta     = new List <ta>();
            List <course> remain_course = new List <course>();

            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                remain_ta.Add(new ta(sortedTAList[i].id, sortedTAList[i].wish1, sortedTAList[i].wish2, sortedTAList[i].wish3, sortedTAList[i].remain_hours, sortedTAList[i].experiance));
            }
            sortedTAList = new List <ta>();
            sortedTAList = sortList(nonVictimList);
            // choose mwad sana 4
            var academic_4_id = (from x in db.AcademicYears
                                 where x.AcademicYear1 == 4
                                 select x.ID).SingleOrDefault();
            int acad_4     = Convert.ToInt32(academic_4_id);
            var academic_4 = (from x in db.Courses
                              where x.AcademicYear_id == acad_4
                              select x.ID).ToList();
            List <int> academic_list = new List <int>();

            for (int i = 0; i < academic_4.Count(); i++)
            {
                academic_list.Add(academic_4[i]);
            }
            List <course> courses_4    = new List <course>();
            List <course> coursesNot_4 = new List <course>();

            for (int i = 0; i < courseList.Count(); i++)
            {
                bool check = false;
                for (int j = 0; j < academic_list.Count(); j++)
                {
                    if (academic_list[j] == courseList[i].id)
                    {
                        courses_4.Add(new course(courseList[i].id, courseList[i].course_hours, courseList[i].remain_hours, courseList[i].lab_hours));

                        check = true;
                        break;
                    }
                }
                if (check == false)
                {
                    coursesNot_4.Add(new course(courseList[i].id, courseList[i].course_hours, courseList[i].remain_hours, courseList[i].lab_hours));
                }
            }

            TaForEachCourse(sortedTAList, courses_4, taForCourse);
            for (int i = 0; i < courses_4.Count(); i++)
            {
                remain_course.Add(new course(courses_4[i].id, courses_4[i].course_hours, courses_4[i].remain_hours, courses_4[i].lab_hours));
            }
            TaForEachCourse(sortedTAList, coursesNot_4, taForCourse);
            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                remain_ta.Add(new ta(sortedTAList[i].id, sortedTAList[i].wish1, sortedTAList[i].wish2, sortedTAList[i].wish3, sortedTAList[i].remain_hours, sortedTAList[i].experiance));
            }

            for (int i = 0; i < coursesNot_4.Count(); i++)
            {
                remain_course.Add(new course(coursesNot_4[i].id, coursesNot_4[i].course_hours, coursesNot_4[i].remain_hours, coursesNot_4[i].lab_hours));
            }
            // elyear ely ana feha 3shan a add elvictim
            var years = (from x in db.Years
                         select x.ID).ToList();
            List <int> yearss = new List <int>();
            int        year;

            if (years.Count() == 1)
            {
                year = 1;
            }
            else
            {
                for (int i = 0; i < years.Count(); i++)
                {
                    yearss.Add(years[i]);
                }

                year = yearss[years.Count() - 1];
            }

            var victim = (from x in db.VictimHistories
                          where x.Year_id == year
                          select x.Ta_id).ToList();

            for (int i = 0; i < remain_ta.Count(); i++)
            {
                VictimHistory victim1 = new VictimHistory();
                victim1.Ta_id   = remain_ta[i].id;
                victim1.Year_id = year;
                db.VictimHistories.Add(victim1);
                db.SaveChanges();
            }
            remain_ta = sortList(remain_ta);
            // lw remain ta = remain course
            for (int i = 0; i < remain_ta.Count(); i++)
            {
                for (int j = 0; j < remain_course.Count(); j++)
                {
                    if (remain_ta[i].remain_hours == remain_course[j].remain_hours)
                    {
                        if (remain_ta[i].remain_hours != 0)
                        {
                            LinkDoctorCourse link = new LinkDoctorCourse();
                            link.Course_id = remain_course[j].id;
                            link.Doctor_id = remain_ta[i].id;
                            link.hours     = remain_ta[i].remain_hours;

                            db.LinkDoctorCourses.Add(link);
                            db.SaveChanges();
                        }
                        remain_ta.Remove(remain_ta[i]);
                        if (i > 0 && i != remain_ta.Count() - 1)
                        {
                            i--;
                        }
                        else if (i == 0)
                        {
                            i = 0;
                        }
                        remain_course.Remove(remain_course[j]);
                        if (j > 0 && j != remain_course.Count() - 1)
                        {
                            j--;
                        }
                        else if (j == 0)
                        {
                            j = 0;
                        }
                    }
                }
            }
            // lw remain ta >< remain course
            for (int i = 0; i < remain_ta.Count(); i++)
            {
                for (int j = 0; j < remain_course.Count(); j++)
                {
                    if (remain_ta[i].remain_hours > remain_course[j].remain_hours)
                    {
                        if (remain_course[j].course_hours != 0 && remain_ta[i].remain_hours % remain_course[j].course_hours != 0)
                        {
                            while (remain_ta[i].remain_hours % remain_course[j].course_hours != 0)
                            {
                                remain_ta[i].remain_hours--;
                            }
                        }
                        if (remain_course[j].lab_hours != 0 && remain_ta[i].remain_hours % remain_course[j].lab_hours != 0)
                        {
                            while (remain_ta[i].remain_hours % remain_course[j].lab_hours != 0)
                            {
                                remain_ta[i].remain_hours--;
                            }
                        }
                        if (remain_course[j].remain_hours != 0)
                        {
                            LinkDoctorCourse link = new LinkDoctorCourse();
                            link.Course_id = remain_course[j].id;
                            link.Doctor_id = remain_ta[i].id;
                            link.hours     = remain_course[j].remain_hours;
                            db.LinkDoctorCourses.Add(link);
                            db.SaveChanges();
                        }
                        remain_ta[i].remain_hours -= remain_course[j].remain_hours;
                        remain_course.Remove(remain_course[j]);
                        if (j > 0 && j != remain_course.Count() - 1)
                        {
                            j--;
                        }
                        else if (j == 0)
                        {
                            j = 0;
                        }
                    }
                    // lw course hours > ta hours
                    else
                    {
                        if (remain_course[j].course_hours != 0 && remain_ta[i].remain_hours % remain_course[j].course_hours != 0)
                        {
                            while (remain_ta[i].remain_hours % remain_course[j].course_hours != 0)
                            {
                                remain_ta[i].remain_hours++;
                            }
                        }
                        if (remain_course[j].lab_hours != 0 && remain_ta[i].remain_hours % remain_course[j].lab_hours != 0)
                        {
                            while (remain_ta[i].remain_hours % remain_course[j].lab_hours != 0)
                            {
                                remain_ta[i].remain_hours++;
                            }
                        }
                        if (remain_ta[i].remain_hours != 0)
                        {
                            LinkDoctorCourse link = new LinkDoctorCourse();
                            link.Course_id = remain_course[j].id;
                            link.Doctor_id = remain_ta[i].id;
                            link.hours     = remain_ta[i].remain_hours;
                            db.LinkDoctorCourses.Add(link);
                            db.SaveChanges();
                        }
                        remain_course[j].remain_hours -= remain_ta[i].remain_hours;
                        remain_ta.Remove(remain_ta[i]);
                        if (i > 0 && i != remain_ta.Count() - 1)
                        {
                            i--;
                        }
                        else if (i == 0)
                        {
                            i = 0;
                        }
                    }
                }
            }
        }
Beispiel #16
0
        public static void TaForEachCourse(List <ta> sortedTAList, List <course> courseList, List <TaForCourse> taForCourse)
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();

            // wish 1
            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                for (int j = 0; j < courseList.Count(); j++)
                {
                    if (courseList[j].id == sortedTAList[i].wish1)
                    {
                        // lw hours elcourse > hours el ta
                        if (courseList[j].remain_hours > sortedTAList[i].remain_hours)
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }


                            int x = sortedTAList[i].remain_hours;

                            //  sortedTAList[i].remain_hours = courseList[j].remain_hours - x;
                            courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }
                            // lw elta hours b2t zero aw 22l yshelo mn ellist
                            sortedTAList.Remove(sortedTAList[i]);
                            if (i > 0 && i != sortedTAList.Count() - 1)
                            {
                                i--;
                            }
                            else if (i == 0)
                            {
                                i = 0;
                            }

                            if (courseList[j].remain_hours <= 0)
                            {
                                courseList.Remove(courseList[j]);
                                if (j > 0 && j != courseList.Count() - 1)
                                {
                                    j--;
                                }
                                else if (j == 0)
                                {
                                    j = 0;
                                }
                            }
                            break;
                        }
                        // lw hours ellecture <= hours el ta
                        else
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }

                            int x = courseList[j].remain_hours;
                            sortedTAList[i].remain_hours = sortedTAList[i].remain_hours - courseList[j].remain_hours;
                            // courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }

                            if (sortedTAList[i].remain_hours <= 0)
                            {
                                sortedTAList.Remove(sortedTAList[i]);
                                if (i > 0 && i != sortedTAList.Count() - 1)
                                {
                                    i--;
                                }
                                else if (i == 0)
                                {
                                    i = 0;
                                }
                            }


                            courseList.Remove(courseList[j]);
                            if (j > 0 && i != courseList.Count() - 1)
                            {
                                j--;
                            }
                            else if (j == 0)
                            {
                                j = 0;
                            }
                        }
                    }
                }
            }
            //wish2
            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                for (int j = 0; j < courseList.Count(); j++)
                {
                    if (courseList[j].id == sortedTAList[i].wish2)
                    {
                        // lw hours elcourse > hours el ta
                        if (courseList[j].remain_hours > sortedTAList[i].remain_hours)
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }

                            int x = sortedTAList[i].remain_hours;

                            //sortedTAList[i].remain_hours = courseList[j].remain_hours - x;
                            courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }
                            // lw elta hours b2t zero aw 22l yshelo mn ellist
                            sortedTAList.Remove(sortedTAList[i]);
                            if (i > 0 && i != sortedTAList.Count() - 1)
                            {
                                i--;
                            }
                            else if (i == 0)
                            {
                                i = 0;
                            }

                            if (courseList[j].remain_hours <= 0)
                            {
                                courseList.Remove(courseList[j]);
                                if (j > 0 && j != courseList.Count() - 1)
                                {
                                    j--;
                                }
                                else if (j == 0)
                                {
                                    j = 0;
                                }
                            }
                            break;
                        }
                        // lw hours ellecture <= hours el ta
                        else
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }

                            int x = courseList[j].remain_hours;
                            sortedTAList[i].remain_hours = sortedTAList[i].remain_hours - courseList[j].remain_hours;
                            //  courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }

                            if (sortedTAList[i].remain_hours <= 0)
                            {
                                sortedTAList.Remove(sortedTAList[i]);
                                if (i > 0 && i != sortedTAList.Count() - 1)
                                {
                                    i--;
                                }
                                else if (i == 0)
                                {
                                    i = 0;
                                }
                            }


                            courseList.Remove(courseList[j]);
                            if (j > 0 && i != courseList.Count() - 1)
                            {
                                j--;
                            }
                            else if (j == 0)
                            {
                                j = 0;
                            }
                        }
                    }
                }
            }
            // wish 3
            //for (int i = 0; i < sortedTAList.Count(); i++)
            //{

            //    for (int j = 0; j < courseList.Count(); j++)
            //    {
            //        if (courseList[j].id == sortedTAList[i].wish3)
            //        {
            //            if (courseList[j].remain_hours > sortedTAList[i].remain_hours)
            //            {
            //                if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
            //                {
            //                    while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
            //                        sortedTAList[i].remain_hours++;
            //                }
            //                else if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
            //                {
            //                    while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
            //                        sortedTAList[i].remain_hours++;
            //                }

            //                int x = sortedTAList[i].remain_hours;
            //                sortedTAList[i].remain_hours = x - sortedTAList[i].remain_hours;
            //                taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
            //                // insert record in linkDoctorCourse
            //                LinkDoctorCourse link = new LinkDoctorCourse();
            //                link.Course_id = courseList[j].id;
            //                link.Doctor_id = sortedTAList[i].id;
            //                link.hours = x;
            //                db.LinkDoctorCourses.Add(link);
            //                db.SaveChanges();
            //                // lw elta hours b2t zero aw 22l yshelo mn ellist
            //                if (sortedTAList[i].remain_hours <= 0)
            //                {
            //                    sortedTAList.Remove(sortedTAList[i]);
            //                    if (i > 0)
            //                        i--;
            //                    else
            //                        i = 0;
            //                }
            //                courseList[j].remain_hours = courseList[j].remain_hours - x;
            //                if (courseList[j].remain_hours == 0)
            //                {
            //                    courseList.Remove(courseList[j]);
            //                    if (j > 0)
            //                        j--;
            //                    else
            //                        j = 0;
            //                }

            //                break;
            //            }
            //            else
            //            {
            //                int x = courseList[j].remain_hours;
            //                sortedTAList[i].remain_hours = courseList[j].remain_hours - sortedTAList[i].remain_hours;
            //                courseList[j].remain_hours = courseList[j].remain_hours - x;
            //                // insert record in linkDoctorCourse
            //                LinkDoctorCourse link = new LinkDoctorCourse();
            //                link.Course_id = courseList[j].id;
            //                link.Doctor_id = sortedTAList[i].id;
            //                link.hours = x;
            //                db.LinkDoctorCourses.Add(link);
            //                db.SaveChanges();

            //                if (sortedTAList[i].remain_hours <= 0)
            //                {
            //                    sortedTAList.Remove(sortedTAList[i]);
            //                    if (i > 0)
            //                        i--;
            //                    else
            //                        i = 0;
            //                }
            //                courseList[j].remain_hours = courseList[j].remain_hours - x;
            //                if (courseList[j].remain_hours == 0)
            //                {
            //                    courseList.Remove(courseList[j]);
            //                    if (j > 0)
            //                        j--;
            //                    else
            //                        j = 0;
            //                }

            //            }
            //        }
            //    }

            //}
            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                for (int j = 0; j < courseList.Count(); j++)
                {
                    if (courseList[j].id == sortedTAList[i].wish3)
                    {
                        // lw hours elcourse > hours el ta
                        if (courseList[j].remain_hours > sortedTAList[i].remain_hours)
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }

                            int x = sortedTAList[i].remain_hours;

                            // sortedTAList[i].remain_hours = courseList[j].remain_hours - x;
                            courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            LinkDoctorCourse link = new LinkDoctorCourse();
                            link.Course_id = courseList[j].id;
                            link.Doctor_id = sortedTAList[i].id;
                            link.hours     = x;
                            db.LinkDoctorCourses.Add(link);
                            db.SaveChanges();
                            // lw elta hours b2t zero aw 22l yshelo mn ellist
                            sortedTAList.Remove(sortedTAList[i]);
                            if (i > 0 && i != sortedTAList.Count() - 1)
                            {
                                i--;
                            }
                            else if (i == 0)
                            {
                                i = 0;
                            }

                            if (courseList[j].remain_hours <= 0)
                            {
                                courseList.Remove(courseList[j]);
                                if (j > 0 && j != courseList.Count() - 1)
                                {
                                    j--;
                                }
                                else if (j == 0)
                                {
                                    j = 0;
                                }
                            }
                            break;
                        }
                        // lw hours ellecture <= hours el ta
                        else
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }

                            int x = courseList[j].remain_hours;
                            sortedTAList[i].remain_hours = sortedTAList[i].remain_hours - courseList[j].remain_hours;
                            courseList[j].remain_hours   = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }

                            if (sortedTAList[i].remain_hours <= 0)
                            {
                                sortedTAList.Remove(sortedTAList[i]);
                                if (i > 0 && i != sortedTAList.Count() - 1)
                                {
                                    i--;
                                }
                                else if (i == 0)
                                {
                                    i = 0;
                                }
                            }


                            courseList.Remove(courseList[j]);
                            if (j > 0 && i != courseList.Count() - 1)
                            {
                                j--;
                            }
                            else if (j == 0)
                            {
                                j = 0;
                            }
                        }
                    }
                }
            }
        }