Esempio n. 1
0
        /// <summary>
        /// Try to connect
        /// </summary>
        private async void TestConnect()
        {
            DBUtilisateur db = new DBUtilisateur();
            Commercial    c  = db.GetByUsernamePassword(Login, Global.sha256(Password));

            Global.commercial = c;
            if (c != null)
            {
                NavigateToAccueil();
            }
            else
            {
                WSCommercial ws = new WSCommercial();
                IsBusy = true;
                await ws.Login(Login, Global.sha256(Password), LoginCallback);

                IsBusy = false;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// WS Login callback
        /// </summary>
        /// <param name="obj"></param>
        private void LoginCallback(IRestResponse obj)
        {
            if (obj.StatusCode == System.Net.HttpStatusCode.OK)
            {
                // Convert json to commercial
                WSCommercial ws = new WSCommercial();
                Commercial   c  = ws.JSONToCommercial(obj.Content);

                DBUtilisateur dbu = new DBUtilisateur();
                DBClient      dbc = new DBClient();
                DBEstimation  dbe = new DBEstimation();
                // Insert // Update commercial
                Commercial commercialFound = dbu.GetByIdServeur(c.IDServeur);
                if (commercialFound != null)
                {
                    dbu.UpdateByIdServeur(c);
                }
                else
                {
                    dbu.Add(c);
                }
                commercialFound   = dbu.GetByIdServeur(c.IDServeur);
                Global.commercial = commercialFound;
                // INSERT / UPDATE clients du commercial
                foreach (Client client in c.Clients)
                {
                    Client clientFound = dbc.GetByIdServeur(client.IDServeur);
                    client.IsSynchro = true;
                    if (clientFound != null)
                    {
                        dbc.UpdateByIdServeur(client);
                    }
                    else
                    {
                        client.IDCommercial = commercialFound.ID;
                        dbc.Add(client);
                    }
                    clientFound = dbc.GetByIdServeur(client.IDServeur);
                    // INSERT / UPDATE estimations des clients du commercial
                    foreach (Estimation e in client.Estimations)
                    {
                        Estimation estimationFound = dbe.GetByIdServeur(e.IDServeur);
                        e.IsSynchro = true;
                        if (estimationFound != null)
                        {
                            dbe.UpdateByIdServeur(e);
                        }
                        else
                        {
                            e.IDClient = clientFound.ID;
                            dbe.Add(e);
                        }
                    }
                }
                NavigateToAccueil();
            }
            else if (obj.StatusCode == System.Net.HttpStatusCode.InternalServerError)
            {
                MessageService.message("Impossible de joindre le serveur");
            }
            else if (obj.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                MessageService.message("Identifiants incorrects");
            }
            else if (obj.StatusCode == System.Net.HttpStatusCode.NoContent)
            {
                MessageService.message("Identifiants incorrects");
            }
            else if (obj.StatusCode == 0)
            {
                MessageService.message("Identifiants incorrects");
            }
        }