public ActionResult GetAcountInfo(user user, borrower borrower, string newpassword = null) { //Knyter samman user och borrower -objekten BorrowerWithUser borrowerWithUser = new BorrowerWithUser() { User = user, Borrower = borrower }; Auth _auth = new Auth((BorrowerWithUser)Session["User"]); if (_auth.HasUserPermission()) { if (ModelState.IsValid) { if (user.Password != null && PasswordService.VerifyPassword(user.Password, _auth.LoggedInUser.User.Password)) { if (UserService.EmailExists(user.Email) && _auth.LoggedInUser.User.Email != user.Email) { borrowerWithUser.PushAlert(AlertView.Build("Email existerar. Försök igen!", AlertType.Danger)); return(View(borrowerWithUser)); } if (!_auth.IsSameAs(borrowerWithUser, newpassword)) { if (newpassword == "") { UserService.Update(borrowerWithUser, user.Password); } else { if (!PasswordValidaton.IsValid(newpassword)) { borrowerWithUser.PushAlert(AlertView.Build(PasswordValidaton.ErrorMessage, AlertType.Danger)); return(View(borrowerWithUser)); } UserService.Update(borrowerWithUser, newpassword); } borrowerWithUser.PushAlert(AlertView.Build("Du har uppdaterat ditt konto.", AlertType.Success)); Session["User"] = BorrowerService.GetBorrowerWithUserByPersonId(user.PersonId); return(View(borrowerWithUser)); } else { borrowerWithUser.PushAlert(AlertView.Build("Inget har uppdaterats.", AlertType.Info)); return(View(borrowerWithUser)); } } borrowerWithUser.PushAlert(AlertView.Build("Du måste ange ditt eget lösenord.", AlertType.Danger)); return(View(borrowerWithUser)); } return(View(borrowerWithUser)); } return(Redirect("/Error/Code/403")); }
// Lägger till användarkonto till en borrower public ActionResult AddUser(user u) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { BorrowerWithBorrows b = BorrowerService.GetBorrowerWithBorrows(u.PersonId); if (ModelState.IsValid) { if (PasswordValidaton.IsValid(u.Password)) { if (!UserService.EmailExists(u.Email)) { AuthService.CreateUser(u); TempData["Alert"] = AlertView.Build("Du har skapat ett användarkonto till låntagaren.", AlertType.Success); return(RedirectToAction("Borrower", new { id = u.PersonId })); } TempData["Alert"] = AlertView.Build("Konto med emailen " + u.Email + " existerar. Ange en annan!", AlertType.Danger); return(View("Borrower", b)); } TempData["Alert"] = AlertView.Build(PasswordValidaton.ErrorMessage, AlertType.Danger); return(RedirectToAction("Borrower", new { id = u.PersonId })); } TempData["Alert"] = AlertView.BuildErrors(ViewData); return(RedirectToAction("Borrower", new { id = u.PersonId })); } return(Redirect("/Error/Code/403")); }
public ActionResult Borrower(BorrowerWithUser BorrowerWithUser) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { if (ModelState.IsValid && (BorrowerWithUser.Borrower.CategoryId == 1 || BorrowerWithUser.Borrower.CategoryId == 2 || BorrowerWithUser.Borrower.CategoryId == 3 || BorrowerWithUser.Borrower.CategoryId == 4)) { user tempU = AuthService.GetUserByPersonId(BorrowerWithUser.Borrower.PersonId); if (BorrowerWithUser.User != null && !(UserService.EmailExists(BorrowerWithUser.User.Email) && BorrowerWithUser.User.Email != tempU.Email)) { UserService.Update(BorrowerWithUser, null); } else { BorrowerService.UpdateBorrower(BorrowerWithUser.Borrower); } TempData["Alert"] = AlertView.Build("Du har uppdaterat låntagaren.", AlertType.Success); return(RedirectToAction("/Borrower/" + BorrowerWithUser.Borrower.PersonId)); } return(View(BorrowerService.GetBorrowerWithBorrows(BorrowerWithUser.Borrower.PersonId))); } return(Redirect("/Error/Code/403")); }
public ActionResult Create(BorrowerAndCategories baci) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { baci.Categories = CategoryService.GetCategories(); if (ModelState.IsValid && (baci.CatergoryId == 1 || baci.CatergoryId == 2 || baci.CatergoryId == 3 || baci.CatergoryId == 4)) { if (!BorrowerService.BorrowerExists(baci.Borrower.PersonId)) { borrower b = new borrower(); b = baci.Borrower; b.CategoryId = baci.CatergoryId; BorrowerService.StoreBorrower(b); TempData["Alert"] = AlertView.Build("Låntagare " + baci.Borrower.FirstName + " " + baci.Borrower.LastName + " skapad.", AlertType.Success); return(Redirect("Start")); } baci.PushAlert(AlertView.Build("Detta personnumret är redan registrerat hos oss", AlertType.Danger)); return(View(baci)); } return(View(baci)); } return(Redirect("/Error/Code/403")); }
/// <summary> /// Removes an author /// </summary> /// <param name="a"></param> /// <returns></returns> public ActionResult Remove(AuthorWithBooks a) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { AuthorService.DeleteAuthor(a.Author); TempData["Alert"] = AlertView.Build("Du har tagit bort författaren " + a.Author.FirstName + " " + a.Author.LastName, AlertType.Success); return(RedirectToAction("Start")); } return(Redirect("/Error/Code/403")); }
public ActionResult RenewLoan(string barcode, string personid, int index) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { ActiveAndHistoryBorrows borrows = new ActiveAndHistoryBorrows(); borrows.Active = BorrowService.GetActiveBorrowedBooks(personid); BorrowService.RenewLoad(BorrowerService.GetBorrower(personid), borrows.Active[index].Borrow.Barcode); TempData["AlertView"] = AlertView.Build("Lån är uppdaterade.", AlertType.Success); return(Redirect("/BorrowerAdmin/Borrower/" + personid)); } return(Redirect("/Error/Code/403")); }
public ActionResult Login(string email, string password) { if (AuthService.Login(email, password)) { BorrowerWithUser b = BorrowerService.GetBorrowerWithUserByEmail(email); Session["User"] = b; Session["Permissions"] = b.User.RoleId; return(Redirect("/")); } TempData["Alert"] = AlertView.Build("Fel email eller lösenord. Försök igen!", AlertType.Danger); return(View()); }
// Tar bort en borrower och konto om det finns public ActionResult Remove(BorrowerWithBorrows bwb) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { if (!BorrowerService.RemoveBorrower(bwb.BorrowerWithUser.Borrower)) { TempData["Alert"] = AlertView.Build("Det gick inte att ta bort låntagare. Kontrollera att inga aktiva lån finns.", AlertType.Danger); return(RedirectToAction("Borrower", new { id = bwb.BorrowerWithUser.Borrower.PersonId })); } TempData["Alert"] = AlertView.Build("Låntagare med PersonId " + bwb.BorrowerWithUser.Borrower.PersonId + " är nu borttagen", AlertType.Success); return(Redirect("Start")); } return(Redirect("/Error/Code/403")); }
public ActionResult Create(author a) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { if (ModelState.IsValid) { AuthorService.StoreAuthor(a); TempData["Alert"] = AlertView.Build("Du har skapat författaren " + a.FirstName + " " + a.LastName, AlertType.Success); return(RedirectToAction("Start")); } return(View(a)); } return(Redirect("/Error/Code/403")); }
public ActionResult Author(AuthorWithBooksAndBooks a) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { if (ModelState.IsValid) { AuthorService.UpdateAuthor(a.Author); TempData["Alert"] = AlertView.Build("Du har uppdaterat författaren.", AlertType.Success); return(View(AuthorService.GetAuthorWithBooksAndBooks(a.Author.Aid))); } return(View(AuthorService.GetAuthorWithBooksAndBooks(a.Author.Aid))); } return(Redirect("/Error/Code/403")); }
/// <summary> /// Removes a book /// </summary> /// <param name="isbn"></param> /// <returns></returns> public ActionResult Remove(string isbn) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { if (!BookService.RemoveBook(isbn)) { TempData["Alert"] = AlertView.Build("Det gick inte att ta bort bok. Kontrollera att det inte finns knutna lån eller författare.", AlertType.Danger); return(RedirectToAction("Book", new { id = isbn })); } TempData["Alert"] = AlertView.Build("Boken med ISBN " + isbn + " är nu borttagen.", AlertType.Success); return(RedirectToAction("Start")); } return(Redirect("/Error/Code/403")); }
public ActionResult Book(book Book) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { if (ModelState.IsValid) { BookService.UpdateBook(Book); TempData["Alert"] = AlertView.Build("Du har uppdaterat bokens uppgifter", AlertType.Success); return(View(BookService.GetBookWithAuthorsAndAuthors(Book.ISBN))); } TempData["Alert"] = AlertView.BuildErrors(ViewData); return(View(BookService.GetBookWithAuthorsAndAuthors(Book.ISBN))); } return(Redirect("/Error/Code/403")); }