// 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")); }
private BorrowerService CreateBorrowerService() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new BorrowerService(userId); return(service); }
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 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 void BorrowerServiceSetUp() { service = new BorrowerService(); Address address = new Address("Brasov", "Octavian", 10); borrower = new Borrower("Alexandra", "Hermeneanu", "*****@*****.**", new DateTime(1999, 10, 10), address, true, false); }
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")); }
public ActionResult Start(string letter = "A") { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission() && LetterLists.LetterList.Contains(letter)) { return(View(new LettersAndBorrowers(LetterLists.LetterList, BorrowerService.GetBorrowersByLetter(letter)))); } return(Redirect("/Error/Code/403")); }
public ActionResult GetAcountInfo() { Auth _auth = new Auth((BorrowerWithUser)Session["User"]); if (_auth.HasUserPermission()) { return(View(BorrowerService.GetBorrowerWithUserByPersonId(_auth.LoggedInUser.User.PersonId))); } return(Redirect("/Error/Code/403")); }
public void GetBorrowerByIdValidCall() { var mockedBorrowerRepository = new Mock <IBorrowerRepository>(); mockedBorrowerRepository.Setup(x => x.GetByID(It.IsAny <int>())).Returns(borrower); IBorrowerService mockService = new BorrowerService(mockedBorrowerRepository.Object); Borrower expected = borrower; Borrower actual = mockService.GetBorrowerById(1); Assert.AreEqual(expected, actual, "Expected to have the same values"); }
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()); }
public void GetAllBorrowersValidCall() { var mockedBorrowerRepository = new Mock <IBorrowerRepository>(); mockedBorrowerRepository.Setup(x => x.Get( It.IsAny <Expression <Func <Borrower, bool> > >(), It.IsAny <Func <IQueryable <Borrower>, IOrderedQueryable <Borrower> > >(), It.IsAny <string>())).Returns(GetAllSampleBorrowers()); IBorrowerService mockService = new BorrowerService(mockedBorrowerRepository.Object); IEnumerable <Borrower> expected = GetAllSampleBorrowers(); IEnumerable <Borrower> actual = mockService.GetAllBorrowers(); Assert.True(EnumerableExtensions.HasSameElementsAs <Borrower>(expected, actual)); }
// 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 BorrowerContract CreateBorrower(BorrowerContract contract) { try { using (var context = new MovieShelfEntities(ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString)) { var provider = new BorrowerDal(context); var process = new BorrowerProcess(provider); var service = new BorrowerService(process); var result = service.Create(new Borrower(contract)); return new Borrower().ConvertToContract(result, new BorrowerContract()); } } catch (Exception exception) { return HandleExceptionResponse<Borrower, BorrowerContract>(exception); } }
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")); }
public DomainListContract<BorrowerContract> FetchAllBorrowers(bool includeDeletion) { try { using (var context = new MovieShelfEntities(ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString)) { var provider = new BorrowerDal(context); var process = new BorrowerProcess(provider); var service = new BorrowerService(process); var result = service.GetAll(includeDeletion); var returnResult = new Borrower().ConvertToContract<Borrower, IEnumerable<Borrower>, BorrowerContract>(result); return returnResult; } } catch (Exception exception) { return HandleExceptionResponse<BorrowerContract>(exception); } }
public BorrowersController(BorrowerService bService, LoanService lService, CollectionService cService) { _borrowerService = bService; _loanService = lService; _collectionService = cService; }
public HomeController() { _BorrowerService = new BorrowerService(); _BookService = new BookService(); }
public DomainStatusContract RemoveBorrower(int id) { try { using (var context = new MovieShelfEntities(ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString)) { var provider = new BorrowerDal(context); var process = new BorrowerProcess(provider); var service = new BorrowerService(process); var result = service.Remove(id); return DomainStatus.ConvertToContract(result); } } catch (Exception exception) { return HandleExceptionResponse(exception); } }