public ActionResult Create(Supervisor supervisor)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }
            ViewData["Layout"] = AuthenticationController.GetUserLayout(HttpContext);

            if (!ModelState.IsValid)
            {
                return(View());
            }

            supervisor.User.Password = AuthenticationController.GetSha256FromString(supervisor.User.Password);

            using (var transaction = _context.Database.BeginTransaction())
            {
                _context.Users.Add(supervisor.User);
                _context.SaveChanges();

                _context.Supervisors.Add(supervisor);
                _context.SaveChanges();

                transaction.Commit();
            }

            return(RedirectToAction(nameof(Index)));
        }
        public ActionResult Delete(int id)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            var theses = _context.Theses
                         .Where(t => t.SuperId == id)
                         .ToList();

            foreach (var thesis in theses)
            {
                _context.Entry(thesis).State = EntityState.Deleted;
            }

            var supervisor = _context.Supervisors
                             .FirstOrDefault(s => s.Id == id);
            var user = _context.Users
                       .FirstOrDefault(u => u.Id == supervisor.UserId);

            _context.Entry(supervisor).State = EntityState.Deleted;
            _context.Entry(user).State       = EntityState.Deleted;
            _context.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
 public ActionResult Create()
 {
     if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
     {
         return(RedirectToAction("NotAuthorized", "Authentication"));
     }
     ViewData["Layout"] = AuthenticationController.GetUserLayout(HttpContext);
     return(View());
 }
        public IActionResult Index()
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            return(View());
        }
예제 #5
0
        public ActionResult Edit(StudentViewModel viewModel)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }
            ViewData["Layout"] = AuthenticationController.GetUserLayout(HttpContext);

            var enteredStudent = viewModel.Student;
            var enteredUser    = viewModel.Student.User;

            var student = _context.Students
                          .FirstOrDefault(s => s.Id == viewModel.Student.Id);
            var user = _context.Users
                       .FirstOrDefault(u => u.Id == student.UserId);

            if (!string.IsNullOrWhiteSpace(enteredUser.Email))
            {
                user.Email = enteredUser.Email;
            }
            if (!string.IsNullOrWhiteSpace(enteredUser.FirstName))
            {
                user.FirstName = enteredUser.FirstName;
            }
            if (!string.IsNullOrWhiteSpace(enteredUser.LastName))
            {
                user.LastName = enteredUser.LastName;
            }
            if (!string.IsNullOrWhiteSpace(enteredUser.Password))
            {
                if (enteredUser.Password != viewModel.ConfirmPassword)
                {
                    ViewData["Message"] = "Wpisane hasła nie są takie same";
                    return(View());
                }
                user.Password = AuthenticationController.GetSha256FromString(enteredUser.Password);
            }

            if (enteredStudent.SpecialtyId != student.SpecialtyId)
            {
                student.SpecialtyId = enteredStudent.SpecialtyId;
            }
            if (enteredStudent.DegreeCycle != student.DegreeCycle)
            {
                student.DegreeCycle = enteredStudent.DegreeCycle;
            }
            if (enteredStudent.StudentNo != student.StudentNo)
            {
                student.StudentNo = enteredStudent.StudentNo;
            }

            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
예제 #6
0
        public IActionResult removeThesis(int thesisId)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Supervisor))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            var thes = _context.Theses.FirstOrDefault(t => t.Id == thesisId);

            _context.Theses.Remove(thes);
            _context.SaveChanges();
            TempData["Success"] = "Temat został pomyślnie usunięty";
            return(RedirectToAction("Theses", "SupervisorHome"));
        }
예제 #7
0
        public IActionResult RemoveStudent(int thesisId)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            var thesis = _context.Theses
                         .FirstOrDefault(t => t.Id == thesisId);

            thesis.StudentId = null;
            _context.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
        public ActionResult Index()
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }
            ViewData["Layout"] = AuthenticationController.GetUserLayout(HttpContext);

            var supervisors = _context.Supervisors
                              .Include(s => s.User)
                              .Include(s => s.Faculty)
                              .OrderBy(s => s.Faculty.Name)
                              .ThenByDescending(s => s.StudentLimit)
                              .ToList();

            return(View(supervisors));
        }
예제 #9
0
        public ActionResult Index()
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            var students = _context.Students
                           .Include(s => s.User)
                           .Include(s => s.Specialty)
                           .Include(s => s.Specialty.Fac)
                           .OrderBy(s => s.Specialty.Fac.Name)
                           .ThenBy(s => s.Specialty.Name)
                           .ToList();

            return(View(students));
        }
        public ActionResult Edit(int id)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }
            ViewData["Layout"] = AuthenticationController.GetUserLayout(HttpContext);

            var supervisor = _context.Supervisors
                             .FirstOrDefault(s => s.Id == id);
            var user = _context.Users
                       .FirstOrDefault(u => u.Id == supervisor.UserId);

            supervisor.User = user;

            return(View(supervisor));
        }
