예제 #1
0
 public static string Delete(SegurityViewModel modelo, int id)
 {
     if (!UsuarioBLL.Verify(modelo.token))//No autorizado
     {
         return "No autorizado";
     }
     using (Entities_Bio db = new Entities_Bio())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 Articulo articulo = db.Articuloes.Find(id);
                 if (articulo == null)
                 {
                     return "Articulo no existe";
                 }
                 db.Entry(articulo).State = System.Data.Entity.EntityState.Deleted;
                 db.SaveChanges();
                 transaction.Commit();
                 return "Eliminación correcta";
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }
예제 #2
0
        public static void Delete(int?id)
        {
            using (Entities_Bio db = new Entities_Bio())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Usuario usuario   = db.Usuarios.Find(id);
                        var     articulos = usuario.Articuloes.Where(t => t.idUsuario == id);
                        Venta   venta     = db.Ventas.Find(usuario.idUsuario);
                        var     ventas    = usuario.Ventas.Where(t => t.idUsuario == id);
                        if (articulos != null)
                        {
                            db.Articuloes.RemoveRange(articulos);
                        }
                        if (venta != null)
                        {
                            db.Ventas.RemoveRange(ventas);
                        }

                        db.Entry(usuario).State = System.Data.Entity.EntityState.Deleted;

                        db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
예제 #3
0
        }//end

        public static bool LogOut(int?id)
        {
            //se crea una instancia o un iniverso dentro de otro universo
            //esta instancia se termina aqui
            using (Entities_Bio db = new Entities_Bio())
            {
                try
                {
                    using (var transaction = db.Database.BeginTransaction())
                    {
                        Usuario userLogin = db.Usuarios.Find(id);
                        userLogin.token_temp = null;
                        db.Usuarios.Attach(userLogin);
                        db.Entry(userLogin).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        transaction.Commit();
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }//end
예제 #4
0
        public static List <Usuario> GetUsuario(string criterio)
        {
            //Ejemplo: criterio = 'quin'
            //Posibles resultados => Quintana, Quintero, Pulloquinga, Quingaluisa...
            Entities_Bio db = new Entities_Bio();

            return(db.Usuarios.Where(x => x.nombres.ToLower().Contains(criterio)).ToList());
        }
예제 #5
0
        public static int Get()
        {
            Entities_Bio db    = new Entities_Bio();
            int          value = int.Parse(db.Ventas
                                           .OrderByDescending(p => p.idVenta)
                                           .Select(r => r.idVenta)
                                           .First().ToString());

            return(value);
            //return db.Negocios.LastOrDefault();
        }
예제 #6
0
        public static List <Venta> ListToNames()
        {
            Entities_Bio db     = new Entities_Bio();
            List <Venta> result = new List <Venta>();

            db.Ventas.ToList().ForEach(x =>
                                       result.Add(
                                           new Venta
            {
                idUsuario = x.idUsuario
            }));
            return(result);
        }
예제 #7
0
 public static List<Articulo> ListToNames()
 {
     Entities_Bio db = new Entities_Bio();
     List<Articulo> result = new List<Articulo>();
     db.Articuloes.ToList().ForEach(x =>
         result.Add(
             new Articulo
             {
                 nombre = x.nombre,
                 idArticulo = x.idArticulo
             }));
     return result;
 }
예제 #8
0
        public static List <Usuario> ListToNames()
        {
            Entities_Bio   db     = new Entities_Bio();
            List <Usuario> result = new List <Usuario>();

            db.Usuarios.ToList().ForEach(x =>
                                         result.Add(
                                             new Usuario
            {
                nombres   = x.nombres,
                idUsuario = x.idUsuario
            }));
            return(result);
        }
예제 #9
0
        public static SegurityViewModel Login(string email, string password)
        {
            //se crea una instancia o un iniverso dentro de otro universo
            //esta instancia se termina aqui
            using (Entities_Bio db = new Entities_Bio())
            {
                SegurityViewModel token = new SegurityViewModel();
                try
                {
                    var lst = db.Usuarios.Where(d => d.email == email && d.contrasena == password);
                    //var lst = db.Usuarios.Where(d => d.email == email && d.contrasena == email && d.estado == "a");
                    if (lst.Count() > 0)
                    {
                        using (var transaction = db.Database.BeginTransaction())
                        {
                            Usuario userLogin = lst.First();
                            if (userLogin.token_temp == null)
                            {
                                userLogin.token_temp = Guid.NewGuid().ToString();
                            }
                            db.Usuarios.Attach(userLogin);
                            db.Entry(userLogin).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            transaction.Commit();

                            token.token       = userLogin.token_temp;
                            token.id_logueado = userLogin.idUsuario;
                            token.nombre      = userLogin.nombres + " " + userLogin.apellidos;
                            //token.pathIMG = userLogin.imgPath;
                            return(token);
                        }
                    }
                    else
                    {
                        return(token);
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }//end
예제 #10
0
        //BLL Bussiness Logic Layer
        //Capa de Logica del Negocio

        public static void Create(Articulo a)
        {
            using (Entities_Bio db = new Entities_Bio())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Articuloes.Add(a);
                        db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
예제 #11
0
 public static void Update(Usuario Usuario)
 {
     using (Entities_Bio db = new Entities_Bio())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 db.Usuarios.Attach(Usuario);
                 db.Entry(Usuario).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }
예제 #12
0
 public static void Delete(int?id)
 {
     using (Entities_Bio db = new Entities_Bio())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 Usuario alumno = db.Usuarios.Find(id);
                 db.Entry(alumno).State = System.Data.Entity.EntityState.Deleted;
                 db.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }
예제 #13
0
        }//end

        public static bool Verify(string token)
        {
            using (Entities_Bio db = new Entities_Bio())
            {
                try
                {
                    if (db.Usuarios.Where(x => x.token_temp.Equals(token)).Count() > 0)
                    {
                        return(true);//existe
                    }
                    else
                    {
                        return(false);//no exite
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }//end
예제 #14
0
        //BLL Bussiness Logic Layer
        //Capa de Logica del Negocio

        public static void Create(Venta a)
        {
            using (Entities_Bio db = new Entities_Bio())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        //DateTime thisDay = DateTime.Today;
                        a.fechaVenta = DateTime.Today;
                        db.Ventas.Add(a);
                        db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
예제 #15
0
        /*
         * public static List<Usuario> GetList(string criterio)
         * {
         *  DBBIOEntities db = new DBBIOEntities();
         *  return db.Usuarios.Where(x => x.nombre.ToLower().Contains(criterio)).ToList();
         * }
         */

        public static List <Usuario> GetList()
        {
            Entities_Bio db = new Entities_Bio();

            //Instancia del contexto

            /*List<Alumno> alumons = db.Alumnoes.ToList();
             * List<Alumno> resultado = new List<Alumno>();
             * foreach (Alumno a in alumons) {
             *  if (a.sexo == "M") {
             *      resultado.Add(a);
             *  }
             * }
             * return resultado;*/
            //SQL -> SELECT * FROM dbo.Alumno WHERE sexo = 'M'
            //return db.Alumnoes.Where(x => x.sexo == "M").ToList();

            //return db.Usuarios.Where(x => x.nombre.ToLower().Contains(criterio)).ToList();
            return(db.Usuarios.ToList());

            //Los metodos del EntityFramework se denomina Linq,
            //y la evluacion de condiciones lambda
        }
예제 #16
0
 public static bool Update(Articulo articulo)
 {
     using (Entities_Bio db = new Entities_Bio())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             try
             {
                 db.Articuloes.Attach(articulo);
                 db.Entry(articulo).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 transaction.Commit();
                 return true;
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 return false;
                 //throw ex;
             }
         }
     }
 }
예제 #17
0
        public static string Add(ArticuloViewModel modelo)
        {
            using (Entities_Bio db = new Entities_Bio())
            {
                if (!UsuarioBLL.Verify(modelo.token))//No autorizado
                {
                    return "No autorizado";
                }
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {

                        Articulo a = new Articulo();
                        a.nombre = modelo.nombre;
                        a.precio = modelo.precio;
                        a.categoria = modelo.categoria;
                        a.detalle = modelo.detalle;
                        a.estado = modelo.estado;
                        a.idUsuario = modelo.idUsuario;
                        a.fecha  = modelo.fecha_ingreso;

                        a.imagen = modelo.imagen;

                        db.Articuloes.Add(a);
                        db.SaveChanges();
                        transaction.Commit();
                        return "Articulo creado exitosamente";
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }//end Create
예제 #18
0
        public static List <Articulo> Get_id(int?id)
        {
            Entities_Bio db = new Entities_Bio();

            return(db.Articuloes.Where(x => x.idUsuario == id).ToList());
        }
예제 #19
0
 public static List<Articulo> Get_id_Login(int? id,string criterio)
 {
     Entities_Bio db = new Entities_Bio();
     return db.Articuloes.Where(x => x.idUsuario != id && x.categoria==criterio).ToList();
 }
예제 #20
0
        }//end Create

        public static Articulo Get(int? id)
        {
            Entities_Bio db = new Entities_Bio();
            return db.Articuloes.Find(id);
        }
예제 #21
0
 public static List<Articulo> GetArticulos(string criterio)
 {
     Entities_Bio db = new Entities_Bio();
     return db.Articuloes.Where(x => x.nombre.ToLower().Contains(criterio)).ToList();
 }
예제 #22
0
        public static Venta Get(int?id)
        {
            Entities_Bio db = new Entities_Bio();

            return(db.Ventas.Find(id));
        }
예제 #23
0
        public static List <Negocio> GetList()
        {
            Entities_Bio db = new Entities_Bio();

            return(db.Negocios.ToList());
        }
예제 #24
0
        public static List <Venta> GetList(int id)
        {
            Entities_Bio db = new Entities_Bio();

            return(db.Ventas.Where(x => x.idUsuario == id).ToList());
        }
예제 #25
0
        public static List <Usuario> GetList()
        {
            Entities_Bio db = new Entities_Bio();

            return(db.Usuarios.ToList());
        }
예제 #26
0
        public static List <Usuario> GetUsuario(string criterio)
        {
            Entities_Bio db = new Entities_Bio();

            return(db.Usuarios.Where(x => x.nombres.ToLower().Contains(criterio)).ToList());
        }
예제 #27
0
        public static Negocio Get(int?id)
        {
            Entities_Bio db = new Entities_Bio();

            return(db.Negocios.Find(id));
        }
예제 #28
0
        public static Usuario Get(int?id)
        {
            Entities_Bio db = new Entities_Bio();

            return(db.Usuarios.Find(id));
        }