Exemplo n.º 1
0
        public void RegistrarIngresoPasajero(IngresoBus ingreso)
        {
            try
            {
                var recorridoDb = _crudRecorrido.Retrieve <Recorrido>(new Recorrido {
                    RecorridoId = ingreso.RecorridoId
                });
                if (recorridoDb == null)
                {
                    throw new BusinessException(217);
                }

                var ruta = _crudRuta.Retrieve <Ruta>(new Ruta {
                    Id = recorridoDb.RutaId
                });

                if (recorridoDb.HoraLlegada != DateTime.MinValue) //EL bus ya llego a su destino
                {
                    throw new BusinessException(225);
                }

                var bus = _crudBus.Retrieve <Bus>(new Bus {
                    Id = recorridoDb.BusPlaca
                });
                if ((bus.CapacidadDePie + bus.CapacidadSentado) <= recorridoDb.CantidadPasajeros) // Bus lleno
                {
                    throw new BusinessException(224);
                }

                var transactionManager = new TransactionManager();
                var terminalManger     = new TerminalManager();

                var terminal = terminalManger.RetrieveById(new Terminal {
                    Id = ruta.TerminalId
                });

                transactionManager.CreateUserTransaction(new Transaccion
                {
                    CardUniqueCode = ingreso.Tarjeta,
                    Charge         = Convert.ToInt32(ruta.CostoTotal),
                    Description    = $"Pasaje de bus de Ruta: {ruta.RutaName}",
                    Type           = "Pago",
                    Terminal       = terminal,
                    Status         = "Activo",
                    LineaId        = ruta.LineaId
                }, true);

                recorridoDb.CantidadPasajeros++;
                _crudRecorrido.UpdatePasajeros(recorridoDb);
            }
            catch (Exception e)
            {
                ExceptionManager.GetInstance().Process(e);
            }
        }
Exemplo n.º 2
0
 public void RegistrarIngreso(IngresoBus ingreso)
 {
     try
     {
         Console.WriteLine($"Terminal: {_config.Terminal} -> " + ingreso.Tarjeta + " targeta en el bus");
         var response = _client.PostAsJsonAsync(_config.IngresoPasajero, ingreso).Result;
         response.EnsureSuccessStatusCode();
     }
     catch (Exception e)
     {
         Console.WriteLine($"Terminal: {_config.Terminal} -> " + "Registro ingreso: " + e.Message);
     }
 }
Exemplo n.º 3
0
        public void RunRecorrido(Ruta ruta, Recorrido recorrido)
        {
            try
            {
                var tarjetas = _tarjetaList.Where(t => t.Terminal.Id == _config.Terminal).ToList();

                recorrido = RegistroRecorrido(recorrido); // Recorrido
                Console.WriteLine($"Terminal: {_config.Terminal} -> " + recorrido.RecorridoId + " running");

                var rnd = new Random();

                for (int i = 0; i < 3; i++) // 3 pasengers
                {
                    var ingreso = new IngresoBus
                    {
                        RecorridoId = recorrido.RecorridoId,
                        Tarjeta     = tarjetas[rnd.Next(tarjetas.Count)].CodigoUnico
                    };

                    RegistrarIngreso(ingreso);
                }

                RegistroSalida(recorrido); // Salida

                foreach (var wp in ruta.Route.Waypoints)
                {
                    Thread.Sleep(2000); // wait two seconds between points
                    var pos = new Posicion
                    {
                        RecorridoId = recorrido.RecorridoId,
                        Longitude   = wp.Lng,
                        Latitude    = wp.Lat
                    };
                    UpdatePosicion(pos); // Update
                }

                RegistrarLlegada(recorrido); // Llegada
            }
            catch (Exception e)
            {
                Console.WriteLine($"Terminal: {_config.Terminal} -> run recorrido: " + e.Message);
            }
            finally
            {
                _resetEvent.Set();
            }
        }
Exemplo n.º 4
0
        [AllowAnonymous] //Usado en servicio
        public IHttpActionResult Ingreso(IngresoBus ingreso)
        {
            _apiResp = new ApiResponse();
            var mng = new RecorridoManager();

            try
            {
                mng.RegistrarIngresoPasajero(ingreso);
                _apiResp.Message = "Ingreso Correcto";
            }
            catch (BusinessException bex)
            {
                return(InternalServerError(new Exception(bex.ExceptionId + "-" + bex.AppMessage.Message)));
            }

            return(Ok(_apiResp));
        }