예제 #1
0
        public static bool RemoveBorrower(borrower b) {

            if (HasActiveBorrows(b.PersonId))
                return false;

            BorrowRepository.RemoveBorrowsByPersonId(b.PersonId);
            UserRepository.RemoveUser(b.PersonId);
            BorrowerRepository.RemoveBorrower(b);

            return true;
        }
예제 #2
0
        private static BorrowerWithBorrows mapBorrowerWithBorrows(borrower b)
        {
            BorrowerWithBorrows borrowerwithborrows = new BorrowerWithBorrows();
            borrowerwithborrows.BorrowerWithUser = new BorrowerWithUser();
            
            borrowerwithborrows.BorrowerWithUser.Borrower = b;
            borrowerwithborrows.Borrows = new ActiveAndHistoryBorrows();
            borrowerwithborrows.Borrows.Active = BorrowService.GetActiveBorrowedBooks(b.PersonId);
            borrowerwithborrows.Borrows.History = BorrowService.GetHistoryBorrowedBooks(b.PersonId);
            borrowerwithborrows.Categories = CategoryService.GetCategories();
            borrowerwithborrows.BorrowerWithUser.User = UserRepository.GetUserByPersonId(b.PersonId);

            if (borrowerwithborrows.BorrowerWithUser.User == null)
                borrowerwithborrows.BorrowerWithUser.User = new user();

            borrowerwithborrows.Roles = RoleRepository.GetRoles();
            return borrowerwithborrows;
        }
예제 #3
0
 public static void StoreBorrower(borrower b){
     BorrowerRepository.StoreBorrower(b);
 }
예제 #4
0
 public static void UpdateBorrower(borrower b)
 {
     BorrowerRepository.UpdateBorrower(b);
 }
예제 #5
0
        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");               
        }
        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");
        }
예제 #7
0
 public static void RenewAllLoans(borrower br, List<BorrowedBookCopy> borrowes)
 {
     DateTime ToBeReturnedDate = DateTime.Today.AddDays(CategoryRepository.GetCategoryById(br.CategoryId).Period);
     foreach (BorrowedBookCopy b in borrowes)
         BorrowRepository.UpdateBorrowDates(br.PersonId, b.Borrow.Barcode, ToBeReturnedDate);
 }
예제 #8
0
 public static void RenewLoad(borrower br, string barcode)
 {
     DateTime ToBeReturnedDate = DateTime.Today.AddDays(CategoryRepository.GetCategoryById(br.CategoryId).Period);
     BorrowRepository.UpdateBorrowDates(br.PersonId, barcode, ToBeReturnedDate);
 }