예제 #11
0
        public IActionResult Index()
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Supervisor))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }
            var userId = HttpContext.Session.GetInt32("UserId");

            var supervisor = _context.Supervisors
                             .FirstOrDefault(s => (s.UserId == userId));

            supervisor.User = _context.Users
                              .FirstOrDefault(u => (u.Id == userId));

            supervisor.Faculty = _context.Faculties
                                 .FirstOrDefault(f => (f.Id == supervisor.FacultyId));

            return(View(supervisor));
        }
        public ActionResult Edit(Supervisor model)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            var supervisor = _context.Supervisors
                             .FirstOrDefault(s => s.Id == model.Id);
            var user = _context.Users
                       .FirstOrDefault(u => u.Id == model.UserId);

            if (model.User.FirstName != user.FirstName)
            {
                user.FirstName = model.User.FirstName;
            }
            if (model.User.LastName != user.LastName)
            {
                user.LastName = model.User.LastName;
            }
            if (model.User.Email != user.Email)
            {
                user.Email = model.User.Email;
            }
            if (!string.IsNullOrWhiteSpace(model.User.Password))
            {
                user.Password = AuthenticationController.GetSha256FromString(model.User.Password);
            }

            if (model.FacultyId != supervisor.FacultyId)
            {
                supervisor.FacultyId = model.FacultyId;
            }
            if (model.StudentLimit != supervisor.StudentLimit)
            {
                supervisor.StudentLimit = model.StudentLimit;
            }

            _context.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
예제 #13
0
        public ActionResult Edit(int id)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }
            ViewData["Layout"] = AuthenticationController.GetUserLayout(HttpContext);

            var student = _context.Students
                          .FirstOrDefault(s => s.Id == id);

            student.User = _context.Users
                           .FirstOrDefault(u => u.Id == student.UserId);
            student.Specialty = _context.Specialties
                                .FirstOrDefault(s => s.Id == student.SpecialtyId);

            return(View(new StudentViewModel {
                Student = student
            }));
        }
예제 #14
0
        public IActionResult CreateThesis(int supersId, string thesisSubject)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Student))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            var userId = HttpContext.Session.GetInt32("UserId");

            var stud = _context.Students
                       .FirstOrDefault(s => s.UserId == userId);

            var thesis = new Thesis {
                Subject = thesisSubject, DegreeCycle = stud.DegreeCycle, SpecId = stud.SpecialtyId, SuperId = supersId, StudentId = stud.Id
            };

            _context.Add(thesis);
            _context.SaveChanges();
            return(RedirectToAction("Index", "StudentHome"));
        }
예제 #15
0
        public ActionResult Index()
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            var theses = _context.Theses
                         .Include(t => t.Super)
                         .Include(t => t.Super.User)
                         .Include(t => t.Student)
                         .Include(t => t.Student.User)
                         .Include(t => t.Spec)
                         .Include(t => t.Spec.Fac)
                         .OrderBy(t => (t.Student == null))
                         .ThenBy(t => t.Spec.Fac.Name)
                         .ThenBy(t => t.Spec.Name)
                         .ToList();

            return(View(theses));
        }
예제 #16
0
        public ActionResult Create(StudentViewModel model)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Admin))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }
            ViewData["Layout"] = AuthenticationController.GetUserLayout(HttpContext);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var enteredStudent = model.Student;
            var enteredUser    = model.Student.User;

            using (var transaction = _context.Database.BeginTransaction())
            {
                var matchedUser = _context.Users
                                  .FirstOrDefault(u => (u.Email == model.Student.User.Email));
                if (matchedUser != null)
                {
                    ViewData["Message"] = "Taki użytkownik istnieje już w systemie!";
                    return(View(model));
                }

                enteredUser.Password = AuthenticationController.GetSha256FromString(enteredUser.Password);

                _context.Users.Add(enteredUser);
                _context.SaveChanges();

                model.Student.UserId = enteredUser.Id;
                _context.Students.Add(enteredStudent);
                _context.SaveChanges();

                transaction.Commit();
            }
            return(RedirectToAction(nameof(Index)));
        }
예제 #17
0
        public IActionResult Index()
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Student))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }
            int?userId = HttpContext.Session.GetInt32("UserId");

            var user = _context.Users
                       .FirstOrDefault(u => (u.Id == userId));
            var student = _context.Students
                          .FirstOrDefault(s => (s.UserId == userId));

            student.Specialty = _context.Specialties
                                .FirstOrDefault(s => s.Id == student.SpecialtyId);
            student.Specialty.Fac = _context.Faculties
                                    .FirstOrDefault(f => f.Id == student.Specialty.FacId);

            var thesis = _context.Theses
                         .FirstOrDefault(t => (t.StudentId == student.Id)) ?? new Thesis {
                Id = 0, Subject = "Brak Wybranej Pracy"
            };
            var supervisorUser = new User {
                FirstName = "Brak", LastName = "Promotora"
            };

            if (thesis.Id != 0)
            {
                supervisorUser = _context.Supervisors
                                 .Where(s => s.Id == thesis.SuperId)
                                 .Include(s => s.User)
                                 .Select(s => s.User)
                                 .FirstOrDefault();
            }

            return(View(new StudentPanelViewModel {
                User = user, Student = student, Thesis = thesis, Supervisor = supervisorUser
            }));
        }
