// 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"));
        }
Beispiel #2
0
        public ActionResult Create(BookWithClassifications bwc, int copies, string library)
        {
            if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission())
            {
                if (ModelState.IsValid)
                {
                    BookService.StoreBook(bwc.Book, copies, library);

                    return(RedirectToAction("Book", new { id = bwc.Book.ISBN }));
                }

                TempData["Alert"] = AlertView.BuildErrors(ViewData);

                return(View(BookService.NewBookWithClassifications()));
            }

            return(Redirect("/Error/Code/403"));
        }
Beispiel #3
0
        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"));
        }