Ejemplo n.º 1
0
        public async void insertDocument(T document, IMongo imongo)
        {
            JsonSerializerSettings property = new JsonSerializerSettings();

            property.NullValueHandling = NullValueHandling.Ignore;
            String                   json        = JsonConvert.SerializeObject(document, Formatting.None, property);
            HttpStringContent        content     = new HttpStringContent(json);
            HttpMediaTypeHeaderValue contentType = new HttpMediaTypeHeaderValue("application/json");

            content.Headers.ContentType = contentType;
            HttpResponseMessage x = await client.PostAsync(new Uri(url), content);

            if (x.ReasonPhrase.Equals("OK"))
            {
                MessageBox.Show("El Usuario se agregó correctamente");
                imongo.insertar(2);
            }
            else
            {
                MessageBox.Show("Error al agregar usuario, revise su conexión");
                imongo.insertar(1);
            }
        }