Ejemplo n.º 1
0
        private string ProcessVelocidadExcedidaGenericEvent(IGeoPoint generico)
        {
            var text   = ExtraText.GetVelocidadExcedidaExtraText(generico, Coche);
            var chofer = GetChofer(generico.GetRiderId());
            var fecha  = generico.GetDateTime();
            var evento = MessageSaver.Save(generico, MessageCode.SpeedingTicket.GetMessageCode(), Dispositivo, Coche, chofer, fecha, generico.GeoPoint, text, ZonaManejo);

            var infraccion = new Infraccion
            {
                Vehiculo         = Coche,
                Alcanzado        = generico.GeoPoint.Speed.Unpack(),
                CodigoInfraccion = Infraccion.Codigos.ExcesoVelocidad,
                Empleado         = evento.Chofer,
                Fecha            = fecha,
                Latitud          = generico.GeoPoint.Lat,
                Longitud         = generico.GeoPoint.Lon,
                FechaFin         = null,
                LatitudFin       = 0,
                LongitudFin      = 0,
                Permitido        = 0,
                Zona             = ZonaManejo,
                FechaAlta        = DateTime.UtcNow
            };

            DaoFactory.InfraccionDAO.Save(infraccion);

            return(MessageCode.SpeedingTicket.GetMessageCode());
        }
Ejemplo n.º 2
0
        private string ProcessPanicEvent(Event generico, string code)
        {
            var text   = ExtraText.GetExtraText(generico, code).Trim().ToUpperInvariant();
            var chofer = GetChofer(generico.GetRiderId());
            var fecha  = generico.GetDateTime();
            var evento = MessageSaver.Save(generico, code, Dispositivo, Coche, chofer, fecha, generico.GeoPoint, text, ZonaManejo);

            var infraccion = new Infraccion
            {
                Vehiculo         = Coche,
                Alcanzado        = generico.GeoPoint.Speed.Unpack(),
                CodigoInfraccion = Infraccion.Codigos.Panico,
                Empleado         = evento.Chofer,
                Fecha            = fecha,
                Latitud          = generico.GeoPoint.Lat,
                Longitud         = generico.GeoPoint.Lon,
                FechaFin         = null,
                LatitudFin       = 0,
                LongitudFin      = 0,
                Permitido        = 0,
                Zona             = ZonaManejo,
                FechaAlta        = DateTime.UtcNow
            };

            DaoFactory.InfraccionDAO.Save(infraccion);

            return(code);
        }
Ejemplo n.º 3
0
        public int GetDurationPoints(Infraccion infraction)
        {
            var duration = infraction.Alcanzado - infraction.Permitido;
            var p        = PuntajesTiempo.FirstOrDefault(time => time.Segundos <= duration);

            return(p != null ? p.Puntaje : 0);
        }
