public SPuntoControl updatePuntoControl(SPuntoControl a) { try { if (a.Orden < 1) { throw new ECompartida("El orden debe ser mayor a cero"); } List <SPuntoControl> pclist = puntosControlDeUnTrayecto((int)a.IdTrayecto); pclist.ForEach(x => { if (x.Orden == a.Orden) { if (x.Id != a.Id) { throw new ECompartida("Ya existe un punto de control con el mismo orden"); } } }); return(_dal.updatePuntoControl(a)); } catch (Exception) { throw; } }
public PuntoControl entidadAModelo(SPuntoControl p, PuntoControl pc) { pc.id = (int)p.Id; pc.idTrayecto = (int)p.IdTrayecto; pc.orden = p.Orden; pc.tiempo = p.Tiempo; pc.borrado = p.Borrado; pc.nombre = p.Nombre; if (p.IdAgencia != null) { pc.idAgencia = p.IdAgencia; } return(pc); }
public SPuntoControl addPuntoControl(SPuntoControl a) { using (trackingFULLEntities en = new trackingFULLEntities()) { try { PuntoControl ag = en.PuntoControl.Add(_conv.entidadAModelo(a)); en.SaveChanges(); return(_conv.modeloAEntidad(ag)); } catch (Exception) { throw; } } }
public IHttpActionResult editPuntoControl(SPuntoControl pc) { try { BLPuntoControl bl = new BLPuntoControl(); BLTrayecto blT = new BLTrayecto(); if (!blT.paquetesEnTransito((int)pc.IdTrayecto)) { return(Ok(bl.updatePuntoControl(pc))); } throw new ECompartida("Hay paquetes en transito en este trayecto actualmente"); } catch (Exception e) { return(Content(HttpStatusCode.InternalServerError, e.Message)); } }
public PuntoControl entidadAModelo(SPuntoControl p) { PuntoControl puntoControl = new PuntoControl() { idTrayecto = p.IdTrayecto, orden = p.Orden, tiempo = p.Tiempo, borrado = p.Borrado, nombre = p.Nombre }; if (p.Id != null) { puntoControl.id = (int)p.Id; } if (p.IdAgencia != null) { puntoControl.idAgencia = p.IdAgencia; } return(puntoControl); }
//PUNTO DE CONTROL public SPuntoControl modeloAEntidad(PuntoControl p) { if (p == null) { return(null); } SPuntoControl puntoControl = new SPuntoControl() { Id = p.id, IdTrayecto = (int)p.idTrayecto, Orden = (int)p.orden, Tiempo = (int)p.tiempo, Borrado = (bool)p.borrado, Nombre = p.nombre }; if (p.idAgencia != null) { puntoControl.IdAgencia = p.idAgencia; } return(puntoControl); }
public SPaquetePuntoControl avanzar(SPaquetePuntoControl ppc) { try { var _dalPPC = new DALPaquetePuntoControl(); var _dalPC = new DALPuntoControl(); var _dalT = new DALTrayecto(); SPaquete p = _dal.getPaquete(ppc.IdPaquete); if (p != null && p.Borrado == false) { STrayecto t = _dalT.getTrayecto((int)p.IdTrayecto); List <SPaquetePuntoControl> ppcList = _dalPPC.getAllByPaquete((int)p.Id); ppc.FechaLlegada = DateTime.Now; ppc.Borrado = false; if (ppcList.Count > 0) { if (t.ListaPuntosControl.Max(x => x.Orden) > ppcList.Max(y => t.ListaPuntosControl.First(z => z.Id == y.IdPuntoControl).Orden) + 1) { SPuntoControl pcActual = t.ListaPuntosControl.First(x => x.Orden == ppcList.Max(y => t.ListaPuntosControl.First(z => z.Id == y.IdPuntoControl).Orden) + 1); ppc.IdPuntoControl = (int)t.ListaPuntosControl.First(x => x.Orden == pcActual.Orden).Id; int tiempoEstimado = 0; t.ListaPuntosControl.ForEach(x => { if (x.Orden <= pcActual.Orden) { tiempoEstimado += x.Tiempo; } }); int tiempoViaje = (p.FechaIngreso - ppc.FechaLlegada).Seconds; if ((tiempoViaje <= tiempoEstimado)) { ppc.Retraso -= (tiempoEstimado - tiempoViaje); } else { ppc.Retraso += (tiempoViaje - tiempoEstimado); } BLEmail.actualizacionEstado(new BLPaquete().getPaquete(ppc.IdPaquete)); return(_dalPPC.addPaquetePuntoControl(ppc)); } else if (t.ListaPuntosControl.Max(x => x.Orden) == ppcList.Max(y => t.ListaPuntosControl.First(z => z.Id == y.IdPuntoControl).Orden) + 1) { throw new ECompartida("Solo queda el ultimo paso de entrega, para esto debe realizar la peticion correspondiente enviando el codigo proporcionado por el cliente"); } else { throw new ECompartida("El paquete ya llego a su punto final, no se puede avanzar mas"); } } else { ppc.IdPuntoControl = (int)t.ListaPuntosControl.First(x => x.Orden == 1).Id; return(_dalPPC.addPaquetePuntoControl(ppc)); } } throw new ECompartida("Error"); } catch (Exception) { throw; } }