private void SavePari(Res response, int id, StructPari value) { SqlConnection connection = Models.Connexion.Get("Server=localhost;Database=foot;User ID=sa;Password=itu;"); Models.PariDAO padao = new Models.PariDAO(connection); Models.PariDetailDAO paddao = new Models.PariDetailDAO(connection); Models.ClientDAO cldao = new Models.ClientDAO(connection); Models.Pari pari = new Models.Pari(value.pari); pari.Id = padao.NextId(); Models.PariDetail detail = new Models.PariDetail(value.detail); detail.Id = paddao.NextId(); detail.Pari = pari; Models.Client client = cldao.SelectOne("WHERE id='" + pari.Client + "'"); client.Solde -= detail.Montant; if (client != null && padao.Insert(pari.ToInsert()) > 0) { paddao.Insert(detail.ToInsert()); cldao.Update(client); value.pari.id = pari.Id; value.detail.id = detail.Id; response.data = value; response.error = false; } else { throw new Exception("Enregistrement du pari impossible !"); } }
private void ManagePut(Res response, Models.PariDetail pari, Models.PariDetail contre) { float montant = -1; if (pari.Montant > contre.Montant) { montant = contre.Montant; } else { montant = pari.Montant; } Models.Jonction jonct = new Models.Jonction(jodao.NextId(), pari, contre, montant, 0); float pMont = pari.Montant - montant, cMont = contre.Montant - montant; if (pMont >= 0) { pari.Montant = pMont; } else { pari.Montant = 0; } if (cMont >= 0) { contre.Montant = cMont; } else { contre.Montant = 0; } if (pari.Pari.Equilibre == 0) { Models.Client cl1 = pari.Pari.Client; Models.Client cl2 = contre.Pari.Client; cl1.Solde += pari.Montant; pari.Montant = 0; cl2.Solde += contre.Montant; contre.Montant = 0; Models.ClientDAO cldao = new Models.ClientDAO(connection); cldao.Update(cl1); cldao.Update(cl2); } paddao.Update(pari); paddao.Update(contre); jodao.Insert(jonct.ToInsert()); response.data = new Jonction() { id = jonct.Id, pari = pari.Id, contrePari = contre.Id, montant = jonct.Montant }; response.error = false; }
private void Crediter(Res response, Client value) { SqlConnection connection = Models.Connexion.Get("Server=localhost;Database=foot;User ID=sa;Password=itu;"); Models.ClientDAO cldao = new Models.ClientDAO(connection); Models.Client client = cldao.SelectOne("WHERE id='" + value.id + "' AND password='******'"); if (client != null) { client.Solde += value.solde; cldao.Update(client); response.error = false; } else { throw new Exception("Votre pseudo ou mots de passe est errone !"); } }
private void DefinitivePlan(Plan value, SqlConnection connection) { this.VerifierPlan(value); value.AddInteret(connection); Models.PretDAO prdao = new Models.PretDAO(connection); Models.ClientDAO cldao = new Models.ClientDAO(connection); Models.RemboursementDAO rbdao = new Models.RemboursementDAO(connection); Models.Pret pret = new Models.Pret(value.pret); Models.Client client = cldao.SelectOne("WHERE id='" + value.pret.client.id + "'"); client.Solde += pret.Montant; pret.Id = prdao.NextId(); pret.Client = client; prdao.Insert(pret); cldao.Update(client); foreach (Remboursement r in value.remboursements) { Models.Remboursement rb = new Models.Remboursement(r); rb.Id = rbdao.NextId(); rb.Pret = pret; rbdao.Insert(rb); } }