public IActionResult Register(RegisterStudentViewModel model) { model.Faculties = _context.Faculties.ToList(); if (!ModelState.IsValid) { return(View(model)); } using (var transaction = _context.Database.BeginTransaction()) { var matchedUser = _context.Users .FirstOrDefault(u => (u.Email == model.User.Email)); if (matchedUser != null) { ViewData["Message"] = "Taki u¿ytkownik istnieje ju¿ w systemie!"; return(View(model)); } model.User.Password = GetSha256FromString(model.User.Password); _context.Users.Add(model.User); _context.SaveChanges(); model.Student.UserId = model.User.Id; _context.Students.Add(model.Student); _context.SaveChanges(); transaction.Commit(); HttpContext.Session.SetString("UserRole", "student"); } TempData["Message"] = "Pomyœlnie zarejestrowano"; return(RedirectToAction("Login", "Authentication")); }
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 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")); }
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")); }
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 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))); }