예제 #18
0
        public IActionResult ReserveThesis(int thesisId)
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Student))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            var userId = HttpContext.Session.GetInt32("UserId");

            var chosenThesis = _context.Theses
                               .FirstOrDefault(t => t.Id == thesisId && t.StudentId == null);

            if (chosenThesis == null)
            {
                TempData["Error"] = "Ten temat został właśnie zajęty";
                return(RedirectToAction("Index"));
            }

            var supervisor = _context.Supervisors
                             .FirstOrDefault(s => s.Id == chosenThesis.SuperId);
            var supervisorThesesWithStudentsCount = _context.Theses
                                                    .Count(t => t.SuperId == chosenThesis.SuperId && t.StudentId != null);

            if (supervisorThesesWithStudentsCount >= supervisor.StudentLimit)
            {
                TempData["Error"] = "Ten promotor ma już maksymalną ilość studentów";
                return(RedirectToAction("Index"));
            }

            var loggedStudent = _context.Students
                                .FirstOrDefault(s => s.UserId == userId);

            chosenThesis.StudentId = loggedStudent.Id;
            _context.SaveChanges();

            TempData["Success"] = "Temat został pomyślnie przydzielony";
            return(RedirectToAction("Index", "StudentHome"));
        }
예제 #19
0
        public IActionResult Theses()
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Supervisor))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }
            var userId = HttpContext.Session.GetInt32("UserId");

            var super = _context.Supervisors
                        .FirstOrDefault(s => s.UserId == userId);

            var students = _context.Students
                           .Include(s => s.ChosenThesis)
                           .Include(s => s.User)
                           .Include(s => s.ChosenThesis.Spec)
                           .Where(s => s.ChosenThesis.SuperId == super.Id);

            var thesesNotChosen = _context.Theses
                                  .Where(t => t.SuperId == super.Id && t.StudentId == null)
                                  .Include(t => t.Spec)
                                  .ToList();

            var specialtiesForSupervisor = from s in _context.Specialties
                                           join f in _context.Faculties on s.FacId equals f.Id
                                           where f.Id == super.FacultyId
                                           select new Specialty
            {
                Id   = s.Id,
                Name = s.Name
            };

            return(View(new SupervisorPanelViewModel {
                Students = students,
                ThesesNotChosen = thesesNotChosen,
                SpecialitiesForSupervisor = specialtiesForSupervisor
            }));
        }
예제 #20
0
        public IActionResult Theses()
        {
            if (!AuthenticationController.IsUserAuthorized(HttpContext, AuthenticationController.UserRole.Student))
            {
                return(RedirectToAction("NotAuthorized", "Authentication"));
            }

            int?userId = HttpContext.Session.GetInt32("UserId");

            var loggedStudent = _context.Students
                                .FirstOrDefault(s => s.UserId == userId);

            loggedStudent.Specialty = _context.Specialties
                                      .FirstOrDefault(s => s.Id == loggedStudent.SpecialtyId);

            var chosenThesis = _context.Theses
                               .FirstOrDefault(t => t.StudentId == loggedStudent.Id);

            if (chosenThesis != null)
            {
                TempData["Error"] = "Wybrałeś już temat pracy! W razie problemów skontaktuj się ze swoim promotorem.";
                return(RedirectToAction("Index", "StudentHome"));
            }

            int specialtyId = loggedStudent.SpecialtyId;
            int degreeCycle = loggedStudent.DegreeCycle;
            int facultyId   = loggedStudent.Specialty.FacId;

            var supervisorsByStudentCounts = _context.Supervisors
                                             .Where(s => s.FacultyId == facultyId)
                                             .ToDictionary(s => s.Id, s => 0);

            var studentCounts = (
                from s in _context.Supervisors
                join t in _context.Theses on s.Id equals t.SuperId
                where s.FacultyId == facultyId && t.StudentId != null
                select new { superId = s.Id, thesisId = t.Id }
                into x
                group x by x.superId
                into g
                select new
            {
                SupervisorId = g.Key,
                ThesisCount = g.Count()
            }).ToList();

            foreach (var entry in studentCounts)
            {
                supervisorsByStudentCounts[entry.SupervisorId] = entry.ThesisCount;
            }

            var supers = _context.Supervisors
                         .Where(s => s.FacultyId == facultyId && supervisorsByStudentCounts[s.Id] < s.StudentLimit)
                         .Include(s => s.User)
                         .ToList();

            return(View(new ThesesListViewModel
            {
                Supervisors = supers,
                SupervisorsByStudentCounts = supervisorsByStudentCounts,
                FacultyId = facultyId,
                SpecialtyId = specialtyId,
                DegreeCycle = degreeCycle
            }));
        }