public AccountService()
 {
     if (AccountService.accountDataAccess == null)
     {
         AccountService.accountDataAccess = new AccountDataAccess();
     }
 }
Ejemplo n.º 2
0
        public List <Entity.Sales.CustomerType> GetCustomerType()
        {
            List <Entity.Sales.CustomerType> CustomerTypeList = new List <Entity.Sales.CustomerType>();

            AccountDataAccess.GetCustomerTypes().CopyListTo(CustomerTypeList);
            return(CustomerTypeList);
        }
        public void SaveToDatabase_MultipleAccounts_AllSaved()
        {
            var account1 = new Account
            {
                Name = "Account1",
                CurrentBalance = 1234
            };

            var account2 = new Account
            {
                Name = "Account2",
                CurrentBalance = 999
            };

            var account3 = new Account();
            var account4 = new Account();

            var dataAccess = new AccountDataAccess(connectionCreator);
            dataAccess.SaveItem(account1);
            dataAccess.SaveItem(account2);
            dataAccess.SaveItem(account3);
            dataAccess.SaveItem(account4);

            var resultList = dataAccess.LoadList();

            Assert.AreNotSame(account1, account2);
            Assert.IsTrue(resultList.Any(x => x.Id == account1.Id && x.Name == account1.Name));
            Assert.IsTrue(resultList.Any(x => x.Id == account2.Id && x.Name == account2.Name));
        }
Ejemplo n.º 4
0
        public void SaveToDatabase_MultipleAccounts_AllSaved()
        {
            var account1 = new Account {
                Name           = "Account1",
                CurrentBalance = 1234
            };

            var account2 = new Account {
                Name           = "Account2",
                CurrentBalance = 999
            };

            var account3 = new Account();
            var account4 = new Account();

            var dataAccess = new AccountDataAccess(connectionCreator);

            dataAccess.SaveItem(account1);
            dataAccess.SaveItem(account2);
            dataAccess.SaveItem(account3);
            dataAccess.SaveItem(account4);

            var resultList = dataAccess.LoadList();

            Assert.AreNotSame(account1, account2);
            Assert.IsTrue(resultList.Any(x => x.Id == account1.Id && x.Name == account1.Name));
            Assert.IsTrue(resultList.Any(x => x.Id == account2.Id && x.Name == account2.Name));
        }
        public void SaveToDatabase_ExistingAccount_CorrectId()
        {
            var balance = 456468;

            var account = new Account
            {
                CurrentBalance = balance
            };

            var dataAccess = new AccountDataAccess(connectionCreator);

            dataAccess.SaveItem(account);

            Assert.IsNull(account.Name);

            var id = account.Id;

            var name = "Sparkonto";

            account.Name = name;

            Assert.AreEqual(id, account.Id);
            Assert.AreEqual(name, account.Name);
            Assert.AreEqual(balance, account.CurrentBalance);
        }
