Esempio n. 1
0
        /// <summary>
        /// Get chantiers from WS
        /// </summary>
        private async void GetChantiersFromWS()
        {
            WSChantier ws = new WSChantier();

            IsBusy = true;
            await ws.GetChantiers(Global.commercial.Token, ChantierCallback);

            IsBusy = false;
        }
Esempio n. 2
0
        /// <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);
                    }
                }
            }
        }