Beispiel #1
0
        public async Task <IActionResult> PatchTramos(int id, [FromBody] JsonPatchDocument <Tramos> TramosPatch)
        {
            Tramos tramos = await _context.Tramos.FirstOrDefaultAsync(u => u.Id == id);

            if (tramos == null)
            {
                return(NotFound());
            }

            try
            {
                TramosPatch.ApplyTo(tramos);

                _context.Entry(tramos).State = EntityState.Modified;

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TramosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> PutTramos(int id, [FromBody] Tramos tramos)
        {
            if (id != tramos.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tramos).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TramosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        public async Task <ActionResult <Mascotas> > PostTramos(Tramos tramos)
        {
            _context.Tramos.Add(tramos);

            await _context.SaveChangesAsync();

            return(Ok());
        }
Beispiel #4
0
        public void SubirTramo(string tramoDescripcion)
        {
            var tramo = this.Tramos.FirstOrDefault(x => x.Descripcion == tramoDescripcion);

            if (tramo != null)
            {
                int posicion = Tramos.IndexOf(tramo);
                if (posicion != 0)
                {
                    Tramos.Remove(tramo);
                    Tramos.Insert(posicion - 1, tramo);
                }
            }
        }
Beispiel #5
0
        public bool IsValid()
        {
            ErrorMessage = "";

            if (CantidadTramos == 0)
            {
                ErrorMessage += "Debe seleccionar por lo menos 1 tramo. " + System.Environment.NewLine;
            }

            foreach (TramoViewModel tramo in Tramos)
            {
                if (tramo.PuertoDesde.IDPuerto == tramo.PuertoHasta.IDPuerto)
                {
                    int tramoIndex = Tramos.IndexOf(tramo);
                    ErrorMessage += "Tramo invalido [" + tramoIndex + "] El puerto desde no puede ser el mismo que el puerto hasta." + System.Environment.NewLine;
                }
            }

            //Validar coherencia de tramos (los puertos deben ser A->B, B->C, C->A)
            //Tramos de la forma A->B, C->A son invalidos)
            try
            {
                TramoViewModel tramoAnterior = null;
                foreach (TramoViewModel tramo in Tramos)
                {
                    //Validar
                    if (tramoAnterior != null)
                    {
                        if (tramoAnterior.PuertoHasta.IDPuerto != tramo.PuertoDesde.IDPuerto)
                        {
                            //El armado de tramos es invalido, el [destino] del anterior deberia coincidir con el [desde] del actual
                            //Con 1 tramo invalido ya mostrar el msj de error
                            throw new Exception("El armado de tramos es inválido. Cada nuevo tramo debe tener como orígen el puerto de destino del tramo anterior");
                        }
                    }
                    tramoAnterior = tramo;
                }
            }
            catch (Exception ex)
            {
                ErrorMessage += ex.Message + System.Environment.NewLine;
            }

            //If error message is empty, object is valid
            return(string.IsNullOrEmpty(ErrorMessage));
        }
Beispiel #6
0
        private string GetDescripcionPuertosInicialYFinal()
        {
            string desc = "";

            if (Tramos != null && Tramos.Count > 0)
            {
                if (Tramos.Count == 1)
                {
                    desc = Tramos.First().PuertoDesde.Nombre + " - " + Tramos.First().PuertoHasta.Nombre;
                }
                else
                {
                    desc = Tramos.First().PuertoDesde.Nombre + " - " + Tramos.Last().PuertoHasta.Nombre;
                }
            }

            return(desc);
        }
Beispiel #7
0
        public virtual Tramo GetTramo(Estacion estacionActual, Sentido sentido)
        {
            Tramo proximoTramo;

            if (sentido == Sentido.IDA)
            {
                proximoTramo = Tramos.First(x => x.EstacionOrigen == estacionActual);
            }
            else
            {
                proximoTramo = Tramos.First(x => x.EstacionDestino == estacionActual);
                Tramo tramoInvertido = new Tramo
                {
                    Distancia       = proximoTramo.Distancia,
                    TiempoViaje     = proximoTramo.TiempoViaje,
                    EstacionOrigen  = proximoTramo.EstacionDestino,
                    EstacionDestino = proximoTramo.EstacionOrigen
                };
                proximoTramo = tramoInvertido;
            }
            return(proximoTramo);
        }