public ActionResult UpdateProjectNote(string idStud, string idProj)
        {
            if (_idProjInt != null)
            {
                _idProjInt = Convert.ToInt32(idProj);
            }
            int idStudint = Convert.ToInt32(idStud);

            _teaProfile.Stages = new List <Models.TeacherModels.StageContext>();
            using (var entity = new Data.TestEntities())
            {
                var stages = entity.etapy.Where(x => x.id_proj == _idProjInt);
                //var notebyStage = entity.notesbyStage(_projStud.id_student.ToString(), _projStud.id_proj.ToString());
                try
                {
                    foreach (var item in stages)
                    {
                        var note = entity.Database.SqlQuery <string>($"SELECT wartosc FROM oceny_etapow WHERE id_etap = {item.id_etap} AND id_prow = {_teaProfile.LoginModel.Teacher.id_prow} AND id_student = {idStudint}").ToList();
                        //StagesView.Items.Add(new Model.StageViewModel { Id = item.id_etap, Date = item.termin_etapu.ToString(), Stage = item.nazwa_etapu, Note = note.Count > 0 ? note[0] : "" });
                        _teaProfile.Stages.Add(new Models.TeacherModels.StageContext {
                            Stage = item, IDStudent = idStudint, Note = note.Count > 0 ? note[0] : ""
                        });
                    }
                }
                catch (Exception) { }
            }

            _teaProfile.Student.id_student = idStudint;

            return(View(_teaProfile));
        }
        public ActionResult ProjectDetails(string idSub)
        {
            int intID = Convert.ToInt32(idSub);



            using (var entity = new Data.TestEntities())
            {
                _stuProfile.ProjectDetails.Stages = new List <Models.TeacherModels.StageContext>();
                var stages = entity.etapy.Where(x => x.id_proj == intID);
                try
                {
                    foreach (var item in stages)
                    {
                        //StagesView.Items.Add(new Model.StageViewModel { Id = item.id_etap, Date = item.termin_etapu.ToString(), Stage = item.nazwa_etapu });

                        var note = entity.Database.SqlQuery <string>($"SELECT wartosc FROM oceny_etapow WHERE id_etap = {item.id_etap}").ToList();

                        _stuProfile.ProjectDetails.Stages.Add(new Models.TeacherModels.StageContext {
                            IDStudent = _stuProfile.LoginModel.Student.id_student, Stage = item,
                            Note      = note.Count > 0 ? note[0] : ""
                        });
                    }

                    _stuProfile.ProjectDetails.SubjectNote = entity.oceny_projektow.Where(x => x.id_student == _stuProfile.LoginModel.Student.id_student && x.id_proj == intID).FirstOrDefault().wartosc_oceny_proj;
                }
                catch (Exception) { }
            }

            return(View(_stuProfile));
        }
        public ActionResult ProjectsInClass(string idSub)
        {
            int idInt = Convert.ToInt32(idSub);

            _stuProfile.Projects = new List <Models.StudentModels.ProjectContext>();
            using (var entity = new Data.TestEntities())
            {
                //var projects = entity.projectsbyteacherandclass(_classe.id_zajec.ToString(),_classe.id_prow.ToString());

                try
                {
                    var projects = entity.projekty.Where(x => x.id_zajec == idInt);

                    foreach (var item in projects)
                    {
                        _stuProfile.Projects.Add(new Models.StudentModels.ProjectContext {
                            Id = item.id_proj, Project = item.nazwa_proj
                        });
                    }
                }
                catch (Exception)
                {
                }
            }

            return(View(_stuProfile));
        }
        public ActionResult Index()
        {
            _stuProfile.Classes = new List <Models.StudentModels.ClassContext>();
            using (var entity = new Data.TestEntities())
            {
                var stud_class = entity.zajecia.Where(x => x.studenci.Contains(entity.studenci.Where(u => u.id_student == _stuProfile.LoginModel.Student.id_student).FirstOrDefault()));


                try
                {
                    foreach (var item in stud_class)
                    {
                        _stuProfile.Classes.Add(new Models.StudentModels.ClassContext
                        {
                            Classe    = item,
                            ClassType = entity.typy_zajec.Where(x => x.id_typ == item.id_typ).FirstOrDefault(),
                            Subject   = entity.przedmioty.Where(x => x.id_przed == item.id_przed).FirstOrDefault(),
                            Teacher   = entity.prowadzacy.Where(a => a.id_prow == item.id_prow).FirstOrDefault()
                        });
                    }
                }
                catch (System.Exception)
                {
                }
            }
            return(View(_stuProfile));
        }
        public ActionResult UpdateStageNote(Models.TeacherModels.TeacherProfile prof)
        {
            using (var entity = new Data.TestEntities())
            {
                Data.oceny_etapow stageNote = new Data.oceny_etapow()
                {
                    id_prow    = _teaProfile.LoginModel.Teacher.id_prow,
                    wartosc    = prof.Note,
                    id_student = prof.Student.id_student,
                    id_etap    = prof.Stage.id_etap
                };


                var query =
                    "BEGIN "
                    + "IF NOT EXISTS(SELECT * FROM oceny_etapow "
                    + $"WHERE id_student = {prof.Student.id_student} "
                    + $"AND id_etap = {prof.Stage.id_etap} "
                    + $"AND id_prow = {_teaProfile.LoginModel.Teacher.id_prow}) "
                    + "BEGIN "
                    + $"INSERT INTO dbo.oceny_etapow (id_prow, id_student,id_etap, wartosc) VALUES({_teaProfile.LoginModel.Teacher.id_prow},{prof.Student.id_student},{prof.Stage.id_etap},'{prof.Note}')"
                    + " END"
                    + " ELSE"
                    + " BEGIN"
                    + $" UPDATE oceny_etapow SET wartosc = {prof.Note} WHERE id_student = {prof.Student.id_student} AND id_etap = {prof.Stage.id_etap} AND id_prow = {_teaProfile.LoginModel.Teacher.id_prow}"
                    + " END"
                    + " END";


                entity.Database.ExecuteSqlCommand(query);
            }


            return(RedirectToAction("StudentsInProject", _teaProfile));
        }
        public ActionResult CreateStudent(Models.SupervisorModels.SupervisorProfile _mod)
        {
            Console.WriteLine("Hello");

            using (var entity = new Data.TestEntities())
            {
                Data.studenci student = new Data.studenci()
                {
                    imie_student              = _mod.Student.imie_student,
                    nazwisko_student          = _mod.Student.nazwisko_student,
                    drugie_imie_student       = _mod.Student.drugie_imie_student,
                    id_grupy                  = _mod.Student.id_grupy,
                    email_student             = _mod.Student.email_student,
                    telefon_student           = _mod.Student.telefon_student,
                    pesel_student             = _mod.Student.pesel_student,
                    miejsce_urodzenia_student = _mod.Student.miejsce_urodzenia_student,
                    data_urodzenia_student    = _mod.Student.data_urodzenia_student,
                    nr_album                  = _mod.Student.nr_album
                };

                entity.studenci.Add(student);
                entity.SaveChanges();
            }
            return(RedirectToAction("Index", _supProfile));
        }
        public ActionResult DeleteStudentFromClass(string id, string idClass, string idGroup)
        {
            int idInt = Convert.ToInt32(id);

            _idClass = Convert.ToInt32(idClass);

            using (var entity = new Data.TestEntities())
            {
                try
                {
                    entity.zajecia.Where(x => x.id_zajec == _idClass).FirstOrDefault().studenci.Remove(entity.studenci.Where(y => y.id_student == idInt).FirstOrDefault());

                    entity.SaveChanges();
                }catch (Exception e)
                {
                    return(RedirectToAction("Error", _supProfile));
                }
            }
            _idGroup = Convert.ToInt32(idGroup);
            using (var entity = new Data.TestEntities())
            {
                _supProfile.StudentsContext = entity.studenci.Where(x => x.zajecia.Contains(entity.zajecia.Where(y => y.id_zajec == _idClass).FirstOrDefault())).ToList();
                _supProfile.StudentsInClass = entity.studenci.Where(x => x.id_grupy == _idGroup).ToList();
            }

            return(RedirectToAction("EditStudentsInClasses", _supProfile));
        }
        public ActionResult EditProject(string idProj)
        {
            if (idProj != null)
            {
                _idProjInt = Convert.ToInt32(idProj);
            }
            _teaProfile.Stages = new List <Models.TeacherModels.StageContext>();

            using (var entity = new Data.TestEntities())
            {
                var stages = entity.etapy.Where(x => x.id_proj == _idProjInt);
                try
                {
                    foreach (var item in stages)
                    {
                        _teaProfile.Stages.Add(new Models.TeacherModels.StageContext {
                            Stage = item
                        });
                    }
                }
                catch (Exception) { }
            }


            return(View(_teaProfile));
        }
        public ActionResult Edit(Models.SupervisorModels.SupervisorProfile prof)
        {
            Console.WriteLine("Hello");

            using (var entity = new Data.TestEntities())
            {
                var a = entity.studenci.Where(x => x.id_student == prof.Student.id_student).FirstOrDefault();

                a.imie_student              = prof.Student.imie_student;
                a.drugie_imie_student       = prof.Student.drugie_imie_student;
                a.nazwisko_student          = prof.Student.nazwisko_student;
                a.nr_album                  = prof.Student.nr_album;
                a.miejsce_urodzenia_student = prof.Student.miejsce_urodzenia_student;
                a.data_urodzenia_student    = Convert.ToDateTime(prof.Student.data_urodzenia_student);
                a.email_student             = prof.Student.email_student;
                a.id_grupy                  = prof.Student.id_grupy;
                a.pesel_student             = prof.Student.pesel_student;
                a.telefon_student           = prof.Student.telefon_student;


                entity.SaveChanges();
            }

            ViewBag.GroupList = GetGroupList();


            return(RedirectToAction("Index", _supProfile));
        }
        public ActionResult EditProject(Models.TeacherModels.TeacherProfile prof)
        {
            _teaProfile.Stages = new List <Models.TeacherModels.StageContext>();

            using (var entity = new Data.TestEntities())
            {
                var project = entity.projekty.Where(x => x.id_proj == prof.Project.id_proj).FirstOrDefault();

                project.nazwa_proj = prof.Project.nazwa_proj;
                project.termin_wyk = prof.Project.termin_wyk;

                entity.SaveChanges();

                var stages = entity.etapy.Where(x => x.id_proj == _idProjInt);

                foreach (var item in stages)
                {
                    _teaProfile.Stages.Add(new Models.TeacherModels.StageContext {
                        Stage = item
                    });
                }
            }


            return(View(_teaProfile));
        }
        public ActionResult TeaProjects()
        {
            ViewBag.ClassesProjectList = GetClassesByTeacherList(_teaProfile.LoginModel.Teacher.id_prow.ToString());
            _teaProfile.Projects       = new List <Models.TeacherModels.ProjectContext>();
            using (var entity = new Data.TestEntities())
            {
                var temp     = entity.projectsbyTeacher1(_teaProfile.LoginModel.Teacher.id_prow.ToString());
                var projects = entity.projekty.Where(x => x.id_prow == _teaProfile.LoginModel.Teacher.id_prow);

                try
                {
                    foreach (var item in projects)
                    {
                        var subject = entity.przedmioty.Where(x => x.id_przed == item.zajecia.przedmioty.id_przed).FirstOrDefault();
                        _teaProfile.Projects.Add(new Models.TeacherModels.ProjectContext {
                            ProjectName = item.nazwa_proj, SubjectName = subject.nazwa_przed, ID = item.id_proj
                        });
                    }
                }
                catch (Exception e) { }
            }


            return(View(_teaProfile));
        }
        public ActionResult StudentsInProject(string idProj)
        {
            if (idProj != null)
            {
                _idProjInt = Convert.ToInt32(idProj);
            }


            _teaProfile.StudentsInProject    = new List <Models.TeacherModels.StudentInProjectContext>();
            _teaProfile.ApplicationInProject = new List <Models.TeacherModels.ApplicationContext>();
            using (var entity = new Data.TestEntities())
            {
                //var students = entity.studenci.Where(x => x.projekty.Where(y => y.id_proj == _project.id_proj).FirstOrDefault().id_proj == _project.id_proj);

                //var students = entity.projekty.Where(e => e.id_proj == _project.id_proj).Select(e => e.studenci.All(x=>x.id_student));
                _teaProfile.Project = entity.projekty.Where(x => x.id_proj == _idProjInt).FirstOrDefault();


                try
                {
                    //var ids = entity.Database.SqlQuery<StudentsSchema>($"SELECT * FROM dbo.studenci_projekty WHERE id_proj='{_project.id_proj}'").ToList();
                    var ids = entity.Database.SqlQuery <StudentsSchema>($"SELECT * FROM dbo.studenci_projekty WHERE id_proj='{_idProjInt}'").ToList();
                    foreach (var item in ids)
                    {
                        var student = entity.studenci.Where(x => x.id_student == item.id_student).FirstOrDefault();
                        Data.oceny_projektow note = null;
                        note = entity.oceny_projektow.Where(x => x.id_student == item.id_student && x.id_proj == item.id_proj).FirstOrDefault();


                        _teaProfile.StudentsInProject.Add(new Models.TeacherModels.StudentInProjectContext {
                            IDProj = item.id_proj, IDStudent = item.id_student, Note = note != null ? note.wartosc_oceny_proj : "", StudentLastName = student.nazwisko_student, StudentName = student.imie_student
                        });
                    }
                }
                catch (Exception)
                {
                }

                var query = entity.Database.SqlQuery <Models.TeacherModels.ApplicationContext>($"SELECT * FROM dbo.zgloszenia WHERE id_proj = {_idProjInt}").ToList();

                try
                {
                    foreach (var item in query)
                    {
                        var student = entity.studenci.Where(x => x.id_student == item.id_student).FirstOrDefault();
                        //ApplicationsView.Items.Add(new Model.ApplicationViewModel { projId = item.id_proj, studId = item.id_student, Date = item.data_zgloszenia.ToString(), StudentName = student.imie_student, StudentLastName = student.nazwisko_student });
                        _teaProfile.ApplicationInProject.Add(new Models.TeacherModels.ApplicationContext {
                            id_student = item.id_student, Date = item.Date, id_proj = item.id_proj, StudentName = student.imie_student, StudentLastName = student.nazwisko_student
                        });
                    }
                }
                catch (Exception) { }
            }
            _teaProfile.Project.id_proj = Convert.ToInt32(idProj);


            return(View(_teaProfile));
        }
        public ActionResult Index()
        {
            using (var entity = new Data.TestEntities())
            {
                _teaProfile.Subjects = entity.przedmioty.Where(x => x.id_prow == _teaProfile.LoginModel.Teacher.id_prow).ToList();
            }

            return(View(_teaProfile));
        }
        public ActionResult EditGroup(string id)
        {
            using (var entity = new Data.TestEntities())
            {
                int idInt = Convert.ToInt32(id);
                _supProfile.Group = entity.grupy_dziekanskie.Where(x => x.id_grupy == idInt).FirstOrDefault();
            }

            return(View(_supProfile));
        }
        public ActionResult Index()
        {
            ViewBag.GroupList = GetGroupList();
            using (var entity = new Data.TestEntities())
            {
                _supProfile.StudentsContext = entity.studenci.ToList();
            }

            return(View(_supProfile));
        }
        public ActionResult AddGroupToClass(Models.SupervisorModels.SupervisorProfile prof)
        {
            using (var entity = new Data.TestEntities())
            {
                entity.zajecia.Where(x => x.id_zajec == prof.Classe.id_zajec).FirstOrDefault().grupy_dziekanskie.Add(entity.grupy_dziekanskie.Where(x => x.id_grupy == prof.Group.id_grupy).FirstOrDefault());

                entity.SaveChanges();
            }

            return(RedirectToAction("EditClass", new { id = prof.Classe.id_zajec }));
        }
        public ActionResult EditGroup(Models.SupervisorModels.SupervisorProfile prof)
        {
            using (var entity = new Data.TestEntities())
            {
                var a = entity.grupy_dziekanskie.Where(x => x.id_grupy == prof.Group.id_grupy).FirstOrDefault();

                a.nazwa_grupy = prof.Group.nazwa_grupy;

                entity.SaveChanges();
            }
            return(RedirectToAction("Groups", _supProfile));
        }
        public ActionResult EditTeacher(string id)
        {
            ViewBag.TeacherTypeList = GetTeacherTypeList();

            using (var entity = new Data.TestEntities())
            {
                int idInt = Convert.ToInt32(id);
                _supProfile.Teacher = entity.prowadzacy.Where(x => x.id_prow == idInt).FirstOrDefault();
            }

            return(View(_supProfile));
        }
        public ActionResult EditSubject(string id)
        {
            ViewBag.TeacherList = GetTeacherList();

            using (var entity = new Data.TestEntities())
            {
                int idInt = Convert.ToInt32(id);
                _supProfile.Subject = entity.przedmioty.Where(x => x.id_przed == idInt).FirstOrDefault();
            }

            return(View(_supProfile));
        }
        public ActionResult DeleteTeacher(string id)
        {
            using (var entity = new Data.TestEntities())
            {
                int idInt   = Convert.ToInt32(id);
                var teacher = entity.prowadzacy.Where(x => x.id_prow == idInt).FirstOrDefault();

                entity.prowadzacy.Remove(teacher);
                entity.SaveChanges();
            }

            return(RedirectToAction("Teacher", _supProfile));
        }
        public ActionResult Groups()
        {
            _supProfile.GroupContext = new List <Data.grupy_dziekanskie>();

            using (var entity = new Data.TestEntities())
            {
                foreach (var item in entity.grupy_dziekanskie)
                {
                    _supProfile.GroupContext.Add(item);
                }
            }
            return(View(_supProfile));
        }
        public ActionResult AddStudentToProject(Models.TeacherModels.TeacherProfile prof)
        {
            using (var entity = new Data.TestEntities())
            {
                entity.projekty.Where(x => x.id_proj == prof.Project.id_proj).FirstOrDefault().studenci.Add(entity.studenci.Where(a => a.id_student == prof.Student.id_student).FirstOrDefault());

                entity.SaveChanges();

                entity.Database.ExecuteSqlCommand($"DELETE FROM dbo.zgloszenia WHERE id_proj ={prof.Project.id_proj} and id_student = {prof.Student.id_student}");
            }


            return(RedirectToAction("StudentsInProject", _teaProfile));
        }
        public ActionResult CreateGroup(Models.SupervisorModels.SupervisorProfile _mod)
        {
            using (var entity = new Data.TestEntities())
            {
                Data.grupy_dziekanskie group = new Data.grupy_dziekanskie()
                {
                    nazwa_grupy = _mod.Group.nazwa_grupy
                };
                entity.grupy_dziekanskie.Add(group);
                entity.SaveChanges();
            }

            return(RedirectToAction("Groups", _supProfile));
        }
        public ActionResult ApplyToProject(string idSub)
        {
            int idInt = Convert.ToInt32(idSub);

            using (var entity = new Data.TestEntities())
            {
                var date = DateTime.Today.Day.ToString();
                //entity.projekty.Where(x => x.id_proj == project.id_proj).FirstOrDefault().studenci.Add(entity.studenci.Where(a => a.id_student == _student.id_student).FirstOrDefault());
                entity.Database.ExecuteSqlCommand($"INSERT INTO dbo.zgloszenia (id_student, id_proj, data_zgloszenia) VALUES({_stuProfile.LoginModel.Student.id_student},{idInt}, '{DateTime.Now}')");

                entity.SaveChanges();
            }

            return(RedirectToAction("Index", _stuProfile));
        }
        public ActionResult CreateSubject(Models.SupervisorModels.SupervisorProfile _mod)
        {
            using (var entity = new Data.TestEntities())
            {
                Data.przedmioty subject = new Data.przedmioty()
                {
                    nazwa_przed = _mod.Subject.nazwa_przed,
                    id_prow     = _mod.Subject.id_prow
                };

                entity.przedmioty.Add(subject);
                entity.SaveChanges();
            }
            return(RedirectToAction("Subjects", _supProfile));
        }
        public ActionResult Edit(string id)
        {
            ViewBag.GroupList = GetGroupList();

            //List<Data.studenci> students = new List<Data.studenci>();

            using (var entity = new Data.TestEntities())
            {
                int idInt = Convert.ToInt32(id);
                _supProfile.Student = entity.studenci.Where(x => x.id_student == idInt).FirstOrDefault();
            }


            return(View(_supProfile));
        }
        internal IEnumerable <SelectListItem> GetGroupList()
        {
            List <SelectListItem> temp = new List <SelectListItem>();

            using (var entity = new Data.TestEntities())
            {
                foreach (var item in entity.grupy_dziekanskie)
                {
                    temp.Add(new SelectListItem {
                        Text = item.nazwa_grupy, Value = item.id_grupy.ToString()
                    });
                }
            }
            return(temp);
        }
        internal IEnumerable <SelectListItem> GetClassTypeList()
        {
            List <SelectListItem> temp = new List <SelectListItem>();

            using (var entity = new Data.TestEntities())
            {
                foreach (var item in entity.typy_zajec)
                {
                    temp.Add(new SelectListItem {
                        Text = item.nazwa_typ, Value = item.id_typ.ToString()
                    });
                }
            }
            return(temp);
        }
        internal IEnumerable <SelectListItem> GetSubjectList()
        {
            List <SelectListItem> temp = new List <SelectListItem>();

            using (var entity = new Data.TestEntities())
            {
                foreach (var item in entity.przedmioty)
                {
                    temp.Add(new SelectListItem {
                        Text = item.nazwa_przed, Value = item.id_przed.ToString()
                    });
                }
            }
            return(temp);
        }
        internal IEnumerable <SelectListItem> GetTeacherTypeList()
        {
            List <SelectListItem> temp = new List <SelectListItem>();

            using (var entity = new Data.TestEntities())
            {
                foreach (var item in entity.typy_prowadzacych)
                {
                    temp.Add(new SelectListItem {
                        Text = item.typ_prowadzacy, Value = item.id_typ_prowadzacy.ToString()
                    });
                }
            }
            return(temp);
        }