Ejemplo n.º 6
0
        //Reset Password
        public static Boolean GeneratePasswordResetToken(AccountViewModel_GeneratePasswordResetToken view, string ConnectionString, SecurityLogic security)
        {
            //Pre DAL Check
            if (view.LoginID == null)
            {
                view.Errors.Add("Please insert a valid Email");
            }

            if (view.Errors.Count > 0)
            {
                return(false);
            }

            //Set Salt and Generate Password Reset Token
            view.salt = security.GenerateSalt();
            AccountDataAccess.GeneratePasswordResetToken(view, ConnectionString, security);

            //Post DAl Validation Check
            if (view.AccountID == null)
            {
                return(false);
            }
            if (view.Email == null)
            {
                return(false);
            }
            if (view.Errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
        public void SaveToDatabase_CreateAndUpdateAccount_CorrectlyUpdated()
        {
            var firstName  = "old name";
            var secondName = "new name";

            var account = new Account
            {
                Name           = firstName,
                CurrentBalance = 1234
            };

            var dataAccess = new AccountDataAccess(connectionCreator);

            dataAccess.SaveItem(account);

            Assert.AreEqual(firstName, dataAccess.LoadList().FirstOrDefault(x => x.Id == account.Id).Name);

            account.Name = secondName;
            dataAccess.SaveItem(account);

            var accounts = dataAccess.LoadList();

            Assert.IsFalse(accounts.Any(x => x.Name == firstName));
            Assert.AreEqual(secondName, accounts.First(x => x.Id == account.Id).Name);
        }
Ejemplo n.º 8
0
        //Verify Email
        public static Boolean VerifyEmail(AccountViewModel_VerifyEmail view, string ConnectionString)
        {
            if (view.EmailVerificationKey == null)
            {
                view.Errors.Add("No Token was Provided");
            }
            if (view.EmailVerificationKey == null)
            {
                view.Errors.Add("No Key was Provided");
            }

            if (view.Errors.Count > 0)
            {
                return(false);
            }

            if (AccountDataAccess.VerifyEmail(view, ConnectionString))
            {
                if (view.AccountID == null || view.AccountID <= 0)
                {
                    view.Errors.Add("Error Validating Email Verification Token");
                }

                if (view.Errors.Count > 0)
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
 public frmLogin()
 {
     InitializeComponent();
     StartPosition          = FormStartPosition.CenterScreen;
     accountDataAccess      = new AccountDataAccess();
     loginHistoryDataAccess = new LoginHistoryDataAccess();
 }
Ejemplo n.º 10
0
        public int SaveAccounts(Entity.Sales.Accounts Model)
        {
            AccountsDbModel DbModel = new AccountsDbModel();

            Model.CopyPropertiesTo(DbModel);
            return(AccountDataAccess.SaveAccounts(DbModel));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> GetTokenDetails([FromRoute] string token)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    new OperationResponse
                    {
                        HasSucceeded             = false,
                        IsDomainValidationErrors = true,
                        Message = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage))
                    };
                }

                AccountDataAccess _AccountAccess = new AccountDataAccess(_iconfiguration);

                DatabaseResponse response = await _AccountAccess.AuthenticateToken(token);

                if (response.ResponseCode == 105)
                {
                    //Authentication success

                    var _accesstoken = new AccessToken();

                    _accesstoken = (AccessToken)response.Results;

                    // return basic user info (without password) and token to store client side
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        Message = EnumExtensions.GetDescription(DbReturnValue.AuthSuccess),
                        ReturnedObject = _accesstoken
                    }));
                }

                else
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.ReasonUnknown),
                        IsDomainValidationErrors = true
                    }));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    IsDomainValidationErrors = false
                }));
            }
        }
        public SqlDataReader GetAccountDetail(int Id)
        {
            AccountDataAccess accObj   = new AccountDataAccess();
            AccountModel      accModel = new AccountModel();
            SqlDataReader     sdr      = accObj.ReadDetail(Id);

            return(sdr);
        }
