Beispiel #1
0
 public IHttpActionResult GetId(int id)
 {
     try
     {
         BLPaquete bl       = new BLPaquete();
         SPaquete  p        = bl.getPaquete(id);
         string    rolToken = TokenInfo.getClaim(Request, "role");
         if (rolToken == "Cliente")
         {
             string    emailToken = TokenInfo.getClaim(Request, "email");
             BLCliente blc        = new BLCliente();
             SCliente  c          = blc.getClienteByEmail(emailToken);
             if (p.IdDestinatario == c.Id || p.IdRemitente == c.Id)
             {
                 return(Ok(p));
             }
             else
             {
                 throw new ECompartida("Alto ahi maleante! No tienes acceso a esta informacion");
             }
         }
         else
         {
             return(Ok(p));
         }
     }
     catch (Exception e)
     {
         return(Content(HttpStatusCode.InternalServerError, e.Message));
     }
 }
Beispiel #2
0
 public SCliente updateCliente(SCliente a)
 {
     try
     {
         return(_dal.updateCliente(a));
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #3
0
 public Cliente entidadAModelo(SCliente c, Cliente cl)
 {
     cl.id              = c.Id;
     cl.email           = c.Email;
     cl.nombreCompleto  = c.NombreCompleto;
     cl.tipoDocumento   = c.TipoDocumento;
     cl.numeroDocumento = c.NumeroDocumento;
     cl.telefono        = c.Telefono;
     cl.borrado         = c.Borrado;
     return(cl);
 }
Beispiel #4
0
 public SCliente addCliente(SCliente a)
 {
     try
     {
         if (validacion(a))
         {
             return(_dal.addCliente(a));
         }
         throw new ECliente("Algun error raro del carajo");
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #5
0
        public Cliente entidadAModelo(SCliente c)
        {
            Cliente cliente = new Cliente()
            {
                id              = c.Id,
                email           = c.Email,
                nombreCompleto  = c.NombreCompleto,
                tipoDocumento   = c.TipoDocumento,
                numeroDocumento = c.NumeroDocumento,
                telefono        = c.Telefono,
                borrado         = c.Borrado
            };

            return(cliente);
        }
Beispiel #6
0
 public SCliente addCliente(SCliente a)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Cliente ag = en.Cliente.Add(_conv.entidadAModelo(a));
             en.SaveChanges();
             return(_conv.modeloAEntidad(ag));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Beispiel #7
0
 public string consultarEstado(string codigo, string email)
 {
     try
     {
         BLCliente _blC = new BLCliente();
         SCliente  c    = _blC.getClienteByEmail(email);
         SPaquete  p    = _dal.consultaEstado(c.Id, codigo);
         if (p.FechaEntrega == p.FechaIngreso)
         {
             return("El paquete se encuentra en viaje actualmente, para mas detalles: " + Direcciones.Web + "paquete/details/" + p.Id);
         }
         return("El paquete ya fue entregado, para mas detalles: " + Direcciones.Web + "paquete/details/" + p.Id);
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #8
0
 public bool updateEnvioDomicilio(SDomicilio d, string email)
 {
     try
     {
         SPaquete  p    = getPaquete(d.IdPaquete);
         BLCliente _blC = new BLCliente();
         SCliente  c    = _blC.getCliente((int)p.IdDestinatario);
         if (c.Email == email)
         {
             return(_dal.updateEnvioDomicilio(d));
         }
         throw new ECompartida("No tienes permisos para realizar esta accion");
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #9
0
 public List <SPaquete> paquetesRecibidos(string email) // el email es del que realizo la peticion
 {
     try
     {
         BLCliente bl = new BLCliente();
         SCliente  c  = bl.getClienteByEmail(email);
         if (c.Email != null)
         {
             BLPaquete blp = new BLPaquete();
             return(blp.paquetesRecibidos(c.Id));
         }
         throw new ECompartida("No tienes permisos suficientes para realizar esta accion");
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #10
0
 public dynamic detallesPaquete(string email, string role, int idPaquete)
 {
     try
     {
         SPaquete  paquete   = this.getPaquete(idPaquete);
         BLCliente blCliente = new BLCliente();
         if (role != "Admin")
         {
             SCliente cliente = blCliente.getClienteByEmail(email);
             if (cliente != null)
             {
                 if (cliente.Id != paquete.IdDestinatario && cliente.Id != paquete.IdRemitente)
                 {
                     throw new ECompartida("No tienes acceso a la informacion de este paquete");
                 }
             }
             else
             {
                 throw new ECompartida("El email enviado en la solicitud no pertenece a un cliente del sistema");
             }
         }
         SCliente       Remitente      = blCliente.getCliente((int)paquete.IdRemitente);
         SCliente       Destinatario   = blCliente.getCliente((int)paquete.IdDestinatario);
         BLTrayecto     bLTrayecto     = new BLTrayecto();
         STrayecto      Trayecto       = bLTrayecto.getTrayecto((int)paquete.IdTrayecto);
         BLPuntoControl bLPuntoControl = new BLPuntoControl();
         Trayecto.ListaPuntosControl = bLPuntoControl.puntosControlDeUnTrayecto((int)paquete.IdTrayecto);
         BLPaquetePuntoControl       bLPaquetePuntoControl = new BLPaquetePuntoControl();
         List <SPaquetePuntoControl> PaquetePuntosControl  = bLPaquetePuntoControl.puntosControlDeUnPaquete((int)paquete.Id);
         dynamic respuesta = new ExpandoObject();
         respuesta.IdTrayecto          = paquete.Id;
         respuesta.Qr                  = paquete.Codigo;
         respuesta.Trayecto            = Trayecto;
         respuesta.Remitente           = Remitente;
         respuesta.Destinatario        = Destinatario;
         respuesta.PaquetePuntoControl = PaquetePuntosControl;
         return(respuesta);
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #11
0
        //CLIENTE

        public SCliente modeloAEntidad(Cliente c)
        {
            if (c == null)
            {
                return(null);
            }
            SCliente cliente = new SCliente()
            {
                Id              = c.id,
                Email           = c.email,
                NombreCompleto  = c.nombreCompleto,
                TipoDocumento   = c.tipoDocumento,
                NumeroDocumento = c.numeroDocumento,
                Telefono        = c.telefono,
                Borrado         = (bool)c.borrado
            };

            return(cliente);
        }
Beispiel #12
0
 public bool existe(SCliente c)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Cliente a = en.Cliente.FirstOrDefault(x => x.email == c.Email);
             if (a != null)
             {
                 return(true);
             }
             return(false);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Beispiel #13
0
        public List <SCliente> nuevoPaquete(List <SCliente> clientes)
        {
            List <SCliente> clientesRespuesta = new List <SCliente>();

            try
            {
                clientes.ForEach(x =>
                {
                    x.Borrado = false;
                    x.Id      = 0;
                    if (!_dal.existe(x))
                    {
                        clientesRespuesta.Add(_dal.addCliente(x));
                    }
                    else
                    {
                        SCliente c       = _dal.getClienteByEmail(x.Email);
                        c.NombreCompleto = x.NombreCompleto;
                        c.Telefono       = x.Telefono;
                        c.Borrado        = x.Borrado;
                        if (x.TipoDocumento != null)
                        {
                            if (x.TipoDocumento == "CI" || x.NumeroDocumento == "Pasaporte")
                            {
                                c.NumeroDocumento = x.NumeroDocumento;
                                c.TipoDocumento   = x.TipoDocumento;
                            }
                            else
                            {
                                throw new ECliente("El tipo de documento indicado no es valido");
                            }
                        }
                        clientesRespuesta.Add(_dal.updateCliente(c));
                    }
                });
                return(clientesRespuesta);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #14
0
 public bool validacion(SCliente c)
 {
     try
     {
         if (!_dal.existe(c))
         {
             if (c.NumeroDocumento != null)
             {
                 if (c.TipoDocumento.ToUpper() != "CI".ToUpper() && c.TipoDocumento.ToUpper() != "Pasaporte".ToUpper())
                 {
                     throw new ECliente("El tipo de documento indicado no es valido");
                 }
             }
             return(true);
         }
         throw new ECliente("El email o el numero de documento ya esta registrado en el sistema");
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #15
0
        public IHttpActionResult Authenticate(SAEData d)
        {
            try
            {
                SUsuario    usuario        = d.usuario;
                SEATrayecto trayecto       = d.trayecto;
                STrayecto   ActualTrayecto = null;

                SAEPaquete p = d.paquete;

                BLCliente bl        = new BLCliente();
                BLUsuario blusuario = new BLUsuario();
                SUsuario  oUsuario  = blusuario.login(usuario);
                BLPaquete blPaquete = new BLPaquete();

                if (usuario == null)
                {
                    return(Content(HttpStatusCode.Unauthorized, "El usuario no existe"));
                }
                else if (oUsuario.Rol != "Admin" && oUsuario.Rol != "Funcionario" && oUsuario.Rol != "Encargado")
                {
                    return(Content(HttpStatusCode.Unauthorized, "El usuario no esta autorisado para usar elte servicio"));
                }

                if (p.adelanta != null)
                {
                    if (p.Id == null)
                    {
                        return(Content(HttpStatusCode.Unauthorized, "Error en paquete, se intento adelantar pero no se recibio el identificador"));
                    }
                    else
                    {
                        return(Ok(blPaquete.avanzar(new SPaquetePuntoControl()
                        {
                            IdPaquete = (int)p.Id, IdEmpleado = oUsuario.Id
                        })));
                    }
                }
                if (p.atrasa != null)
                {
                    if (p.Id == null)
                    {
                        return(Content(HttpStatusCode.Unauthorized, "Error en paquete, se intento retroceder pero no se recibio el identificador"));
                    }
                    else
                    {
                        return(Ok(blPaquete.retroceder(new SPaquetePuntoControl()
                        {
                            IdPaquete = (int)p.Id, IdEmpleado = oUsuario.Id
                        })));
                    }
                }
                if (p.entrega != null)
                {
                    if (p.Id == null)
                    {
                        return(Content(HttpStatusCode.Unauthorized, "Error en paquete, se intento entregar pero no se recibio el identificador"));
                    }
                    else if (p.code == null)
                    {
                        return(Content(HttpStatusCode.Unauthorized, "Error en paquete, se intento entregar pero no se recibio el codigo"));
                    }
                    else
                    {
                        return(Ok(blPaquete.entregaCliente(new SPaquetePuntoControl()
                        {
                            IdEmpleado = oUsuario.Id,
                            IdPaquete = (int)p.Id
                        }, p.code)));
                    }
                }


                STrayecto t = trayecto;
                if ((p.IdDestinatario == p.IdRemitente && p.IdRemitente != null) ||
                    (p.Remitente != null && p.Destinatario != null && p.Destinatario.NumeroDocumento == p.Remitente.NumeroDocumento))
                {
                    return(Content(HttpStatusCode.NotFound, "Error en el paquete, el destinatario no puede ser el remitente"));
                }
                string sMsg = p.validacion();
                if (sMsg != "")
                {
                    return(Content(HttpStatusCode.NotFound, sMsg));
                }
                else
                {
                    SCliente cActualDestinatario = null;
                    SCliente cActualRemitente    = null;
                    if (p.IdDestinatario != null)
                    {
                        cActualDestinatario = bl.getCliente((int)p.IdDestinatario);
                    }
                    else
                    {
                        bl.validacion(p.Destinatario);
                    }
                    if (p.IdRemitente != null)
                    {
                        cActualRemitente = bl.getCliente((int)p.IdRemitente);
                    }
                    else
                    {
                        bl.validacion(p.Remitente);
                    }


                    if (cActualDestinatario == null && p.Destinatario == null)
                    {
                        return(Content(HttpStatusCode.NotFound, "Error en el paquete, el destinatario no existe en el sistema"));
                    }
                    if (cActualRemitente == null && p.Remitente == null)
                    {
                        return(Content(HttpStatusCode.NotFound, "Error en el paquete, el remitente no existe en el sistema"));
                    }

                    if (p.IdTrayecto != null && p.IdTrayecto != t.Id)
                    {
                        return(Content(HttpStatusCode.NotFound, "Error en el paquete, no pertenece al trayecto enviado"));
                    }
                    else if (trayecto == null && d.IdTrayecto == null)
                    {
                        return(Content(HttpStatusCode.NotFound, "Error en el trayecto, faltan los datos"));
                    }
                    else if (d.IdTrayecto != null)
                    {
                        BLTrayecto blTrayecto = new BLTrayecto();
                        ActualTrayecto = blTrayecto.getTrayecto((int)d.IdTrayecto);
                        if (ActualTrayecto == null)
                        {
                            return(Content(HttpStatusCode.NotFound, "El trayecto no existe."));
                        }
                    }
                    else if (trayecto != null)
                    {
                        BLTrayecto blTrayecto = new BLTrayecto();

                        string sMsgTrayecto = trayecto.validasionCrearAgencias();
                        if (sMsgTrayecto != "")
                        {
                            return(Content(HttpStatusCode.NotFound, sMsgTrayecto));
                        }
                        else if (trayecto.Id == null)
                        {
                            ActualTrayecto = blTrayecto.addTrayecto(creaAgencias(trayecto));
                        }
                        else
                        {
                            if (blTrayecto.paquetesTransito(trayecto) != 0)
                            {
                                return(Content(HttpStatusCode.NotFound, "Hay paquetes en transito"));
                            }
                            else
                            {
                                ActualTrayecto = blTrayecto.updateTrayecto(creaAgencias(trayecto));
                            }
                        }
                    }

                    if (p.IdTrayecto == null)
                    {
                        p.IdTrayecto = ActualTrayecto.Id;
                    }
                    if (p.Destinatario != null && cActualDestinatario != null)
                    {
                        cActualDestinatario = bl.updateCliente(p.Destinatario);
                    }
                    else if (p.Destinatario != null && cActualDestinatario == null)
                    {
                        p.Destinatario.Id   = 0;
                        cActualDestinatario = bl.addCliente(p.Destinatario);
                    }
                    if (p.Remitente != null && cActualRemitente != null)
                    {
                        cActualRemitente = bl.updateCliente(p.Remitente);
                    }
                    else if (p.Remitente != null && cActualRemitente == null)
                    {
                        p.Remitente.Id   = 0;
                        cActualRemitente = bl.addCliente(p.Remitente);
                    }
                    p.IdDestinatario = cActualDestinatario.Id;
                    p.IdRemitente    = cActualRemitente.Id;
                    SPaquete np = null;
                    if (p.Id == null)
                    {
                        np = blPaquete.addPaquete(p);
                    }
                    else
                    {
                        np = blPaquete.updatePaquete(p);
                    }
                    return(Ok(new SAERespuesta()
                    {
                        usuario = usuario,
                        trayecto = t,
                        paquete = np
                    }));
                }
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.InternalServerError, e.Message));
            }
        }