Exemplo n.º 1
0
 private void Cash_card_btn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ATMContext"];
         using (ATMContext context = new ATMContext(settings.ConnectionString))
         {
             int      money    = Convert.ToInt32(TextBox.Text);
             CardCash cardCash = new CardCash();
             string   tB       = TextBox.Text;
             if (tB == "10" || tB == "50" || tB == "100" || tB == "200" || tB == "500" || tB == "1000")
             {
                 var x = context.CardCash.Single(x => x.CardID == _cardId);
                 if (x.Cash > money)
                 {
                     x.Cash -= money;
                     context.SaveChanges();
                     MessageBox.Show("Выдача денег");
                     TextBox.Text = "";
                 }
                 else
                 {
                     MessageBox.Show($"На карт не достаточно средств!\n Баланс на карте: {cardAtmRepository.GetBalanse(_cardId)}");
                 }
             }
             else
             {
                 MessageBox.Show("Банкомат может выддат только 10,50,100,200,500,1000");
             }
         }
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 2
0
 internal void Create(CardCash newData)
 {
     CardCash exists = _repo.GetById(newData.Id);
       if (exists != null)
       {
     throw new Exception("Relationship already exists");
       }
       // Pretty sure I don't need this on create...
       // else if (exists.UserId != newData.UserId)
       // {
       //   throw new Exception("");
       // }
       _repo.Create(newData);
 }
Exemplo n.º 3
0
 // internal Cash GetCashByCardId(Card card)
 // {
 //   var exists = _repo.GetCashByCardId(card);
 //   // if (exists == null)
 //   // {
 //   //   throw new Exception("This is not the VaultKeep you are looking for");
 //   // }
 //   // else if (exists.UserId != userId)
 //   // {
 //   //   throw new Exception("Get yer own VaultKeep ya ninnie!");
 //   // }
 //   return exists;
 // }
 internal string Delete(int cashId, int cardId, string userId)
 {
     CardCash exists = _repo.FindByIds(cashId, cardId);
       if (exists == null)
       {
     throw new Exception("Invalid Id Combination");
       }
       else if (exists.UserId != userId)
       {
     throw new Exception("No tienes estes");
       }
       _repo.Delete(exists.Id);
       return "Successfully Deleted";
 }
Exemplo n.º 4
0
 public ActionResult <CardCash> Create([FromBody] CardCash newData)
 {
     try
     {
         var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         newData.UserId = userId;
         _ccs.Create(newData);
         return(Ok("Success"));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }