public IActionResult Index() { if (!Middleware.CheckUserPermission(PermissionType.None, HttpContext)) { return(RedirectToAction("Login", "User")); } BookIndexViewModel bivm = new BookIndexViewModel(); bivm.Books = new List <BookModel>(); foreach (Book book in BookContainer.GetNewestBooks(8)) { BookModel temp = new BookModel(); temp.Id = book.Id; temp.Name = book.Name; temp.Price = book.Price; temp.QualityRating = book.QualityRating; bivm.Books.Add(temp); } return(View(bivm)); }
public IActionResult Index() { if (!Middleware.CheckUserPermission(PermissionType.Admin, HttpContext)) { return(RedirectToAction("Login", "User")); } List <Course> courses = CourseContainer.GetAll(); // FIXME: Kan dit beter ? CourseListViewModel slvm = new CourseListViewModel(); slvm.Courses = new List <CourseModel>(); foreach (Course course in courses) { CourseModel temp = new CourseModel(); temp.Id = course.Id; temp.Name = course.Name; slvm.Courses.Add(temp); } return(View(slvm)); }
public IActionResult Index() { if (!Middleware.CheckUserPermission(PermissionType.Admin, HttpContext)) { return(RedirectToAction("Login", "User")); } List <Sector> sectors = SectorContainer.GetAll(); // FIXME: Kan dit beter ? SectorListViewModel slvm = new SectorListViewModel(); slvm.Sectors = new List <SectorModel>(); foreach (Sector sector in sectors) { SectorModel temp = new SectorModel(); temp.Id = sector.Id; temp.Name = sector.Name; slvm.Sectors.Add(temp); } return(View(slvm)); }
public IActionResult Edit(int id) { if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext)) { return(RedirectToAction("Login", "User")); } Book book = BookContainer.GetBookById(id); // FIXME: Hoe kan dit beter? BookModel bookModel = new BookModel(); bookModel.Id = book.Id; bookModel.User = new UserModel(); bookModel.User.Id = book.User.Id; bookModel.User.FirstName = book.User.FirstName; bookModel.User.Insertion = book.User.Insertion; bookModel.User.LastName = book.User.LastName; bookModel.User.Email = book.User.Email; bookModel.Course = new CourseModel(); bookModel.Course.Id = book.Course.Id; bookModel.Course.Name = book.Course.Name; bookModel.Sector = new SectorModel(); bookModel.Sector.Id = book.Sector.Id; bookModel.Sector.Name = book.Sector.Name; bookModel.Name = book.Name; bookModel.Price = book.Price; bookModel.QualityRating = book.QualityRating; return(View(bookModel)); }
public IActionResult Create() { if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext)) { return(RedirectToAction("Login", "User")); } return(View()); }
public IActionResult Create(SectorModel sectorModel) { if (!Middleware.CheckUserPermission(PermissionType.Admin, HttpContext)) { return(RedirectToAction("Login", "User")); } SectorContainer.Save(sectorModel); return(RedirectToAction("Index")); }
public IActionResult Create(BookModel book) { if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext)) { return(RedirectToAction("Login", "User")); } BookContainer.Save(book); return(RedirectToAction("Index")); }
public IActionResult Logout() { if (!Middleware.CheckUserPermission(PermissionType.None, HttpContext)) { return(RedirectToAction("Login", "User")); } SessionHandler.ClearSession(HttpContext); return(RedirectToAction("Index", "Home")); }
public IActionResult Remove(int id) { if (!Middleware.CheckUserPermission(PermissionType.Admin, HttpContext)) { return(RedirectToAction("Login", "User")); } // TODO: Add validation message SectorContainer.Remove(id, SessionHandler.GetUserID(HttpContext)); return(RedirectToAction("Index")); }
public IActionResult Edit(SectorModel sectorModel) { if (!Middleware.CheckUserPermission(PermissionType.Admin, HttpContext)) { return(RedirectToAction("Login", "User")); } if (SectorContainer.Update(sectorModel)) { return(RedirectToAction("Index")); } return(RedirectToAction("Edit", sectorModel.Id)); }
public IActionResult Register() { if (!Middleware.CheckUserPermission(PermissionType.None, HttpContext)) { return(RedirectToAction("Login", "User")); } if (SessionHandler.GetUserID(HttpContext) != 0) { return(RedirectToAction("Index", "Home")); } return(View()); }
public IActionResult Login(UserLoginModel userLoginModel) { if (!Middleware.CheckUserPermission(PermissionType.None, HttpContext)) { return(RedirectToAction("Login", "User")); } // TODO: Hash the password; User user = UserContainer.GetByEmailAndPassword(userLoginModel); SessionHandler.SetUserId(user.Id, HttpContext); SessionHandler.SetPermission(user.Permission, HttpContext); return(Redirect(Request.Headers["Referer"].ToString())); }
public IActionResult Edit(int id) { if (!Middleware.CheckUserPermission(PermissionType.Admin, HttpContext)) { return(RedirectToAction("Login", "User")); } Course course = CourseContainer.GetCourseById(id); CourseModel courseModel = new CourseModel(); courseModel.Id = course.Id; courseModel.Name = course.Name; return(View(courseModel)); }
public IActionResult Edit(int id) { if (!Middleware.CheckUserPermission(PermissionType.Admin, HttpContext)) { return(RedirectToAction("Login", "User")); } Sector sector = SectorContainer.GetSectorById(id); SectorModel sectorModel = new SectorModel(); sectorModel.Id = sector.Id; sectorModel.Name = sector.Name; return(View(sectorModel)); }
public void UserCanGoToUserPage() { // Arrange PermissionType currentPermissionType = PermissionType.User; PermissionType neededPermissiongType = PermissionType.User; var mockSessionHandler = new Mock <ISessionHandler>(); mockSessionHandler.Setup(m => m.GetPermissionType(It.IsAny <HttpContext>())).Returns(currentPermissionType); Middleware middleware = new Middleware(mockSessionHandler.Object); // Act bool result = middleware.CheckUserPermission(neededPermissiongType, null); // Assert Assert.AreEqual(true, result); }
public IActionResult Remove(int id) { if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext)) { return(RedirectToAction("Login", "User")); } if (BookContainer.Remove(id, SessionHandler.GetUserID(HttpContext))) { // TODO: Add message } else { // TODO: Add message } return(RedirectToAction("Index")); }
public IActionResult Register(UserModel userModel) { if (!Middleware.CheckUserPermission(PermissionType.None, HttpContext)) { return(RedirectToAction("Login", "User")); } if (SessionHandler.GetUserID(HttpContext) != 0) { return(RedirectToAction("Index", "Home")); } // TODO: Hash the password; UserContainer.Save(userModel); ViewData["Message"] = "Succesfully registered;"; return(View()); }
public IActionResult Index() { if (!Middleware.CheckUserPermission(PermissionType.User, HttpContext)) { return(RedirectToAction("Login", "User")); } BookIndexViewModel bivm = new BookIndexViewModel(); bivm.Books = new List <BookModel>(); foreach (Book book in BookContainer.GetAllBooks()) { // FIXME: Dit moet beter kunnen. BookModel temp = new BookModel(); temp.Id = book.Id; temp.User = new UserModel(); temp.User.Id = book.User.Id; temp.User.FirstName = book.User.FirstName; temp.User.Insertion = book.User.Insertion; temp.User.LastName = book.User.LastName; temp.User.Email = book.User.Email; temp.Course = new CourseModel(); temp.Course.Id = book.Course.Id; temp.Course.Name = book.Course.Name; temp.Sector = new SectorModel(); temp.Sector.Id = book.Sector.Id; temp.Sector.Name = book.Sector.Name; temp.Name = book.Name; temp.Price = book.Price; temp.QualityRating = book.QualityRating; bivm.Books.Add(temp); } return(View(bivm)); }