//public ActionResult Save_Data(Grades model)
        public ActionResult Save_Data(FormCollection fc)
        {
            try
            {
                SzkolaEntities db     = new SzkolaEntities();
                School_Grades  Grades = new School_Grades();

                string   Forma_Zaliczenia4 = fc["Uwagi"];
                string[] Forma_Zaliczenia  = Forma_Zaliczenia4.Split(',');
                string   Ocena4            = fc["Ocena"];
                string[] Ocena             = Ocena4.Split(',');
                string   Student4          = fc["StudentID"];
                string[] Student           = Student4.Split(',');
                string   TeacherID         = fc["TeacherID"];

                //float Grade;
                //double Grade4;
                //double Ocena = Convert.ToDouble(fc["Ocena"]);

                for (int i = 0; i < Forma_Zaliczenia.Length; i++)
                {
                    if ((Forma_Zaliczenia[i] == "X" || Forma_Zaliczenia[i] == null || Ocena[i] == "X"))
                    {
                        TempData["Brak_Danych"] = "Niestety nie udało się Tobie wprowadzić żadnych ocen!";

                        continue;
                        //Grade = float.Parse(Ocena[i]);
                        //Grade4 = double.Parse(Ocena[i]);
                    }
                    else
                    {
                        Grades.Uwagi     = Forma_Zaliczenia[i];
                        Grades.StudentID = Convert.ToInt32(Student[i]);

                        Grades.Ocena = Convert.ToDouble(Ocena[i].Replace(".", ","));


                        Grades.TeacherID = Convert.ToInt32(TeacherID);
                        Grades.Data      = DateTime.Now;

                        db.School_Grades.Add(Grades);
                        db.SaveChanges();


                        TempData["Informacja"] = "Wszystkie oceny zostały prawidłowo zapisane!";
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(RedirectToAction("Come_Back"));
        }
        public ActionResult Student_Grades()
        {
            int             UserID;
            LoginController Log = new LoginController();

            Log.wyciaganie_ID(out UserID);



            SzkolaEntities db     = new SzkolaEntities();
            School_Grades  Grades = new School_Grades();

            var Pobrane = (from table2 in db.Student
                           join table3 in db.School_Grades on table2.StudentID equals table3.StudentID
                           join table4 in db.Teacher on table3.TeacherID equals table4.TeacherID
                           join table5 in db.School_Class on table2.ClassID equals table5.ClassID
                           where
                           table2.UserID == UserID
                           select new Grades
            {
                ClassID = table2.ClassID,
                Nazwa_Klasy = table5.Nazwa,
                Przedmiot = table4.Przedmiot,
                Ocena = table3.Ocena,
                Uwagi = table3.Uwagi,
                Data = table3.Data,
                TeacherID = table4.TeacherID
            }).ToList();

            var ID = Pobrane.FirstOrDefault().ClassID;

            var Przedmioty = (from table1 in db.Teacher
                              join table2 in db.User
                              on table1.UserID equals table2.UserID
                              where table1.ClassID == ID

                              select new Grades
            {
                Imie2 = table2.Imie,
                Nazwisko2 = table2.Nazwisko,
                przedmiot2 = table1.Przedmiot
            }).Distinct().ToList();


            ViewBag.Przedmioty = Przedmioty;



            return(View("Student_Grades", "~/Views/Main_Layout.cshtml", Pobrane));
        }
        public ActionResult Grades_View_II()
        {
            //string ClassID = fc["ClassID"];
            //int ID_Class = Convert.ToInt32(ClassID);
            int ID_Class = Convert.ToInt32(Session["ClassID"]);

            var Przedmiot = "Matematyka";

            if (TempData.ContainsKey("Przedmiot"))
            {
                Przedmiot = TempData["Przedmiot"].ToString().Trim();
            }
            else
            {
                ///*TempData*/["Pusto"] = "Matematyka";
                Przedmiot = "Matematyka";
            }

            SzkolaEntities db     = new SzkolaEntities();
            School_Grades  Grades = new School_Grades();



            Data Dane = new Data();

            var Zaciaganie = (from table1 in db.User
                              join table2 in db.Student on table1.UserID equals table2.UserID
                              where
                              table2.ClassID == ID_Class
                              select new Data
            {
                Imie = table1.Imie,
                Nazwisko = table1.Nazwisko,
                StudentID = table2.StudentID
            }).ToList();

            DataGradesModel DGM = new DataGradesModel();

            ViewBag.Zaciaganie = Zaciaganie;



            var Pobrane = (from table2 in db.Student
                           join table3 in db.School_Grades on table2.StudentID equals table3.StudentID
                           join table4 in db.Teacher on table3.TeacherID equals table4.TeacherID
                           where
                           table2.ClassID == ID_Class &&
                           table4.Przedmiot == Przedmiot

                           select new Grades
            {
                Przedmiot = table4.Przedmiot,
                Ocena = table3.Ocena,
                Uwagi = table3.Uwagi,
                StudentID2 = table2.StudentID,
                Data = table3.Data
            }).ToList();

            ViewBag.Pobrane = Pobrane;


            double suma  = 0;
            int    ilosc = 0;
            double wynik;

            foreach (var item in Pobrane)
            {
                suma  = suma + item.Ocena;
                ilosc = ilosc + 1;
            }
            if (ilosc == 0)
            {
                ViewBag.Wynik50 = "Brak Ocen";
            }
            else
            {
                wynik           = Math.Round(suma / ilosc, 2);
                ViewBag.Wynik50 = " Średnia całej klasy wynosi: " + wynik;
            }

            var Przedmioty = (from table1 in db.Teacher
                              select new Grades
            {
                przedmiot2 = table1.Przedmiot
            }).Distinct().ToList();

            ViewBag.Przedmioty = Przedmioty;


            return(View("~/Views/Teacher/Grades_View_II.cshtml", "~/Views/Main_Layout.cshtml", Pobrane));
        }