public ActionResult EditStudent(string id, string course, FormCollection collection)//---> gets course name, delete the row of it and add new row with changes from the faculty
        {
            DateTime     now   = DateTime.Now;
            StudentsDal  dal   = new StudentsDal();
            ExamsDal     dalEx = new ExamsDal();
            Students     sd    = dal.students.Find(id, course);
            List <Exams> ex    = (from x in dalEx.exams
                                  where x.CourseId.Contains(sd.CourseName)
                                  select x).ToList <Exams>();

            foreach (Exams e in ex)
            {
                DateTime MoedADate = DateTime.Parse(e.MoedADate);
                DateTime MoedBDate = DateTime.Parse(e.MoedBDate);
                int      resultA   = DateTime.Compare(MoedADate, now.Date);
                if (resultA > 0)
                {
                    return(RedirectToAction("ErrorPageAddGrade"));
                }
                int resultB = DateTime.Compare(MoedBDate, now.Date);
                if (resultB > 0)
                {
                    return(RedirectToAction("ErrorPageAddGrade"));
                }
            }
            dal.students.Remove(sd);
            dal.SaveChanges();

            Students stud = new Students()
            {
                FirstName  = collection["FirstName"],
                LastName   = collection["LastName"],
                Id         = collection["Id"],
                CourseName = collection["CourseName"],
                GradeMoedA = collection["GradeMoedA"],
                GradeMoedB = collection["GradeMoedB"],
                FinalGrade = collection["FinalGrade"]
            };

            if (ModelState.IsValid)
            {
                try
                {
                    (from s in dal.students
                     where s.Id == id
                     select s).ToList();
                    dal.students.Add(stud);
                    dal.SaveChanges();
                }
                catch (Exception)
                {
                    TempData["error"] = "The course already exist!\n"; // print error message
                    return(View());
                }
            }
            return(View("Home"));
        }
        public ActionResult AddStudents(Students obj)//send info to db
        {
            StudentsDal dal  = new StudentsDal();
            CoursesDal  dalC = new CoursesDal();
            //list of of the same student and his courses
            List <Students> studentsCourses = (from s in dal.students
                                               where s.Id.Contains(obj.Id)
                                               select s).ToList <Students>();
            //list of all the courses
            List <Courses> CoursesObj = (from c in dalC.courses
                                         select c).ToList <Courses>();

            foreach (Students std in studentsCourses)
            {
                //only one course
                List <Courses> Crs = (from c in CoursesObj
                                      where c.CourseId.Contains(std.CourseName)
                                      select c).ToList <Courses>();
                Courses cr = dalC.courses.Find(obj.CourseName);
                foreach (Courses c in Crs)
                {
                    if (cr.Day == c.Day)
                    {
                        if (System.Convert.ToDecimal(cr.StartHour) >= System.Convert.ToDecimal(c.StartHour) &&
                            System.Convert.ToDecimal(cr.StartHour) <= System.Convert.ToDecimal(c.EndHour) ||
                            System.Convert.ToDecimal(cr.EndHour) >= System.Convert.ToDecimal(c.StartHour) &&
                            System.Convert.ToDecimal(cr.EndHour) <= System.Convert.ToDecimal(c.EndHour))
                        {
                            return(RedirectToAction("ErrorPageAddStud"));
                        }
                    }
                }
            }
            Students students = new Students()
            {
                FirstName  = obj.FirstName,
                LastName   = obj.LastName,
                Id         = obj.Id,
                CourseName = obj.CourseName,
                GradeMoedA = obj.GradeMoedA,
                GradeMoedB = obj.GradeMoedB,
                FinalGrade = obj.FinalGrade
            };

            //StudentsDal dal = new StudentsDal();

            if (ModelState.IsValid)
            {
                try
                {
                    dal.students.Add(obj);
                    dal.SaveChanges();
                }
                catch (Exception)
                {
                    TempData["error"] = "The course already exist!\n"; // print error message
                    return(View());
                }
            }
            return(RedirectToAction("Home"));
        }