Example #1
0
 public int paquetesTransito(int id)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             var total = en.Database
                         .SqlQuery <int>("Select SUM(CASE WHEN PuntoControl.orden = a.max THEN 1 ELSE 0 END) as counts from Paquete "
                                         + "LEFT join Trayecto on Paquete.IdTrayecto = Trayecto.id "
                                         + "LEFT join PaquetePuntoControl on Paquete.id = PaquetePuntoControl.idPaquete "
                                         + "LEFT join PuntoControl on PuntoControl.id = PaquetePuntoControl.idPuntoControl "
                                         + "left join("
                                         + "Select PaquetePuntoControl.idPaquete as idPaquete, MAX(PuntoControl.orden) as max from PaquetePuntoControl "
                                         + "join PuntoControl on PuntoControl.id = PaquetePuntoControl.idPuntoControl "
                                         + "WHERE PuntoControl.borrado = 0 AND PaquetePuntoControl.borrado = 0 "
                                         + "Group by PaquetePuntoControl.idPaquete "
                                         + ") AS a on a.idPaquete = Paquete.id "
                                         + "WHERE Paquete.borrado = 0 and Trayecto.id = " + id)
                         .ToList().First();
             return(total);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #2
0
 public SUsuario login(SUsuario u)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Usuario usuario = en.Usuario.First(x => x.email == u.Email);
             if (usuario != null)
             {
                 if (usuario.password == u.Password) // Deberiamos hashear la pass y aca llamariamos a una funcion que compruebe si esta bien o no, por ahora queda asi
                 {
                     if (usuario.emailValido == true)
                     {
                         return(_conv.modeloAEntidad(usuario));
                     }
                     throw new ECompartida("Debe autenticar su correo antes de poder ingresar, por favor revise su email");
                 }
                 throw new ECompartida("La contrase;a no coincide");
             }
             throw new ECompartida("El usuario no existe");
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #3
0
 public void addEmpresa(SEmpresa emp)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Empresa e = new Empresa()
             {
                 nombre  = emp.Nombre,
                 borrado = emp.Borrado
             };
             en.Empresa.Add(e);
             en.SaveChanges();
         }
         catch (DbEntityValidationException e)
         {
             foreach (var eve in e.EntityValidationErrors)
             {
                 Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                   eve.Entry.Entity.GetType().Name, eve.Entry.State);
                 foreach (var ve in eve.ValidationErrors)
                 {
                     Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                       ve.PropertyName, ve.ErrorMessage);
                 }
             }
             throw;
         }
     }
 }
Example #4
0
 public List <EstadisticaDTO> paquetesIngresadosEntregados(string opcion)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             string q = "";
             if (opcion == "ingresado")
             {
                 q = "Select CONVERT(varchar, CAST(Paquete.fechaIngreso as date), 1) as x, COUNT(Paquete.id) as y from Paquete where Paquete.fechaIngreso >= DATEADD(DAY, -7, GETDATE()) group by CAST(Paquete.fechaIngreso as date)";
             }
             else
             {
                 q = "Select CONVERT(varchar, CAST(Paquete.fechaEntrega as date), 1) as x, COUNT(Paquete.id) as y from Paquete where Paquete.fechaEntrega >= DATEADD(DAY, -7, GETDATE()) group by CAST(Paquete.fechaEntrega as date)";
             }
             var estadisticas = en.Database
                                .SqlQuery <EstadisticaDTO>(q)
                                .ToList();
             return(estadisticas);
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Example #5
0
        public STrayecto updateTrayecto(STrayecto a)
        {
            using (trackingFULLEntities en = new trackingFULLEntities())
            {
                try
                {
                    List <string> ids = new List <string>();
                    foreach (SEAPuntoControlAgencia p in a.ListaPuntosControl)
                    {
                        if (p.Id != null)
                        {
                            ids.Add(((int)p.Id).ToString());
                        }
                    }
                    String query = "Select * from PuntoControl WHERE PuntoControl.borrado = 0 and PuntoControl.idTrayecto = " + a.Id;
                    if (ids.Count > 0)
                    {
                        query += " and id NOT IN(" + string.Join(", ", ids) + ")";
                    }
                    en.Database.SqlQuery <SPuntoControl>(query).ToList().ForEach(x =>
                    {
                        x.Borrado = true;
                        en.SaveChanges();
                    });

                    Trayecto ag = en.Trayecto.Find(a.Id);
                    ag = _conv.entidadAModelo(a, ag);
                    DALPuntoControl dalp = new DALPuntoControl();
                    if (a.ListaPuntosControl != null)
                    {
                        a.ListaPuntosControl.ToList().ForEach(x =>
                        {
                            x.IdTrayecto = ag.id;
                            if (x.Id > 0)
                            {
                                dalp.updatePuntoControl(x);
                            }
                            else
                            {
                                dalp.addPuntoControl(x);
                            }
                        });
                    }
                    en.SaveChanges();
                    return(_conv.modeloAEntidad(ag));
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #6
0
 public string getRol(string email)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             return(en.Usuario.First(x => x.email == email).rol);
         }
         catch (Exception e)
         {
             return(e.ToString());
         }
     }
 }
