public async Task publishGeolocalization(Geolocalizacion geolocalizacion) { await _publisher.PublishAsync(new GeolocalizacionEvent(new GeolocalizacionEventDto { Provincia = geolocalizacion.Provincia, Calle = geolocalizacion.Calle, Codigo_Postal = geolocalizacion.Codigo_Postal, Cuidad = geolocalizacion.Cuidad, Id = geolocalizacion.Id, Numero = geolocalizacion.Numero, Pais = geolocalizacion.Pais })); }
public ActionResult AlmacenarUbicaciones() { var model = Newtonsoft.Json.JsonConvert.DeserializeObject <List <UbicacionUsuarioViewModel> >(this.Contenido); Guid userid = new Guid(usuarioId); var usuario = db.Usuarios.Where(u => u.UsuarioApp.Id == usuarioId).First(); foreach (var item in model) { var ubicacion = new Geolocalizacion { Latitud = item.Latitud, Longitud = item.Longitud, Usuario = usuario, FechaHora = Convert.ToDateTime(item.FechaHora) }; db.Geolocalizacion.Add(ubicacion); db.SaveChanges(); } return(Json(new { Result = "OK", Error = "" }, JsonRequestBehavior.AllowGet)); }
public async Task <ApiResponse <GeolocalizarResponse> > Handle(GeolocalizarRequest request, CancellationToken cancellationToken) { try { // Any validations var entity = new Geolocalizacion { Calle = request.Calle, Codigo_Postal = request.Codigo_Postal, Cuidad = request.Cuidad, EstadoId = (int)Enums.Estado.Procesado, Latitud = "", Longuitud = "", Numero = request.Numero, Pais = request.Pais, Provincia = request.Provincia }; using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { _command.Add(entity); await _command.SaveChangeAsync(); await _publisher.publishGeolocalization(entity); scope.Complete(); } return(new ApiResponse <GeolocalizarResponse>(new GeolocalizarResponse { Id = entity.Id.ToString() })); } catch (Exception ex) { request.AddNotification("Exception", $"Se ha lanzado una exception: {ex.Message}"); return(new ApiResponse <GeolocalizarResponse>(request.Notifications, HttpStatusCode.UnprocessableEntity)); } }
private async void Button_Clicked(object sender, EventArgs e) { var oauthToken = await SecureStorage.GetAsync("auth"); Personas personas = JsonConvert.DeserializeObject <Personas>(oauthToken); cliente.DefaultRequestHeaders.Add("Accept", "application/json"); Negos negocios = new Negos(); Negocio nego = new Negocio(); List <Negocio> negocio = new List <Negocio>(); nego.idadmin = personas.persona[0].id; nego.nombre = nom.Text; nego.nit = nit.Text; nego.email = email.Text; nego.direccion = direccion.Text; nego.telefono = telefono.Text; nego.tipo = (string)tipo.SelectedItem; nego.ciudad = ciudad.Text; nego.detalle = detalle.Text; nego.foto = urlImagen; Geolocalizacion geo = new Geolocalizacion(); List <double> latLong = await geo.calcularCoordenadas(nego.direccion); if (latLong == null) { nego.latitud = ""; nego.longitud = ""; await DisplayAlert("Problema con la direccion", "No fue posible verificar la dirección", "OK"); return; } else { nego.latitud = latLong.ElementAt(0).ToString().Replace(",", "."); nego.longitud = latLong.ElementAt(1).ToString().Replace(",", "."); //await DisplayAlert("Direccion correcta", "Latitud: " + nego.latitud + " Longitud: " + nego.longitud, "ok"); } if (string.IsNullOrEmpty(nego.nombre)) { await Application.Current.MainPage.DisplayAlert("error", "Campo nombre no puede estar vacio", "Accept"); return; } else if (string.IsNullOrEmpty(nego.nit)) { await Application.Current.MainPage.DisplayAlert("error", "Se debe ingresar un nit", "Accept"); return; } else if (string.IsNullOrEmpty(nego.email)) { await Application.Current.MainPage.DisplayAlert("error", "Debes ingresar un correo", "Accept"); return; } else if (!utilidades.email_bien_escrito(nego.email)) { await Application.Current.MainPage.DisplayAlert("error", "Correo no admitido", "Accept"); return; } else if (string.IsNullOrEmpty(nego.telefono)) { await Application.Current.MainPage.DisplayAlert("error", "Ingresa un telefono", "Accept"); return; } else if (string.IsNullOrEmpty(nego.direccion)) { await Application.Current.MainPage.DisplayAlert("error", "ingresa", "Accept"); return; } else if (string.IsNullOrEmpty(nego.ciudad)) { await Application.Current.MainPage.DisplayAlert("error", "you must enter a city", "Accept"); return; } else if (string.IsNullOrEmpty(nego.detalle)) { await Application.Current.MainPage.DisplayAlert("error", "you must enter a detail", "Accept"); return; } else if (string.IsNullOrEmpty(nego.foto)) { await Application.Current.MainPage.DisplayAlert("error", "you must choose a photo", "Accept"); return; } negocio.Add(nego); negocios.negocio = negocio; var json = JsonConvert.SerializeObject(negocios); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await cliente.PostAsync(URL, content); var res = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { Console.WriteLine(res); await App.Current.MainPage.DisplayAlert("Registro", "Registro Completado", "OK"); n.actualizarVistaAsync(); await Navigation.PopModalAsync(); } else { Console.WriteLine(res); await App.Current.MainPage.DisplayAlert("Error", "Algo salió mal", "OK"); Console.WriteLine("Error"); } }