public RegisterUserCode RegisterUser(string UserName, string EMail, DateTime DOB, string Password) { BorrowerDAL dal = new BorrowerDAL(_connection); Borrower theBorrower = dal.BorrowerFindByName(UserName); if (theBorrower != null) { return(RegisterUserCode.UserNameExists); } theBorrower = dal.BorrowerFindByEmail(EMail); if (theBorrower != null) { return(RegisterUserCode.EMailExists); } int BorrowerID = dal.BorrowerCreate(UserName, EMail, DOB, MagicConstants.DefaultRole); BorrowerSecuredDAL securedDal = new BorrowerSecuredDAL(_connection); string salt = System.Web.Helpers.Crypto.GenerateSalt(20); string hashed = System.Web.Helpers.Crypto.HashPassword(Password + salt); securedDal.BorrowerSecuredUpdateJust(BorrowerID, hashed, salt); return(RegisterUserCode.Success); }
public int BorrowerCreate( string Name, string EMail, DateTime?DOB, int RoleID) { BorrowerDAL dal = new BorrowerDAL(_connection); return(dal.BorrowerCreate(Name, EMail, DOB, RoleID)); }
public void BorrowerTest() { // arrange BorrowerDAL dal = new BorrowerDAL(MagicSetup.Connection); // act create int rv1 = dal.BorrowerCreate("Test1", "Email", null, 1); Assert.IsTrue(rv1 > 0, $"BorrowerCreate failed rv = {rv1}"); Borrower a = dal.BorrowerFindByID(rv1); Assert.IsNotNull(a, $"BorrowerFindByID for ID {rv1} (just created) returned null"); Assert.IsTrue(a.BorrowerName == "Test1", $"BorrowerName was expected to be 'Test1' but found {a.BorrowerName}"); Assert.IsFalse(a.BorrowerDOB.HasValue, $"BorrowerDOB was expected to be null, but had a value"); Assert.IsTrue(a.RoleID == 1, $"Borrowerroleid was expected to be '1' but was actually '{a.RoleID}'"); int countofBorrowers = dal.BorrowerObtainCount(); Assert.IsTrue(countofBorrowers > 0, $"BorrowersObtainCount should be greater than 0 it is {countofBorrowers}"); List <Borrower> Borrowers = dal.BorrowersGetAll(); Assert.IsTrue(Borrowers.Count == countofBorrowers, $"BorrowersGetAll should have brought back {countofBorrowers} records, but it only found {Borrowers.Count}"); DateTime now = DateTime.Now; int number = dal.BorrowerUpdateJust(rv1, "Test1New", "EMail1", now, 2); Assert.IsTrue(number == 1, $"BorrowerUpdateJust was expected to return 1, but actually returned {number}"); a = dal.BorrowerFindByID(rv1); Assert.IsNotNull(a, $"BorrowerFindByID for ID {rv1} (just updated) returned null"); Assert.IsTrue(a.BorrowerName == "Test1New", $"BorrowerName after update was expected to be 'Test1New' but was actually '{a.BorrowerName}'"); Assert.IsTrue(a.BorrowerDOB.HasValue, "BorrowerDOB was expected to have a value, but was null"); Assert.IsTrue(a.RoleID == 2, $"BorrowerRoleID was expected to be 'newLocation1' but was actually '{a.RoleID}'"); number = dal.BorrowerUpdateSafe(rv1, "Test1New", "EMail1", now, 2, "1", "EMail2", null, 3); Assert.IsTrue(number == 1, $"BorrowerUpdateSafe was expected to return 1 but actually returned {number}"); a = dal.BorrowerFindByID(rv1); Assert.IsNotNull(a, $"BorrowerFindByID for ID {rv1} (just safe updated) returned null"); Assert.IsTrue(a.BorrowerName == "1", $"Borrowername after safeupdate was expected to be '1', but was '{a.BorrowerName}"); Assert.IsFalse(a.BorrowerDOB.HasValue, $"BorrowerDOB after safeupdate was expected to be null, but was not"); Assert.IsTrue(a.RoleID == 3, $"BorrowerRoleID after saftupdate was expected to be '3' but was actually '{a.RoleID}'"); number = dal.BorrowerUpdateSafe(rv1, "1", "EMail2", now, 2, "3", "EMail3", null, 4); Assert.IsTrue(number == 0, $"Borrowerupdatesafe was expected to return 0, but it actually returned {number}"); dal.BorrowerDelete(rv1); }