Example #7
0
 public SAgencia getAgencia(int id)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             return(_conv.modeloAEntidad(en.Agencia.Find(id)));
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Example #8
0
 public SPaquete getPaquete(int id)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             return(_conv.modeloAEntidad(en.Paquete.Find(id)));
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Example #9
0
 public STrayecto getTrayecto(int id)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             return(_conv.modeloAEntidad(en.Trayecto.Find(id)));
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Example #10
0
 public SPuntoControl getPuntoControl(int id)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             return(_conv.modeloAEntidad(en.PuntoControl.Find(id)));
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Example #11
0
 public string getCodigoConfirmacionEmail(int id)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Usuario u = en.Usuario.Find(id);
             return(u.codigoConfirmacion);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #12
0
 public SAgencia addAgencia(SAgencia a)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Agencia ag = en.Agencia.Add(_conv.entidadAModelo(a));
             en.SaveChanges();
             return(_conv.modeloAEntidad(ag));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #13
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;
         }
     }
 }
Example #14
0
 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;
         }
     }
 }
Example #15
0
 public List <EstadisticaDTO> trayectoPaquete()
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             var estadisticas = en.Database
                                .SqlQuery <EstadisticaDTO>("Select Trayecto.nombre as x, COUNT(Paquete.id) as y from Trayecto left join Paquete on Paquete.fechaIngreso = Paquete.fechaEntrega and Paquete.IdTrayecto = Trayecto.id group by Trayecto.nombre")
                                .ToList();
             return(estadisticas);
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Example #16
0
 public SUsuario updateUsuario(SUsuario a)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Usuario ag = en.Usuario.Find(a.Id);
             ag = _conv.entidadAModelo(a, ag);
             en.SaveChanges();
             return(_conv.modeloAEntidad(ag));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #17
0
 public SUsuario newAdmin(int id)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Usuario u = en.Usuario.Find(id);
             u.rol = "SuperAdmin";
             en.SaveChanges();
             return(_conv.modeloAEntidad(u));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #18
0
 public SPaquete updatePaquete(SPaquete a)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Paquete ag = en.Paquete.Find(a.Id);
             ag = _conv.entidadAModelo(a, ag);
             en.SaveChanges();
             return(_conv.modeloAEntidad(ag));
         }
         catch (Exception e)
         {
             throw;
         }
     }
 }