Ejemplo n.º 13
0
        //Login
        public static Boolean Login(AccountViewModel_Login view, AccountViewModel account, string ConnectionString, SecurityLogic security)
        {
            if (view.Login == null)
            {
                view.Errors.Add("No Login Name Provided");
            }
            if (view.password == null)
            {
                view.Errors.Add("No Password Provided");
            }

            if (view.Errors.Count > 0)
            {
                return(false);
            }

            if (AccountDataAccess.GetSalt(view, ConnectionString))
            {
                if (view.salt == null)
                {
                    return(false);
                }

                if (view.Errors.Count > 0)
                {
                    return(false);
                }

                if (AccountDataAccess.Login(view, account, ConnectionString, security))
                {
                    if (account.AccountID == null || account.AccountID <= 0)
                    {
                        view.Errors.Add("No Login Name Provided");
                    }
                    if (account.username == null)
                    {
                        view.Errors.Add("Error Retrieving Username");
                    }
                    if (account.email == null)
                    {
                        view.Errors.Add("Error Retrieving Email");
                    }

                    if (view.Errors.Count > 0)
                    {
                        return(false);
                    }

                    if (account.Errors.Count > 0)
                    {
                        return(false);
                    }

                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 14
0
        public List <Entity.Sales.GetAccounts> GetAllAccounts(Entity.Sales.GetAccountsParam Param)
        {
            List <Entity.Sales.GetAccounts> AllAccountList = new List <Entity.Sales.GetAccounts>();
            GetAccountsParamDbModel         p = new GetAccountsParamDbModel();

            Param.CopyPropertiesTo(p);
            AccountDataAccess.GetAllAccounts(p).CopyListTo(AllAccountList);
            return(AllAccountList);
        }
Ejemplo n.º 15
0
        //Roles
        public static Boolean GetUserPermissions(AccountViewModel account, RoleViewModel_Roles roles, string ConnectionString)
        {
            if (account.AccountID == null)
            {
                account.Errors.Add("Invalid Account ID");
            }

            return(roles.Errors.Count > 0 || account.Errors.Count > 0 ? false : AccountDataAccess.GetUserPermissions(account, roles, ConnectionString));
        }
 public ManagerCollection()
 {
     _dataAccess = new CategoryDataAccess();
     _account    = new AccountDataAccess();
     _cats       = new List <Category>();
     _invs       = new List <Invoice>();
     _buss       = new List <Business>();
     SetCategories();
 }
Ejemplo n.º 17
0
        public bool Login(AccountModel accountLoginModel)
        {
            User userEntity = new User();

            userEntity.EmailId  = accountLoginModel.EmailId;
            userEntity.Password = accountLoginModel.Password;
            AccountDataAccess accountDataAccess = new AccountDataAccess();

            return(accountDataAccess.Login(userEntity));
        }
        public static Account Get(int id)
        {
            var account = AccountDataAccess.Get(id);

            if (account == null)
            {
                throw new Error404NotFound <Account>(id);
            }

            return(account);
        }
        public static async Task <Account> Register(Account account)
        {
            if (account.IsPresent)
            {
                throw new Error400BadRequest <Account>("Email " + account.Email + " đã có người sử dụng");
            }

            account.IsValid();
            account.Password = CryptoHelper.Encrypt(account.Password);

            return(await AccountDataAccess.Add(account));
        }
 protected void btnEnter_Click(object sender, EventArgs e)
 {
     try
     {
         AccountDataAccess.insertAccount(Convert.ToInt32(txtAccountID.Text), Convert.ToInt32(txtZip.Text),
                                         txtLastName.Text, txtFirstName.Text, txtStreet.Text, txtCity.Text, txtState.Text);
     }
     catch (Exception ex)
     {
         lblStatus.Text = "Insert failed. " + ex.Message.ToString();
     }
 }
Ejemplo n.º 21
0
        public static Boolean VerifyPasswordResetToken(AccountViewModel_VerifyPasswordResetToken view, string ConnectionString, SecurityLogic security)
        {
            //Checks if a TOken GUID was provided
            if (view.TokenID == null)
            {
                view.Errors.Add("Invalid Reset TokenID");
            }

            if (view.TokenKey == null)
            {
                view.Errors.Add("Invalid Reset TokenKey");
            }

            if (view.Errors.Count > 0)
            {
                return(false);
            }

            //Gets salt for token if available
            if (AccountDataAccess.VerifyPasswordResetToken_GetSalt(view, ConnectionString))
            {
                //Get Salt Validations
                if (view.Errors.Count > 0)
                {
                    return(false);
                }

                if (view.TokenSalt == null)
                {
                    view.Errors.Add("Invalid Reset Token");
                    return(false);
                }

                //Verifies whether a valid token existed
                if (AccountDataAccess.VerifyPasswordResetToken(view, ConnectionString, security))
                {
                    //Verify Salt Validations
                    if (view.Errors.Count > 0)
                    {
                        return(false);
                    }

                    if (view.AccountID == null || view.AccountID <= 0)
                    {
                        view.Errors.Add("Invalid Reset Token");
                        return(false);
                    }

                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 22
0
        public IActionResult Get([FromBody] CustomerModel model)
        {
            // 1. ADO.NET - most performing method
            // 2. Dapper - high performance and easily code
            // 3. EntityFramework - easily code but heavy, low performance

            // if you are developer without much db knowledge - entrity framework is the best.


            AccountDataAccess accountDataAccess = new AccountDataAccess();

            return(Ok(accountDataAccess.GetCustomerAccounts(model.CustomerId)));
        }
        public static async Task UpdateAccess(AccountUpdateAccessRequest request)
        {
            var account   = ((Account)request.Account).GetManaged;
            var access    = account.Access;
            var newAccess = request.Access;

            if (newAccess == access)
            {
                throw new Error400BadRequest <Account>("Tài khoản này đã được phân quyền là " + access);
            }

            await AccountDataAccess.UpdateAccess(account, newAccess);
        }
Ejemplo n.º 24
0
        public static Boolean DeleteRole(AccountViewModel account, RoleViewModel_Role role, string ConnectionString)
        {
            if (account.AccountID == null)
            {
                account.Errors.Add("Invalid Account ID");
            }

            if (role.RoleID == null)
            {
                role.Errors.Add("Invalid Role ID");
            }

            return(role.Errors.Count > 0 || account.Errors.Count > 0 ? false : AccountDataAccess.DeleteRole(account, role, ConnectionString));
        }
        public AccountModel GetAccdata(string bid)
        {
            AccountDataAccess accDL    = new AccountDataAccess();
            SqlDataReader     sdr      = accDL.ReadAccDetail(bid);
            AccountModel      accModel = new AccountModel();

            if (sdr.Read())
            {
                accModel.applicant_id = Convert.ToInt32(sdr["applicant_id"]);
                accModel.loan_id      = Convert.ToInt32(sdr["loan_id"]);
            }
            AccountDataAccess.sqlcon.Close();
            return(accModel);
        }
Ejemplo n.º 26
0
        public void DeleteFromDatabase_AccountToDelete_CorrectlyDelete()
        {
            var account = new Account {
                Name           = "accountToDelete",
                CurrentBalance = 1234
            };

            var dataAccess = new AccountDataAccess(connectionCreator);

            dataAccess.SaveItem(account);

            Assert.IsTrue(dataAccess.LoadList(x => x.Id == account.Id).Any());

            dataAccess.DeleteItem(account);
            Assert.IsFalse(dataAccess.LoadList(x => x.Id == account.Id).Any());
        }
        public static async Task ChangePassword(Account account, AccountChangePasswordRequest request)
        {
            if (!account.IsEqualPassword(request.Password))
            {
                throw new Error400BadRequest <Account>("Mật khẩu không chính xác");
            }

            if (request.Password == request.NewPassword)
            {
                throw new Error400BadRequest <Account>("Mật khẩu mới không được trùng");
            }

            var newPassword = CryptoHelper.Encrypt(request.NewPassword);

            await AccountDataAccess.ChangePassword(account, newPassword);
        }
Ejemplo n.º 28
0
        public int SignUp(AccountModel accountModel)
        {
            User model = new User();

            model.EmailId  = accountModel.EmailId;
            model.Password = accountModel.Password;
            model.FullName = accountModel.FullName;
            AccountDataAccess accountDataAccess = new AccountDataAccess();
            var isValid = accountDataAccess.UserExists(model);

            if (isValid)
            {
                return(0);
            }
            return(accountDataAccess.SignUp(model));
        }
Ejemplo n.º 29
0
        //Update Account Info
        public static Boolean UpdateAccountInfo(AccountViewModel_EditAccountInfo view, AccountViewModel accountView, string ConnectionString)
        {
            Boolean Status = true;

            view.AccountID = accountView.AccountID;

            if (view.firstname == null)
            {
                view.Errors.Add("Please Input a First Name");
            }

            if (view.lastname == null)
            {
                view.Errors.Add("Please Input a Last Name");
            }

            if (view.AccountID == null)
            {
                view.Errors.Add("An Unexpected Error Occured");
            }

            if (view.Errors.Count > 0)
            {
                return(false);
            }

            if (view.firstname != accountView.firstname || view.lastname != accountView.lastname)
            {
                Status = AccountDataAccess.EditAccountInfo(view, ConnectionString) ? Status : false;
            }

            if (view.email != accountView.email)
            {
                Status = AccountDataAccess.UpdateAccountEmail(view, ConnectionString) ? Status : false;
            }

            if (Status)
            {
                accountView.firstname = view.firstname;
                accountView.lastname  = view.lastname;
                accountView.email     = view.email;
            }

            return(Status);
        }
Ejemplo n.º 30
0
        private bool InsertNewPasswordResetRequestAndSetAccountDeleted(TestSprocGenerator.Business.SingleTable.Bo.Account foundAccount, string passwordResetRequestCode)
        {
            bool success = false;

            AccountDataAccess dataAccess = new AccountDataAccess();

            TestSprocGenerator.Business.SingleTable.Bo.PasswordResetRequest passwordResetRequest =
                new TestSprocGenerator.Business.SingleTable.Bo.PasswordResetRequest(_smoSettings[CONNECTION_STRING_NAME]);

            passwordResetRequest.PasswordResetRequestID = Guid.NewGuid();
            passwordResetRequest.AccountID         = foundAccount.AccountID;
            passwordResetRequest.PasswordResetCode = passwordResetRequestCode;

            foundAccount.Deleted = true;

            success = dataAccess.InsertNewPasswordResetRequestAndSetAccountDeleted(foundAccount, passwordResetRequestCode);

            return(success);
        }
Ejemplo n.º 31
0
        public static Boolean ResendPasswordVerificationEmail(AccountViewModel_GenerateEmailVerificationToken view, string ConnectionString)
        {
            if (view.Login == null)
            {
                view.Errors.Add("Please insert a valid Login");
            }

            if (view.Errors.Count > 0)
            {
                return(false);
            }

            if (AccountDataAccess.ResendVerificationEmail(view, ConnectionString))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 32
0
        public void AccountDataAccess_CrudAccount()
        {
            var accountDataAccess =
                new AccountDataAccess(new SqliteConnectionCreator(new WindowsSqliteConnectionFactory()));

            const string firstName = "fooo Name";
            const string secondName = "new Foooo";

            var account = new Account
            {
                CurrentBalance = 20,
                Iban = "CHF20 0000 00000 000000",
                Name = firstName,
                Note = "this is a note"
            };

            accountDataAccess.SaveItem(account);

            accountDataAccess.LoadList();
            var list = accountDataAccess.LoadList();

            Assert.Equal(1, list.Count);
            Assert.Equal(firstName, list.First().Name);

            account.Name = secondName;

            accountDataAccess.SaveItem(account);

            list = accountDataAccess.LoadList();

            Assert.Equal(1, list.Count);
            Assert.Equal(secondName, list.First().Name);

            accountDataAccess.DeleteItem(account);

            list = accountDataAccess.LoadList();

            Assert.False(list.Any());
        }
        public void AccountDataAccess_CrudAccount()
        {
            var accountDataAccess = new AccountDataAccess();

            const string firstName = "fooo Name";
            const string secondName = "new Foooo";

            var account = new Account
            {
                CurrentBalance = 20,
                Iban = "CHF20 0000 00000 000000",
                Name = firstName,
                Note = "this is a note"
            };

            accountDataAccess.Save(account);

            accountDataAccess.LoadList();
            var list = accountDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(firstName, list.First().Name);

            account.Name = secondName;

            accountDataAccess.Save(account);

            list = accountDataAccess.LoadList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(secondName, list.First().Name);

            accountDataAccess.Delete(account);

            list = accountDataAccess.LoadList();

            Assert.IsFalse(list.Any());
        }
        public void SaveToDatabase_ExistingAccount_CorrectId()
        {
            var balance = 456468;

            var account = new Account
            {
                CurrentBalance = balance
            };

            var dataAccess = new AccountDataAccess(connectionCreator);
            dataAccess.SaveItem(account);

            Assert.IsNull(account.Name);

            var id = account.Id;

            var name = "Sparkonto";
            account.Name = name;

            Assert.AreEqual(id, account.Id);
            Assert.AreEqual(name, account.Name);
            Assert.AreEqual(balance, account.CurrentBalance);
        }
 public AccountDataAccessTests()
 {
     accountData = new AccountDataAccess();
 }
        public void DeleteFromDatabase_AccountToDelete_CorrectlyDelete()
        {
            var account = new Account
            {
                Name = "accountToDelete",
                CurrentBalance = 1234
            };

            var dataAccess = new AccountDataAccess(connectionCreator);
            dataAccess.SaveItem(account);

            Assert.IsTrue(dataAccess.LoadList(x => x.Id == account.Id).Any());

            dataAccess.DeleteItem(account);
            Assert.IsFalse(dataAccess.LoadList(x => x.Id == account.Id).Any());
        }
Ejemplo n.º 37
0
 public AccountService()
 {
     accountData = new AccountDataAccess ();
 }
        public void SaveToDatabase_CreateAndUpdateAccount_CorrectlyUpdated()
        {
            var firstName = "old name";
            var secondName = "new name";

            var account = new Account
            {
                Name = firstName,
                CurrentBalance = 1234
            };

            var dataAccess = new AccountDataAccess(connectionCreator);
            dataAccess.SaveItem(account);

            Assert.AreEqual(firstName, dataAccess.LoadList().FirstOrDefault(x => x.Id == account.Id).Name);

            account.Name = secondName;
            dataAccess.SaveItem(account);

            var accounts = dataAccess.LoadList();
            Assert.IsFalse(accounts.Any(x => x.Name == firstName));
            Assert.AreEqual(secondName, accounts.First(x => x.Id == account.Id).Name);
        }