Ejemplo n.º 1
0
 public void UpdateAmount(double cost)
 {
     try
     {
         using (var db = new VendMachineDbContext())
         {
             Account Account = db.Accounts.Where(x => x.CardNO == cardNo).FirstOrDefault();
             Account.Amount         -= cost;
             db.Entry(Account).State = EntityState.Modified;
             db.SaveChanges();
             log.Info("Payment success");
         }
     }
     catch (Exception)
     {
         log.Error("Db connection failed");
     }
 }
Ejemplo n.º 2
0
 public bool IsValidCard()
 {
     try
     {
         using (var db = new VendMachineDbContext())
         {
             Account Account = db.Accounts.Where(x => x.CardNO == cardNo).FirstOrDefault();
             if (Account != null && Account.Pin == pin)
             {
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception)
     {
         log.Error("Db connection failed");
         return(false);
     }
 }
Ejemplo n.º 3
0
 public bool IsEnough(double cost)
 {
     try
     {
         using (var db = new VendMachineDbContext())
         {
             Account Account = db.Accounts.Where(x => x.CardNO == cardNo).FirstOrDefault();
             if (Account.Amount >= cost)
             {
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception)
     {
         log.Error("Db connection failed");
         return(false);
     }
 }