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 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 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 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 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 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 EditSubject(Models.SupervisorModels.SupervisorProfile prof)
        {
            Console.WriteLine("Hello");

            using (var entity = new Data.TestEntities())
            {
                var a = entity.przedmioty.Where(x => x.id_przed == prof.Subject.id_przed).FirstOrDefault();

                a.id_prow     = prof.Subject.id_prow;
                a.nazwa_przed = prof.Subject.nazwa_przed;

                entity.SaveChanges();
            }

            return(RedirectToAction("Subjects", _supProfile));
        }
        public ActionResult EditClass(Models.SupervisorModels.SupervisorProfile prof)
        {
            using (var entity = new Data.TestEntities())
            {
                var a = entity.zajecia.Where(x => x.id_zajec == prof.Classe.id_zajec).FirstOrDefault();

                a.data_zaj = prof.Classe.data_zaj;
                a.id_prow  = prof.Classe.id_prow;
                a.id_przed = prof.Classe.id_przed;
                a.id_typ   = prof.Classe.id_typ;


                entity.SaveChanges();
            }
            return(RedirectToAction("Classes", _supProfile));
        }
        public ActionResult CreateStage(Models.TeacherModels.TeacherProfile prof)
        {
            using (var entity = new Data.TestEntities())
            {
                Data.etapy stage = new Data.etapy()
                {
                    id_proj      = _idProjInt,
                    nazwa_etapu  = prof.Stage.nazwa_etapu,
                    termin_etapu = prof.Stage.termin_etapu
                };

                entity.etapy.Add(stage);
                entity.SaveChanges();
            }

            return(RedirectToAction("EditProject", _teaProfile));
        }
        public ActionResult CreateProject(Models.TeacherModels.TeacherProfile prof)
        {
            using (var entity = new Data.TestEntities())
            {
                Data.projekty project = new Data.projekty()
                {
                    nazwa_proj = prof.Project.nazwa_proj,
                    termin_wyk = Convert.ToDateTime(prof.Project.termin_wyk),
                    id_zajec   = prof.Classe.id_zajec,
                    id_prow    = _teaProfile.LoginModel.Teacher.id_prow
                };

                entity.projekty.Add(project);
                entity.SaveChanges();
            }

            return(RedirectToAction("TeaProjects", _teaProfile));
        }
        public ActionResult DeleteStudent(string id)
        {
            using (var entity = new Data.TestEntities())
            {
                int idInt   = Convert.ToInt32(id);
                var student = entity.studenci.Where(x => x.id_student == idInt).FirstOrDefault();
                try
                {
                    entity.studenci.Remove(student);
                    entity.SaveChanges();
                }catch (Exception e)
                {
                    return(RedirectToAction("Error", _supProfile));
                }
            }

            return(RedirectToAction("Index", _supProfile));
        }
        public ActionResult CreateClass(Models.SupervisorModels.SupervisorProfile _mod)
        {
            using (var entity = new Data.TestEntities())
            {
                Data.zajecia classe = new Data.zajecia()
                {
                    data_zaj = _mod.Classe.data_zaj,
                    id_prow  = _mod.Classe.id_prow,
                    id_przed = _mod.Classe.id_przed,
                    id_typ   = _mod.Classe.id_typ,
                    id_zajec = _mod.Classe.id_zajec
                };

                entity.zajecia.Add(classe);
                entity.SaveChanges();

                return(RedirectToAction("Classes", _supProfile));
            }
        }
        public ActionResult DeleteClass(string id)
        {
            using (var entity = new Data.TestEntities())
            {
                int idInt  = Convert.ToInt32(id);
                var classe = entity.zajecia.Where(x => x.id_zajec == idInt).FirstOrDefault();


                try
                {
                    entity.zajecia.Remove(classe);
                    entity.SaveChanges();
                }catch (Exception e)
                {
                    return(RedirectToAction("Error", _supProfile));
                }
            }
            return(RedirectToAction("Classes", _supProfile));
        }
        public ActionResult AddStudentToClass(Models.SupervisorModels.SupervisorProfile prof)
        {
            _idClass = Convert.ToInt32(prof.Classe.id_zajec);
            using (var entity = new Data.TestEntities())
            {
                entity.zajecia.Where(x => x.id_zajec == prof.Classe.id_zajec).FirstOrDefault().studenci.Add(entity.studenci.Where(y => y.id_student == prof.Student.id_student).FirstOrDefault());

                entity.SaveChanges();

                _supProfile.Classe.id_zajec = prof.Classe.id_zajec;
            }
            _idGroup = Convert.ToInt32(prof.Group.id_grupy);
            using (var entity = new Data.TestEntities())
            {
                _supProfile.StudentsContext = entity.studenci.Where(x => x.zajecia.Contains(entity.zajecia.Where(y => y.id_zajec == _supProfile.Classe.id_zajec).FirstOrDefault())).ToList();
                _supProfile.StudentsInClass = entity.studenci.Where(x => x.id_grupy == _supProfile.Group.id_grupy).ToList();
            }

            return(RedirectToAction("EditStudentsInClasses", _supProfile));
        }
        public ActionResult DeleteGroup(string id)
        {
            int idInt = Convert.ToInt32(id);

            using (var entity = new Data.TestEntities())
            {
                var group = entity.grupy_dziekanskie.Where(x => x.id_grupy == idInt).FirstOrDefault();


                try
                {
                    entity.grupy_dziekanskie.Remove(group);
                    entity.SaveChanges();
                }
                catch (Exception e)
                {
                    return(RedirectToAction("Error", _supProfile));
                }
            }
            return(RedirectToAction("Groups", _supProfile));
        }
        public ActionResult EditTeacher(Models.SupervisorModels.SupervisorProfile prof)
        {
            using (var entity = new Data.TestEntities())
            {
                var a = entity.prowadzacy.Where(x => x.id_prow == prof.Teacher.id_prow).FirstOrDefault();

                a.haslo                        = prof.Teacher.haslo;
                a.imie_prowadzacy              = prof.Teacher.imie_prowadzacy;
                a.nazwisko_prowadzacy          = prof.Teacher.nazwisko_prowadzacy;
                a.data_urodzenia_prowadzacy    = prof.Teacher.data_urodzenia_prowadzacy;
                a.drugie_imie_prowadzacy       = prof.Teacher.drugie_imie_prowadzacy;
                a.id_typ_prowadzacy            = prof.Teacher.id_typ_prowadzacy;
                a.miejsce_urodzenia_prowadzacy = prof.Teacher.miejsce_urodzenia_prowadzacy;
                a.email_prowadzacy             = prof.Teacher.email_prowadzacy;
                a.telefon_prowadzacy           = prof.Teacher.telefon_prowadzacy;
                a.pesel_prowadzacy             = prof.Teacher.pesel_prowadzacy;

                entity.SaveChanges();
            }
            ViewBag.TeacherTypeList = GetTeacherTypeList();
            return(RedirectToAction("Teacher", _supProfile));
        }
        public ActionResult CreateTeacher(Models.SupervisorModels.SupervisorProfile _mod)
        {
            using (var entity = new Data.TestEntities())
            {
                Data.prowadzacy teacher = new Data.prowadzacy()
                {
                    haslo                        = _mod.Teacher.haslo,
                    imie_prowadzacy              = _mod.Teacher.imie_prowadzacy,
                    nazwisko_prowadzacy          = _mod.Teacher.nazwisko_prowadzacy,
                    data_urodzenia_prowadzacy    = _mod.Teacher.data_urodzenia_prowadzacy,
                    drugie_imie_prowadzacy       = _mod.Teacher.drugie_imie_prowadzacy,
                    id_typ_prowadzacy            = _mod.Teacher.id_typ_prowadzacy,
                    miejsce_urodzenia_prowadzacy = _mod.Teacher.miejsce_urodzenia_prowadzacy,
                    email_prowadzacy             = _mod.Teacher.email_prowadzacy,
                    telefon_prowadzacy           = _mod.Teacher.telefon_prowadzacy,
                    pesel_prowadzacy             = _mod.Teacher.pesel_prowadzacy,
                };

                entity.prowadzacy.Add(teacher);
                entity.SaveChanges();
            }
            return(RedirectToAction("Teacher", _supProfile));
        }