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 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 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 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 RedirectResult _initTeacher(string id)
        {
            int idInt = Convert.ToInt32(id);

            _teaProfile = new Models.TeacherModels.TeacherProfile();
            using (var entity = new Data.TestEntities())
            {
                _teaProfile.LoginModel = new Models.LoginUser()
                {
                    Teacher = entity.prowadzacy.Where(x => x.id_prow == idInt).FirstOrDefault()
                };

                _teaProfile.Subjects = new List <Data.przedmioty>();
            }


            return(Redirect("~/Teacher/Index"));
        }
        public ActionResult AddSubjectNote(Models.TeacherModels.TeacherProfile prof)
        {
            using (var entity = new Data.TestEntities())
            {
                var query =
                    "BEGIN "
                    + "IF NOT EXISTS(SELECT * FROM oceny_przedmiotow "
                    + $"WHERE id_student = {prof.Student.id_student} "
                    + $"AND id_przed = {_idSubInt} "
                    + $"AND id_prow = {_teaProfile.LoginModel.Teacher.id_prow}) "
                    + "BEGIN "
                    + $"INSERT INTO oceny_przedmiotow (id_student, id_przed, id_prow, wartosc_pceny_przedmiot) VALUES ('{prof.Student.id_student}', '{_idSubInt}', '{_teaProfile.LoginModel.Teacher.id_prow}', '{prof.Note}')"
                    + " END"
                    + " ELSE"
                    + " BEGIN"
                    + $" UPDATE oceny_przedmiotow SET wartosc_pceny_przedmiot = {prof.Note} WHERE id_student = {prof.Student.id_student} AND id_prow = {_teaProfile.LoginModel.Teacher.id_prow} AND id_przed = {_idSubInt}"
                    + " END"
                    + " END";
                entity.Database.ExecuteSqlCommand(query);
            }

            return(RedirectToAction("StudentsInSubject", _teaProfile));
        }