Exemplo n.º 1
0
        public void DbManager()
        {
            User    payer            = new User();
            User    reciver          = new User();
            Payment payment          = new Payment();
            PaymentSlipDBEntities db = new PaymentSlipDBEntities();

            if (ValidationSummary() == 7)
            {
                if (db.Users.Any(u => u.IBAN == PayerIBAN.Text))
                {
                    payer            = db.Users.SingleOrDefault(user => user.IBAN == PayerIBAN.Text);
                    payer.Saldo      = payer.Saldo - decimal.Parse(Amount.Text);
                    payer.PaymentPay = payer.PaymentPay + 1;
                }
                else
                {
                    payer.IBAN          = PayerIBAN.Text;
                    payer.Saldo         = 0;
                    payer.PaymentPay    = 0;
                    payer.PaymentRecive = 0;
                    payer.Saldo         = payer.Saldo - decimal.Parse(Amount.Text);
                    payer.PaymentPay    = payer.PaymentPay + 1;
                    payer.Name          = PayerName.Text;
                    db.Users.Add(payer);
                    db.SaveChanges();
                }

                if (db.Users.Any(u => u.IBAN == ReciverIBAN.Text))
                {
                    reciver               = db.Users.SingleOrDefault(user => user.IBAN == ReciverIBAN.Text);
                    reciver.Saldo         = reciver.Saldo + decimal.Parse(Amount.Text);
                    reciver.PaymentRecive = reciver.PaymentRecive + 1;
                }
                else
                {
                    reciver.IBAN          = ReciverIBAN.Text;
                    reciver.PaymentRecive = 0;
                    reciver.PaymentPay    = 0;
                    reciver.Saldo         = 0;
                    reciver.Saldo         = reciver.Saldo + decimal.Parse(Amount.Text);
                    reciver.PaymentRecive = reciver.PaymentRecive + 1;
                    reciver.Name          = ReciverName.Text;
                    db.Users.Add(reciver);
                    db.SaveChanges();
                }
                payment.Amount       = decimal.Parse(Amount.Text);
                payment.Descrpiption = Description.Text;
                payment.Model        = Model.Text;
                payment.PayerDue     = PayerDue.Text;
                payment.ReciverDue   = ReciverDue.Text;
                payment.UserID       = payer.Id;
                db.Payments.Add(payment);
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            User user = new User();
            PaymentSlipDBEntities db = new PaymentSlipDBEntities();

            user = db.Users.SingleOrDefault(u => u.IBAN == Search.Text);
            UserWIn win1 = new UserWIn();

            win1.Name.Text   = user.Name;
            win1.IBAN.Text   = user.IBAN;
            win1.State.Text  = user.Saldo.ToString();
            win1.RecNum.Text = user.PaymentRecive.ToString();
            win1.PayNum.Text = user.PaymentPay.ToString();
            win1.Show();
        }