Example #19
0
 public STrayecto addTrayecto(STrayecto a)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Trayecto ag = en.Trayecto.Add(_conv.entidadAModelo(a));
             if (a.ListaPuntosControl != null)
             {
                 a.ListaPuntosControl.ForEach(x =>
                 {
                     ag.PuntoControl.Add(_conv.entidadAModelo(x));
                 });
             }
             else
             {
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "Recibido en origen", orden = 1, tiempo = 0, borrado = false
                 });
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "Esperando en origen", orden = 2, tiempo = 0, borrado = false
                 });
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "En viaje", orden = 3, tiempo = 0, borrado = false
                 });
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "Recibido en destino", orden = 4, tiempo = 0, borrado = false
                 });
                 ag.PuntoControl.Add(new PuntoControl()
                 {
                     nombre = "Entregado al cliente", orden = 5, tiempo = 0, borrado = false
                 });
             }
             en.SaveChanges();
             return(_conv.modeloAEntidad(ag));
         }
         catch (Exception e)
         {
             throw;
         }
     }
 }
Example #20
0
        public string deletePuntoControl(int id)
        {
            using (trackingFULLEntities en = new trackingFULLEntities())
            {
                try
                {
                    PuntoControl a = en.PuntoControl.Find(id);
                    a.borrado = true;
                    en.SaveChanges();

                    return(null);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #21
0
        public string deleteTrayecto(int id)
        {
            using (trackingFULLEntities en = new trackingFULLEntities())
            {
                try
                {
                    Trayecto a = en.Trayecto.Find(id);
                    a.borrado = true;
                    en.SaveChanges();

                    return(null);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #22
0
        public string deleteCliente(int id)
        {
            using (trackingFULLEntities en = new trackingFULLEntities())
            {
                try
                {
                    Cliente a = en.Cliente.Find(id);
                    a.borrado = true;
                    en.SaveChanges();

                    return(null);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #23
0
        public string deleteAgencia(int id)
        {
            using (trackingFULLEntities en = new trackingFULLEntities())
            {
                try
                {
                    Agencia a = en.Agencia.Find(id);
                    a.borrado = true;
                    en.SaveChanges(); // Que pasa con las demas entidades que tienen a esta agencia como FK????

                    return(null);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #24
0
 public SUsuario getUsuarioByEmail(string email)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Usuario u = en.Usuario.FirstOrDefault(x => x.email == email);
             if (u != null && u.borrado == false)
             {
                 return(_conv.modeloAEntidad(u));
             }
             return(null);
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Example #25
0
 public SUsuario addUsuario(SUsuario u)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Usuario usuario = _conv.entidadAModelo(u);
             usuario.codigoConfirmacion = Randoms.RandomString(100);
             usuario.emailValido        = true;
             en.Usuario.Add(usuario);
             en.SaveChanges();
             return(_conv.modeloAEntidad(usuario));
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #26
0
 public bool isActive(int id)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             PuntoControl a = en.PuntoControl.Find(id);
             if ((bool)a.borrado)
             {
                 return(false);
             }
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #27
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;
         }
     }
 }
Example #28
0
 public SCliente getClienteByEmail(string email)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Cliente a = en.Cliente.FirstOrDefault(x => x.email == email);
             if (a == null)
             {
                 return(null);
             }
             return(_conv.modeloAEntidad(a));
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Example #29
0
 public SPaquete consultaEstado(int idCliente, string codigo)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Paquete dom = en.Paquete.Where(x => x.idDestinatario == idCliente && x.codigoConfirmacion == codigo).FirstOrDefault();
             if (dom != null)
             {
                 return(_conv.modeloAEntidad(dom));
             }
             throw new ECompartida("No se encontro ningun paquete para tu usuario con el codigo dado");
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #30
0
 public SPaquete addPaquete(SPaquete a)
 {
     using (trackingFULLEntities en = new trackingFULLEntities())
     {
         try
         {
             Paquete ag = en.Paquete.Add(_conv.entidadAModelo(a));
             en.SaveChanges();
             SPaquete p = _conv.modeloAEntidad(ag);
             //en.Domicilio5.Add(new Domicilio5() { idPaquete = (int)p.Id, envio = false });
             //en.SaveChanges();
             return(p);
         }
         catch (Exception e)
         {
             throw;
         }
     }
 }