Exemplo n.º 1
0
        public Account GetById(int id)
        {
            string sql = "SELECT Id, Balance FROM Account WHERE Id=@Id";
            SqlParameter parameter = new SqlParameter("@Id", id);
            Account account = new Account();

            using (SqlConnection conn = new SqlConnection(_connStr))
            {
                conn.Open();
                using(SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    cmd.Parameters.Add(parameter);

                    SqlDataReader reader = cmd.ExecuteReader();
                    if (reader.Read()) 
                    {
                        account.Id = id;
                        account.Balance = Convert.ToDecimal(reader["Balance"]);
                    }
                }
            }

            return account;
        }
Exemplo n.º 2
0
        protected void Page_Init(object sender, EventArgs e)
        {
            this._accountService = ObjectFactory.GetInstance<AccountService>();

            this.account1 = this._accountService.GetAccountById(1);
            this.account2 = this._accountService.GetAccountById(2);
        }
Exemplo n.º 3
0
        public void Transfer(Account from, Account to, decimal amount) 
        {
            if (from.Balance > amount)
            {
                from.Balance -= amount;
                to.Balance += amount;

                this._accountRepository.Save(from);
                this._accountRepository.Save(to);

                this._unitOfWork.Commit();
            }
            else 
            {
                throw new Exception("余额不足");
            }
        }
Exemplo n.º 4
0
 public void Remove(Account account)
 {
     _unitOfWork.RegisterRemoved(account, this);
 }
Exemplo n.º 5
0
 public void Add(Account account)
 {
     _unitOfWork.RegisterNew(account, this);
 }
Exemplo n.º 6
0
 public void Save(Account account)
 {
     _unitOfWork.RegisterAmended(account, this);
 }