Esempio n. 1
0
        public async Task <ApiResponse <bool> > Handle(ConsumerGeocodificarRequest request, CancellationToken cancellationToken)
        {
            try
            {
                var entity = await _command.Find <Geolocalizacion>(request.Id);

                entity.Longuitud = request.Longuitud;
                entity.Latitud   = request.Latitud;
                entity.EstadoId  = (int)Enums.Estado.Terminado;

                _command.Update(entity);
                await _command.SaveChangeAsync();

                return(new ApiResponse <bool>(true));
            }
            catch (Exception ex)
            {
                request.AddNotification("Exception", $"Se ha lanzado una exception: {ex.Message}");
                return(new ApiResponse <bool>(request.Notifications, HttpStatusCode.UnprocessableEntity));
            }
        }
        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));
            }
        }