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")); }
// 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(string id) { Auth _auth = new Auth((BorrowerWithUser)Session["User"]); if (_auth.HasAdminPermission()) { if (!BorrowerService.BorrowerExists(id)) { return(Redirect("/Error/Code/404")); } if (UserService.BorrowerIsUser(_auth.LoggedInUser, id)) { return(Redirect("/User/GetAcountInfo")); } return(View(BorrowerService.GetBorrowerWithBorrows(id))); } return(Redirect("/Error/Code/403")); }