Beispiel #1
0
 //Serveur
 public void UpdateByIdChantierProduit(ChantierProduit chantierProduit)
 {
     _connection.Query <ChantierProduit>("UPDATE [ChantierProduit] SET " +
                                         "[IDProduit] = ?, " +
                                         "[IDChantier] = ?" +
                                         "WHERE [IDProduit] = ? " +
                                         "AND [IDChantier] = ? ",
                                         chantierProduit.IDProduit,
                                         chantierProduit.IDChantier,
                                         chantierProduit.IDProduit,
                                         chantierProduit.IDChantier);
 }
        /// <summary>
        /// WS chantier callback
        /// </summary>
        /// <param name="obj"></param>
        private void ChantierCallback(IRestResponse obj)
        {
            if (obj.StatusCode == System.Net.HttpStatusCode.OK)
            {
                WSChantier        ws        = new WSChantier();
                List <Chantier>   chantiers = ws.JSONToChantier(obj.Content);
                DBChantier        dbc       = new DBChantier();
                DBProduit         dbp       = new DBProduit();
                DBChantierProduit dbcp      = new DBChantierProduit();
                foreach (Chantier c in chantiers)
                {
                    Chantier chantierFound = dbc.GetByIdServeur(c.IDServeur);
                    if (chantierFound != null)
                    {
                        dbc.UpdateByIdServeur(c);
                    }
                    else
                    {
                        dbc.Add(c);
                    }
                    chantierFound = dbc.GetByIdServeur(c.IDServeur);
                    foreach (Produit produit in c.Produits)
                    {
                        Produit p = dbp.GetByIdServeur(produit.IDServeur);
                        if (p != null)
                        {
                            ChantierProduit chantierproduitFound = dbcp.Get(chantierFound.ID, p.ID);
                            if (chantierproduitFound != null)
                            {
                                chantierproduitFound.IDChantier = chantierFound.ID;
                                chantierproduitFound.IDProduit  = p.ID;
                                dbcp.UpdateByIdChantierProduit(chantierproduitFound);
                            }
                            else
                            {
                                dbcp.Add(new ChantierProduit(chantierFound.ID, p.ID));
                            }
                        }
                    }
                }

                IEnumerable <Chantier> allChantiers = dbc.GetAll();
                foreach (Chantier item in allChantiers)
                {
                    bool canDelete = true;
                    foreach (Chantier item2 in chantiers)
                    {
                        if (item.IDServeur == item2.IDServeur)
                        {
                            canDelete = false;
                            break;
                        }
                    }
                    if (canDelete == true)
                    {
                        List <ChantierProduit> cp = dbcp.GetByChantier(item.ID);
                        foreach (ChantierProduit item3 in cp)
                        {
                            dbcp.DeleteByIdChantier(item3.IDChantier);
                        }
                        dbc.Delete(item.ID);
                    }
                }
            }
        }
Beispiel #3
0
 public void Update(ChantierProduit chantierProduit)
 {
     _connection.Update(chantierProduit);
 }
Beispiel #4
0
 public int Add(ChantierProduit item)
 {
     return(_connection.Insert(item));
 }