public ActionResult Edit(int id, AdminControllerAdminVM model) { AdministratorRepository adminRepository = new AdministratorRepository(); TryUpdateModel(model); if (ModelState.IsValid) { Administrator admin = null; if (adminRepository.GetAll(filter: a => a.UserName == model.UserName).FirstOrDefault() == null) { admin = new Administrator(); admin.UserName = model.UserName; admin.Password = SecurityService.CreateHash(model.Password); admin.FirstName = model.FirstName; admin.LastName = model.LastName; admin.IsActive = true; adminRepository.Save(admin); return(RedirectToAction("ManageAdministrators")); } else { throw new ArgumentException("Invalid username !"); } } return(View(model)); }
public bool AuthenticateUser(string username, string password, User.UserType userType) { switch (userType) { case User.UserType.Teacher: TeacherRepository teacherRepository = new TeacherRepository(); user = teacherRepository.GetAll(filter: u => u.UserName == username && u.IsActive == true).FirstOrDefault(); break; case User.UserType.Administrator: AdministratorRepository adminRepository = new AdministratorRepository(); user = adminRepository.GetAll(filter: u => u.UserName == username && u.IsActive == true).FirstOrDefault(); break; case User.UserType.Student: StudentRepository studentRepository = new StudentRepository(); user = studentRepository.GetAll(filter: u => u.UserName == username && u.IsActive == true).FirstOrDefault(); break; default: LoggedUser = null; break; } if (SecurityService.ValidatePassword(password, user.Password)) LoggedUser = user; return LoggedUser != null; }
public bool AuthenticateUser(string username, string password, User.UserType userType) { switch (userType) { case User.UserType.Teacher: TeacherRepository teacherRepository = new TeacherRepository(); user = teacherRepository.GetAll(filter: u => u.UserName == username && u.IsActive == true).FirstOrDefault(); break; case User.UserType.Administrator: AdministratorRepository adminRepository = new AdministratorRepository(); user = adminRepository.GetAll(filter: u => u.UserName == username && u.IsActive == true).FirstOrDefault(); break; case User.UserType.Student: StudentRepository studentRepository = new StudentRepository(); user = studentRepository.GetAll(filter: u => u.UserName == username && u.IsActive == true).FirstOrDefault(); break; default: LoggedUser = null; break; } if (SecurityService.ValidatePassword(password, user.Password)) { LoggedUser = user; } return(LoggedUser != null); }
public ActionResult ManageAdministrators() { AdminControllerAdminVM adminModel = new AdminControllerAdminVM(); AdministratorRepository adminRepository = new AdministratorRepository(); adminModel.administratorList = adminRepository.GetAll(); return(View(adminModel)); }
public void AddAdministrator() { var options = new DbContextOptionsBuilder <BetterCalmContext>() .UseInMemoryDatabase(databaseName: "MSP.BetterCalmDatabase").Options; var context = new BetterCalmContext(options); context.Add(listAdministrators[0]); context.SaveChanges(); repository = new AdministratorRepository(context); var initial = repository.GetAll().Count(); repository.Add(listAdministrators[1]); var final = repository.GetAll().Count(); context.Database.EnsureDeleted(); Assert.AreEqual(initial + 1, final); }
public static IEnumerable <Administrator> GetAll() { try { AdministratorRepository _AdministratorRepository = new AdministratorRepository(); return(_AdministratorRepository.GetAll <Administrator>()); } catch (Exception ex) { throw ex; } }
public void TestAdministratorGetAllOK() { IMMRequestContext IMMRequestContext = ContextFactory.GetNewContext(); AdministratorRepository adminRepo = new AdministratorRepository(IMMRequestContext); adminRepo.Add(new Administrator { Id = Guid.NewGuid(), Name = "Just Testing", Email = "*****@*****.**", Password = "******" }); adminRepo.Save(); var admins = adminRepo.GetAll().ToList().Count(); Assert.AreEqual(1, admins); }
public void IsGetableAll() { List <Administrator> list = repository.GetAll(); Assert.NotNull(list, "List wasn't received"); }
public ActionResult ManageAdministrators() { AdminControllerAdminVM adminModel = new AdminControllerAdminVM(); AdministratorRepository adminRepository = new AdministratorRepository(); adminModel.administratorList = adminRepository.GetAll(); return View(adminModel); }
public ActionResult Edit(int id, AdminControllerAdminVM model) { AdministratorRepository adminRepository = new AdministratorRepository(); TryUpdateModel(model); if (ModelState.IsValid) { Administrator admin = null; if (adminRepository.GetAll(filter: a => a.UserName == model.UserName).FirstOrDefault() == null) { admin = new Administrator(); admin.UserName = model.UserName; admin.Password = SecurityService.CreateHash(model.Password); admin.FirstName = model.FirstName; admin.LastName = model.LastName; admin.IsActive = true; adminRepository.Save(admin); return RedirectToAction("ManageAdministrators"); } else { throw new ArgumentException("Invalid username !"); } } return View(model); }
public JsonResult CheckForExistingName(string name, string type, int id) { bool exist = false; switch (type) { case "Admin": Administrator admin = new Administrator(); AdministratorRepository adminRepository = new AdministratorRepository(); admin = adminRepository.GetAll(filter: a => a.UserName == name && a.Id != id).FirstOrDefault(); if (admin != null) { exist = true; }; break; case "Student": Student student = new Student(); StudentRepository studentRepository = new StudentRepository(); student = studentRepository.GetAll(filter: s => s.UserName == name && s.Id != id).FirstOrDefault(); if (student != null) { exist = true; }; break; case "Teacher": Teacher teacher = new Teacher(); TeacherRepository teacherRepository = new TeacherRepository(); teacher = teacherRepository.GetAll(filter: t => t.UserName == name && t.Id != id).FirstOrDefault(); if (teacher != null) { exist = true; }; break; case "Course": Course course = new Course(); CourseRepository courseRepository = new CourseRepository(); course = courseRepository.GetAll(filter: c => c.Name == name).FirstOrDefault(); if (course != null) { exist = true; }; break; case "Title": Title title = new Title(); TitleRepository titleRepository = new TitleRepository(); title = titleRepository.GetAll(filter: t => t.Name == name).FirstOrDefault(); if (title != null) { exist = true; }; break; case "Subject": Subject subject = new Subject(); SubjectRepository subjectRepository = new SubjectRepository(); subject = subjectRepository.GetAll(filter: s => s.Name == name).FirstOrDefault(); if (subject != null) { exist = true; }; break; } return Json(exist, JsonRequestBehavior.AllowGet); }
public JsonResult CheckForExistingName(string name, string type, int id) { bool exist = false; switch (type) { case "Admin": Administrator admin = new Administrator(); AdministratorRepository adminRepository = new AdministratorRepository(); admin = adminRepository.GetAll(filter: a => a.UserName == name && a.Id != id).FirstOrDefault(); if (admin != null) { exist = true; } ; break; case "Student": Student student = new Student(); StudentRepository studentRepository = new StudentRepository(); student = studentRepository.GetAll(filter: s => s.UserName == name && s.Id != id).FirstOrDefault(); if (student != null) { exist = true; } ; break; case "Teacher": Teacher teacher = new Teacher(); TeacherRepository teacherRepository = new TeacherRepository(); teacher = teacherRepository.GetAll(filter: t => t.UserName == name && t.Id != id).FirstOrDefault(); if (teacher != null) { exist = true; } ; break; case "Course": Course course = new Course(); CourseRepository courseRepository = new CourseRepository(); course = courseRepository.GetAll(filter: c => c.Name == name).FirstOrDefault(); if (course != null) { exist = true; } ; break; case "Title": Title title = new Title(); TitleRepository titleRepository = new TitleRepository(); title = titleRepository.GetAll(filter: t => t.Name == name).FirstOrDefault(); if (title != null) { exist = true; } ; break; case "Subject": Subject subject = new Subject(); SubjectRepository subjectRepository = new SubjectRepository(); subject = subjectRepository.GetAll(filter: s => s.Name == name).FirstOrDefault(); if (subject != null) { exist = true; } ; break; } return(Json(exist, JsonRequestBehavior.AllowGet)); }