public bool retroceder(SPaquetePuntoControl ppc) { try { var _dalPPC = new DALPaquetePuntoControl(); List <SPaquetePuntoControl> ppcList = _dalPPC.getAllByPaquete(ppc.IdPaquete); if (ppcList.Count() > 0) { int ppcAEliminarId = ppcList.Max(x => x.Id); SPaquetePuntoControl ppcAEliminar = ppcList.First(x => x.Id == ppcAEliminarId); if (ppcAEliminar != null) { var _dalU = new DALUsuario(); SUsuario empleado = _dalU.getUsuario(ppc.IdEmpleado); if ((empleado.Rol == "Funcionario" && empleado.Id == ppcAEliminar.IdEmpleado) || empleado.Rol == "Encargado" || empleado.Rol == "Admin") { BLEmail.actualizacionEstado(new BLPaquete().getPaquete(ppc.IdPaquete)); return(_dalPPC.deletePaquetePuntoControl(ppcAEliminar.Id)); } else { throw new ECompartida("El usuario que realizo la peticion no tiene autorizacion para realizar esta operacion"); } } throw new ECompartida("No se encontro ningun paquete con el ID enviado"); } throw new ECompartida("No se puede retroceder mas el paquete"); } catch (Exception) { throw; } }
public PaquetePuntoControl entidadAModelo(SPaquetePuntoControl p, PaquetePuntoControl pc) { pc.id = p.Id; pc.idPaquete = p.IdPaquete; pc.idEmpleado = p.IdEmpleado; pc.idPuntoControl = p.IdPuntoControl; pc.fechaLlegada = p.FechaLlegada; pc.retraso = p.Retraso; pc.borrado = p.Borrado; return(pc); }
public SPaquetePuntoControl updatePaquetePuntoControl(SPaquetePuntoControl a) { try { return(_dal.updatePaquetePuntoControl(a)); } catch (Exception) { throw; } }
public SPaquetePuntoControl entregaCliente(SPaquetePuntoControl ppc, string codigo) { try { SPaquete p = _dal.getPaquete(ppc.IdPaquete); if (p.CodigoConfirmacion == codigo) { var _dalPPC = new DALPaquetePuntoControl(); var _dalPC = new DALPuntoControl(); var _dalT = new DALTrayecto(); ppc.FechaLlegada = DateTime.Now; ppc.Borrado = false; var pclist = _dalPC.puntosControlDeUnTrayecto((int)p.IdTrayecto); ppc.IdPuntoControl = pclist.Max(x => (int)x.Id); List <SPaquetePuntoControl> ppcList = _dalPPC.getAllByPaquete((int)p.Id); ppcList.ForEach(x => { if (x.IdPuntoControl == ppc.IdPuntoControl) { throw new ECompartida("El paquete ya fue entregado al cliente anteriormente"); } }); if (ppcList.Count != (pclist.Count - 1)) { throw new ECompartida("Aun falta avanzar pasos antes de poder entregar al cliente"); } int tiempoEstimado = 0; pclist.ForEach(x => { if (x.Orden <= pclist.First(z => z.Id == ppc.IdPuntoControl).Orden) { tiempoEstimado += x.Tiempo; } }); int tiempoViaje = (p.FechaIngreso - ppc.FechaLlegada).Seconds; if ((tiempoViaje <= tiempoEstimado)) { ppc.Retraso -= (tiempoEstimado - tiempoViaje); } else { ppc.Retraso += (tiempoViaje - tiempoEstimado); } return(_dalPPC.addPaquetePuntoControl(ppc)); } throw new ECompartida("El codigo no coincide con el paquete"); } catch (Exception) { throw; } }
public PaquetePuntoControl entidadAModelo(SPaquetePuntoControl p) { PaquetePuntoControl paquetePuntoControl = new PaquetePuntoControl() { id = p.Id, idPaquete = p.IdPaquete, idEmpleado = p.IdEmpleado, idPuntoControl = p.IdPuntoControl, fechaLlegada = p.FechaLlegada, retraso = p.Retraso, borrado = p.Borrado }; return(paquetePuntoControl); }
public SPaquetePuntoControl addPaquetePuntoControl(SPaquetePuntoControl a) { using (trackingFULLEntities en = new trackingFULLEntities()) { try { PaquetePuntoControl ag = en.PaquetePuntoControl.Add(_conv.entidadAModelo(a)); en.SaveChanges(); return(_conv.modeloAEntidad(ag)); } catch (Exception) { throw; } } }
static public string actualizacionEstado(SPaquete paquete) //blpaquete linea 133, 176 { try { var client = new RestClient("https://api.sendinblue.com/v3/smtp/email"); var request = setRequest("post"); BLTrayecto _blT = new BLTrayecto(); BLPaquete _blP = new BLPaquete(); var dp = _blP.detallesPaquete("", "Admin", (int)paquete.Id); DateTime tiempoEstimado = DateTime.Now; string paquetePuntoControl = ""; SPaquetePuntoControl ppcActual = new SPaquetePuntoControl() { Id = 0 }; foreach (var item in dp.PaquetePuntoControl) { if (item.Id > ppcActual.Id) { ppcActual = item; } } foreach (var item in dp.Trayecto.ListaPuntosControl) { if (item.Id > ppcActual.Id) { tiempoEstimado = tiempoEstimado.AddSeconds(item.Tiempo); } if (item.Id == ppcActual.IdPuntoControl) { paquetePuntoControl += "||" + item.Nombre + " / Tu paquete se encuentra aquĆ actualmente || - "; } else { paquetePuntoControl += item.Nombre + " - "; } } request.AddParameter("application/json", "{\"sender\":{\"email\":\"[email protected]\"},\"to\":[{\"email\":\"" + dp.Destinatario.Email + "\"}],\"replyTo\":{\"email\":\"[email protected]\"},\"templateId\":3,\"params\":{\"remitenteNombre\":\"" + dp.Remitente.NombreCompleto + "\",\"remitenteEmail\":\"" + dp.Remitente.Email + "\",\"remitenteTelefono\":\"" + dp.Remitente.Telefono + "\",\"codigoEntrega\":\"" + paquete.CodigoConfirmacion + "\",\"puntoControlPaquete\":\"" + paquetePuntoControl + "\",\"fechaEntregaEstimada\":\"" + tiempoEstimado.ToString() + "\"}}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); return(response.Content); } catch (Exception) { throw; } }
//PAQUETE - PUNTO DE CONTROL public SPaquetePuntoControl modeloAEntidad(PaquetePuntoControl p) { if (p == null) { return(null); } SPaquetePuntoControl paquetePuntoControl = new SPaquetePuntoControl() { Id = p.id, IdPaquete = (int)p.idPaquete, IdEmpleado = (int)p.idEmpleado, IdPuntoControl = (int)p.idPuntoControl, FechaLlegada = (DateTime)p.fechaLlegada, Retraso = (int)p.retraso, Borrado = (bool)p.borrado }; return(paquetePuntoControl); }
public IHttpActionResult entregaCliente(int IdPaquete, string codigo) { try { string email = TokenInfo.getClaim(Request, "email"); BLUsuario _blU = new BLUsuario(); SUsuario u = _blU.getUsuarioByEmail(email); BLPaquete bl = new BLPaquete(); SPaquetePuntoControl ppc = new SPaquetePuntoControl() { IdEmpleado = u.Id, IdPaquete = IdPaquete }; return(Ok(bl.entregaCliente(ppc, codigo))); } catch (Exception e) { return(Content(HttpStatusCode.InternalServerError, e.Message)); } }
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; } }