Ejemplo n.º 1
0
 public static void ResetAccountDatabase()
 {
     using (var context = new TMEntities1())
     {
         context.Database.ExecuteSqlCommand("TRUNCATE TABLE [Accouunt]");
         context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public static bool ChangeBalance(Account account, decimal amount, TMEntities1 context)
        {
            var entity = context.Accounts.FirstOrDefault(p => p.AccountId == account.AccountId);

            if (entity != null)
            {
                if (entity.Balance >= amount * -1)
                {
                    entity.Balance += amount;
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        public static Account GetAccountFromDB(string name)
        {
            var account = new TMEntities1().Accounts.FirstOrDefault(p => p.Name.Equals(name));

            if (account == null)
            {
                account = new Data.Account()
                {
                    Name = name, Balance = 1000, CreatedDate = DateTime.Now, Number = "11111", Token = "11111"
                };
                Save(account);
            }
            return(account);
        }
Ejemplo n.º 4
0
 public static Account Save(Account account)
 {
     using (var context = new TMEntities1()) {
         var entity = context.Accounts.FirstOrDefault(p => p.Name.Equals(account.Name));
         if (entity != null)
         {
             entity.Balance = account.Balance;
         }
         else
         {
             if (string.IsNullOrEmpty(account.Number))
             {
                 account.Number = "11111";
             }
             account.Token       = account.Number;
             account.CreatedDate = DateTime.Now;
             context.Accounts.Add(account);
         }
         context.SaveChanges();
         return(account);
     }
 }
Ejemplo n.º 5
0
 private static bool CompletedTransfer(Account src, Account des, decimal amount)
 {
     using (var context = new TMEntities1())
     {
         using (var dbContextTransaction = context.Database.BeginTransaction())
         {
             try
             {
                 if (AccountService.Widthraw(src, amount, context))
                 {
                     AccountService.Deposit(des, amount, context);
                     context.SaveChanges();
                     dbContextTransaction.Commit();
                     return(true);
                 }
             }
             catch (Exception ex)
             {
                 dbContextTransaction.Rollback();
             }
         }
     }
     return(false);
 }
Ejemplo n.º 6
0
 public static bool Deposit(Account account, decimal amount, TMEntities1 context)
 {
     return(ChangeBalance(account, amount, context));
 }
Ejemplo n.º 7
0
 public static bool Widthraw(Account account, decimal amount, TMEntities1 context)
 {
     amount = amount * -1;
     return(ChangeBalance(account, amount, context));
 }