Ejemplo n.º 1
0
        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 !");
            }
        }
Ejemplo n.º 2
0
        public Res Put(int id, [FromBody] StructPari value)
        {
            Res response = new Res(true, null, null);

            try {
                this.SavePari(response, id, value);
            } catch (Exception ex) {
                response.message = ex.Message;
            } return(response);
        }