Ejemplo n.º 4
0
        public void RegistrarInfraccion(string matricula, int idInfraccion)
        {
            Vehiculo   v = vehiculos.getVehiculo(matricula);
            Infraccion i = infracciones.getInfraccion(idInfraccion);

            try
            {
                if (v == null)
                {
                    throw new Exception("El vehículo no existe.");
                }
                if (i == null)
                {
                    throw new Exception("La infracción no existe.");
                }

                Conductor c = conductores.getConductor(v.DniConductorHabitual);
                c.addInfraccion(i);
                int act = i.incrVeces;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 5
0
        private void sidInfraccion(object sender, EventArgs e)
        {
            int identificador = int.Parse(cbInfraccion.Text.Split("-")[0].Replace(" ", ""));

            if (identificador == 0)
            {
                tbInfraccionNombre.Text           = "";
                nudInfraccionPuntos.Text          = "0";
                rtbInfraccionDescripcion.Text     = "";
                tbInfraccionNombre.ReadOnly       = false;
                nudInfraccionPuntos.ReadOnly      = false;
                rtbInfraccionDescripcion.ReadOnly = false;
            }
            else
            {
                Infraccion i = sistema.getInfraccion(identificador);
                if (i != null)
                {
                    tbInfraccionNombre.Text           = i.Nombre;
                    nudInfraccionPuntos.Text          = i.Puntos.ToString();
                    rtbInfraccionDescripcion.Text     = i.Descripcion;
                    tbInfraccionNombre.ReadOnly       = true;
                    nudInfraccionPuntos.ReadOnly      = true;
                    rtbInfraccionDescripcion.ReadOnly = true;
                }
            }
        }
Ejemplo n.º 6
0
        public HttpResponseMessage Put(int id, [FromBody] Infraccion infraccion)
        {
            try
            {
                Infraccion infraccionOriginal = TheRepository.GetInfraccionById(id).FirstOrDefault();

                if (infraccionOriginal == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotModified, "No se encuentra la infracción"));
                }

                infraccion.Id = infraccionOriginal.Id;

                if (TheRepository.Update(infraccionOriginal, infraccion) && TheRepository.SaveAll())
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(infraccion)));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotModified));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Ejemplo n.º 7
0
        public Infraccion GetInfraccionbyIdSolicitud(Int32 id_solicitud)
        {
            try
            {
                using (SqlConnection sqlConn = new SqlConnection(this.strConn))
                {
                    sqlConn.Open();
                    SqlCommand cmd = new SqlCommand(strConn, sqlConn);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.CommandText = "sp_r_infraccionbyIdSolicitud";
                    cmd.Parameters.AddWithValue("@id_solicitud", id_solicitud);
                    SqlDataReader reader      = cmd.ExecuteReader();
                    Infraccion    mInfraccion = new Infraccion();

                    if (reader.Read())
                    {
                        mInfraccion.Operacion       = new OperacionDAC().getOperacion(Convert.ToInt32(reader["id_solicitud"]));
                        mInfraccion.Rut             = Convert.ToInt32(reader["rut"]);
                        mInfraccion.Patente         = reader["patente"].ToString();
                        mInfraccion.Secursal_origen = reader["sucursal_origen"].ToString();
                    }
                    else
                    {
                        mInfraccion = null;
                    }
                    return(mInfraccion);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 8
0
        private void button2_Click(object sender, EventArgs e)
        {
            var Fecha          = this.dateTimePicker1.Value;
            var Dominio        = textBox1.Text;
            var TipoInfraccion = (TipoInfraccion)comboBox1.SelectedItem;

            infraccion = new Infraccion(Fecha, Dominio, TipoInfraccion);
            this.Close();
        }
Ejemplo n.º 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            DateTime   fechaHoy  = DateTime.Today;
            Infraccion infraSele = listBox1.SelectedItem as Infraccion;
            Pago       pago      = new Pago(fechaHoy, infraSele);

            infraSele.pagar();
            this.Close();
        }
Ejemplo n.º 10
0
        public void CreateInfraccion(Infraccion infraccion)
        {
            if (infraccion == null)
            {
                throw new ArgumentNullException(nameof(infraccion));
            }

            _ctx.Infracciones.Add(infraccion);
        }
Ejemplo n.º 11
0
 public InfraccionModel Create(Infraccion infraccion)
 {
     return(new InfraccionModel()
     {
         Url = _UrlHelper.Link("Infracciones", new { id = infraccion.Id }),
         Id = infraccion.Id,
         Descripcion = infraccion.Descripcion,
         Puntos = infraccion.Puntos
     });
 }
        public IHttpActionResult Get(string id)
        {
            Infraccion infraccion = repository.getById(id);

            if (infraccion == null)
            {
                return(NotFound());
            }
            return(Ok(infraccion));
        }
Ejemplo n.º 13
0
        public bool RegistrarInfraccion(Infraccion i, String mat)
        {
            if (!_dgtManager.ExisteMatricula(mat))
            {
                throw new Exception("Matricula inexistente");
            }
            Vehiculo veh = _dgtManager.Vehiculos.Where(v => v.Matricula == mat).First();

            return(_dgtManager.RegistrarInfraccion(i, veh));
        }
Ejemplo n.º 14
0
        public int GetSpeedingPoints(Infraccion infraction)
        {
            if (infraction.Permitido == 0 || infraction.Alcanzado == 0)
            {
                return(0);
            }
            var porcentaje = ((infraction.Alcanzado - infraction.Permitido) * 100) / infraction.Permitido;
            var p          = PuntajesVelocidad.FirstOrDefault(speed => speed.Porcentaje <= porcentaje);

            return(p != null ? p.Puntaje : 0);
        }
Ejemplo n.º 15
0
        private static int GetGravedadInfraccion(Infraccion infraction)
        {
            if (infraction.Permitido == 0 || infraction.Alcanzado == 0)
            {
                return(0);
            }

            var difference = infraction.Alcanzado - infraction.Permitido;

            return(difference <= 9 ? 1 : difference > 9 && difference <= 17 ? 2 : 3);
        }
Ejemplo n.º 16
0
        private static List <RoutePosition> GetMessagePositions(Infraccion mobileEvent, IEnumerable <List <RoutePosition> > routes)
        {
            var positions = new List <RoutePosition>();

            foreach (var route in routes)
            {
                positions.AddRange(route.Where(position => position.Date >= mobileEvent.Fecha && position.Date <= mobileEvent.FechaFin.Value));
            }

            return(positions);
        }
Ejemplo n.º 17
0
 private string SerializeInfraccion(Infraccion x)
 {
     return(string.Format("{{ \"lat\": {0},\"lon\": {1}, \"date\": {2}, \"enddate\": {3}, \"id\": {4}, \"endlat\": {5}, \"endlon\": {6} }}",
                          x.Latitud.ToString(CultureInfo.InvariantCulture),
                          x.Longitud.ToString(CultureInfo.InvariantCulture),
                          SerializeDate(x.Fecha.ToDisplayDateTime()),
                          x.FechaFin.HasValue ? SerializeDate(x.FechaFin.Value.ToDisplayDateTime()).ToString() : "null",
                          x.Id,
                          x.LatitudFin.ToString(CultureInfo.InvariantCulture),
                          x.LongitudFin.ToString(CultureInfo.InvariantCulture)
                          ));
 }
Ejemplo n.º 18
0
 public bool Insert(Infraccion infraccion)
 {
     try
     {
         _dgtContext.Infracciones.Add(infraccion);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public void update(Infraccion infraccion)
        {
            List <Infraccion> infracciones  = this.getAll();
            Infraccion        oldinfraccion = infracciones.Where(i => i.Identificador == infraccion.Identificador).FirstOrDefault();

            infracciones.Remove(oldinfraccion);

            infracciones.Add(infraccion);
            string json = JsonConvert.SerializeObject(infracciones);

            this.write(json);
        }
Ejemplo n.º 20
0
        public ActionResult <Conductor> CreateInfraccion(Infraccion infraccion)
        {
            var infraccionFromRepo = _repo.GetInfraccionById(infraccion.Id);

            if (infraccionFromRepo != null)
            {
                return(BadRequest());
            }
            _repo.CreateInfraccion(infraccion);
            _repo.SaveChanges();

            return(CreatedAtRoute(nameof(GetInfraccionById), new { id = infraccion.Id }, infraccion));
        }
Ejemplo n.º 21
0
        public HttpResponseMessage Post([FromBody] InfraccionRegistradaDTO inf)
        {
            try
            {
                Infraccion ir = _mapper.ConvertTo <Infraccion, InfraccionDTO>(inf.infraccion);

                _service.RegistrarInfraccion(ir, inf.vehiculo.Matricula);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets the list of points associated to the speed ponderation of the infraction.
        /// </summary>
        /// <param name="infraction"></param>
        /// <returns></returns>
        public int GetSpeedingPoints(Infraccion infraction)
        {
            switch (infraction.CodigoInfraccion)
            {
            case Infraccion.Codigos.ExcesoVelocidad:
            case Infraccion.Codigos.ExcesoRpm:
            {
                var porcentaje = ((infraction.Alcanzado - infraction.Permitido) * 100) / infraction.Permitido;
                return(Puntajes.Where(speed => speed.Porcentaje <= porcentaje).OrderByDescending(speed => speed.Porcentaje).Select(speed => speed.Puntaje).FirstOrDefault());
            }

            default: return(0);
            }
        }
Ejemplo n.º 23
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Infraccion selectedItem = listBox1.SelectedItem as Infraccion;

            if (selectedItem.estaVencida())
            {
                MessageBox.Show("Esta vencida no se puede abonar!");
                button1.Enabled = false;
            }
            else
            {
                button1.Enabled = true;
            }
        }
Ejemplo n.º 24
0
        // POST api/<controller>
        public HttpResponseMessage Post([FromBody] InfraccionDTO inf)
        {
            try
            {
                Infraccion ir = _mapper.ConvertTo <Infraccion, InfraccionDTO>(inf);

                _service.NuevaInfraccion(inf.Identificador, inf.Descripcion, inf.PuntosDescontar);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Gets the list of points associated to the duration of the infraction.
        /// </summary>
        /// <returns></returns>
        public int GetDurationPoints(Infraccion infraction)
        {
            switch (infraction.CodigoInfraccion)
            {
            case Infraccion.Codigos.ExcesoVelocidad:
            case Infraccion.Codigos.ExcesoRpm:
            {
                var duration = infraction.Alcanzado - infraction.Permitido;
                return(Puntajes.Where(time => time.Segundos <= duration).OrderByDescending(time => time.Segundos).Select(time => time.Puntaje).FirstOrDefault());
            }

            default: return(0);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Gets the severity of the current infraction.
        /// </summary>
        /// <param name="infraction"></param>
        /// <returns></returns>
        private static int GetGravedadInfraccion(Infraccion infraction)
        {
            switch (infraction.CodigoInfraccion)
            {
            case Infraccion.Codigos.ExcesoVelocidad:
            case Infraccion.Codigos.ExcesoRpm:
            {
                var difference = infraction.Alcanzado - infraction.Permitido;
                return(difference <= 9 ? 1 : difference > 9 && difference <= 17 ? 2 : 3);
            }

            default: return(0);
            }
        }
Ejemplo n.º 27
0
        internal static List <Infraccion> CrearInfracciones()
        {
            List <Infraccion> infracciones = new List <Infraccion>();

            for (int i = 0; i < 4; i++)
            {
                Infraccion inf = new Infraccion()
                {
                    Identificador = "Inf-" + i.ToString(), Descripcion = SeedEntity.infracciones[i], PuntosDescontar = i + 1
                };
                infracciones.Add(inf);
            }
            return(infracciones);
        }
        public Infraccion add(TipoInfraccion tipo, Vehiculo vehiculo, DateTime fecha, Conductor conductor = null)
        {
            List <Infraccion> infracciones = this.getAll();
            Infraccion        infraccion   = new Infraccion()
            {
                Identificador = Guid.NewGuid().ToString(), Fecha = fecha, TipoInfraccionIdentificador = tipo.Identificador, DNI = conductor != null ? conductor.DNI : null, Matricula = vehiculo.Matricula
            };

            infracciones.Add(infraccion);
            string json = JsonConvert.SerializeObject(infracciones);

            this.write(json);
            return(infraccion);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Process the givenn message as a VelocidadExcedida event.
        /// </summary>
        /// <param name="velocidadExcedida">A message.</param>
        private HandleResults ProcessVelocidadExcedidaEvent(SpeedingTicket velocidadExcedida)
        {
            var inicio = velocidadExcedida.StartPoint ?? velocidadExcedida.TicketPoint;

            if (IsInvalidVelocidadExcedidaMessage(inicio, velocidadExcedida))
            {
                return(HandleResults.BreakSuccess);
            }

            var texto              = GetVelocidadExcedidaText(velocidadExcedida);
            var chofer             = GetChofer(velocidadExcedida.GetRiderId());
            var velocidadPermitida = Convert.ToInt32(velocidadExcedida.SpeedLimit);
            var velocidadAlcanzada = Convert.ToInt32(velocidadExcedida.SpeedReached);
            var estado             = GeocercaManager.CalcularEstadoVehiculo(Coche, inicio, DaoFactory);
            var zona = estado != null && estado.ZonaManejo != null && estado.ZonaManejo.ZonaManejo > 0
                    ? DaoFactory.ZonaDAO.FindById(estado.ZonaManejo.ZonaManejo) : null;

            if (Coche.Empresa.AsignoInfraccionPorAgenda)
            {
                var reserva = DaoFactory.AgendaVehicularDAO.FindByVehicleAndDate(Coche.Id, inicio.Date);
                if (reserva != null)
                {
                    chofer = reserva.Empleado;
                }
            }

            var evento = MessageSaver.Save(velocidadExcedida, MessageCode.SpeedingTicket.GetMessageCode(), Dispositivo, Coche, chofer, inicio.Date, inicio, velocidadExcedida.EndPoint, texto, velocidadPermitida, velocidadAlcanzada, null, zona);

            var infraccion = new Infraccion
            {
                Vehiculo         = Coche,
                Alcanzado        = velocidadAlcanzada,
                CodigoInfraccion = Infraccion.Codigos.ExcesoVelocidad,
                Empleado         = evento.Chofer,
                Fecha            = inicio.Date,
                Latitud          = inicio.Lat,
                Longitud         = inicio.Lon,
                FechaFin         = velocidadExcedida.EndPoint.Date,
                LatitudFin       = velocidadExcedida.EndPoint.Lat,
                LongitudFin      = velocidadExcedida.EndPoint.Lon,
                Permitido        = velocidadPermitida,
                Zona             = zona,
                FechaAlta        = DateTime.UtcNow
            };

            DaoFactory.InfraccionDAO.Save(infraccion);

            return(HandleResults.Success);
        }
        public IHttpActionResult Post(Infraccion infraccion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Vehiculo vehiculo = vehiculoRepository.getById(infraccion.Matricula);

            if (vehiculo == null)
            {
                return(BadRequest("No existe vehículo"));
            }

            TipoInfraccion tipo = tipoRepository.getById(infraccion.TipoInfraccionIdentificador);

            if (tipo == null)
            {
                return(BadRequest("No existe tipo de infracción"));
            }
            Conductor conductor = null;

            if (infraccion.DNI == null)
            {
                List <Conductor> conductoresHabituales = conductorHabitualRepository.getByVehiculo(vehiculo);
                if (conductoresHabituales.Count == 1)
                {
                    conductor = conductoresHabituales.FirstOrDefault();
                }
            }
            else
            {
                conductor = conductorRepository.getById(infraccion.DNI);
                if (conductor == null)
                {
                    return(BadRequest("El conductor no está registrado"));
                }
            }

            Infraccion infraccionNew = repository.add(tipo, vehiculo, infraccion.Fecha, conductor);

            if (conductor != null)
            {
                conductor.Puntos -= tipo.Puntos;
                conductorRepository.update(conductor);
            }

            return(CreatedAtRoute("DefaultApi", new { id = infraccionNew.Identificador }, infraccionNew));
        }