Exemplo n.º 1
0
 public ResponsableOrgaViewModel()
 {
     responsable = new Models.Responsable();
 }
Exemplo n.º 2
0
        /** call web service url and check the licence number*/
        private Boolean IsExistInWebService(Models.Responsable model)
        {
            /**
             * Create url from licencie
             */
            String url          = "http://www.ffjda.org/ws_mobile/webRestGet/service.svc/infosInscriptionASP/";
            String numLicChange = model.Licence.Replace("*", "@").Replace(" ", "§");

            /**
             * Make the request
             */
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + numLicChange);

            try
            {
                WebResponse response = request.GetResponse();
                using (Stream responseStream = response.GetResponseStream())
                {
                    // Reader to open http response
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    String       back   = reader.ReadToEnd();
                    // test le retour de la fonction web
                    // Si j'ai rien le licencie n'existe pas, sinon
                    if (back.Length == 0 || back == null)
                    {
                        return(false);
                    }

                    // Use dictionnary to reade Json string
                    var dict = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(back);
                    // List to skip first stage
                    ArrayList list = (ArrayList)dict["infosInscriptionASPResult"];
                    // Je récupére tous les items de ma chaine json
                    Dictionary <String, Object> items = (Dictionary <String, Object>)list[0];
                    // Et je traite ceux que je veux
                    object item;
                    items.TryGetValue("numLicence", out item);
                    model.Licence = (String)item;
                    // Si le num licence est vide alors la licence n'existe pas
                    if (model.Licence == null || model.Licence.Length == 0)
                    {
                        return(false);
                    }
                    items.TryGetValue("mail", out item);
                    model.Email = (String)item;
                    items.TryGetValue("prenom", out item);
                    model.Prenom = (String)item;
                    items.TryGetValue("nom", out item);
                    model.Nom = (String)item;
                    items.TryGetValue("tel", out item);
                    model.Telephone = (String)item;
                    return(true);
                }
            }
            catch (WebException ex)
            {
                WebResponse errorResponse = ex.Response;
                using (Stream responseStream = errorResponse.GetResponseStream())
                {
                    StreamReader reader    = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
                    String       errorText = reader.ReadToEnd();
                    // log errorText
                }
                throw;
            }
        }