Пример #1
0
        public void guardarProveedor(proveedor proveedor)
        {
            proveedor proveedorExiste = obtenerProveedorID(proveedor.id);

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    if (proveedorExiste == null)
                    {
                        //Guarda el proveedor
                        cdt.proveedor.Add(proveedor);
                        cdt.SaveChanges();
                    }
                    else
                    {
                        //Guarda el proveedor modificado
                        cdt.proveedor.Add(proveedor);
                        cdt.Entry(proveedor).State = EntityState.Modified;
                        cdt.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #2
0
        public void crearInventario(List <producto> produc, inventario inventa, String[] estante, String[] prove)
        {
            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    //salvar primero el inventario, luego los productos
                    cdt.inventario.Add(inventa);

                    //llenar estante, producto, inventario y proveedor
                    foreach (var productoItem in produc)
                    {
                        detalleFactura df = new detalleFactura();
                        df.idInventario     = inventa.id;
                        df.idProducto       = productoItem.id;
                        df.idProveedor      = int.Parse(prove[0]);
                        df.idEstante        = int.Parse(estante[0]);
                        df.precio           = productoItem.costoUnitario;
                        df.cantidadComprada = productoItem.totalStock;

                        cdt.detalleFactura.Add(df);
                    }

                    cdt.SaveChanges();
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #3
0
 public tipoUsuario asignarPermisos(tipoUsuario tu)
 {
     using (contextData cdt = new contextData())
     {
         cdt.Configuration.LazyLoadingEnabled = false;
         cdt.tipoUsuario.Add(tu);
         cdt.SaveChanges();
     }
     return(tu);
 }
Пример #4
0
        public usuario logIn(string email, string clave)
        {
            usuario user = null;

            using (contextData cdt = new contextData()) {
                cdt.Configuration.LazyLoadingEnabled = false;
                user = cdt.usuario.Where(u => u.email == email && u.clave == clave && u.esActivo).FirstOrDefault <usuario>();
            }
            return(user);
        }
Пример #5
0
        public int obtenerPermisos(int id)
        {
            int permiso = 0;

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;
                permiso = cdt.tipoUsuario.Where(x => x.id == id).FirstOrDefault <tipoUsuario>().id;
            }
            return(permiso);
        }
Пример #6
0
        public proveedor obtenerProveedorID(int id)
        {
            proveedor proveedor = null;

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;
                proveedor = cdt.proveedor.Include(x => x.contactos).Include(x => x.producto).Include(x => x.pais).Where(x => x.id == id).FirstOrDefault();
            }
            return(proveedor);
        }
Пример #7
0
        public contactos obtenerContactoID(int id)
        {
            contactos contactos = null;

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;
                contactos = cdt.contactos.Include(x => x.proveedor).Where(x => x.id == id).FirstOrDefault();
            }
            return(contactos);
        }
Пример #8
0
        public IEnumerable <producto> buscarProductoxNombre(string nombre)
        {
            IEnumerable <producto> lista = null;

            using (contextData ctx = new contextData())
            {
                ctx.Configuration.LazyLoadingEnabled = false;
                lista = ctx.producto.ToList().
                        FindAll(l => l.nombre.ToLower().Contains(nombre.ToLower()));
            }
            return(lista);
        }
Пример #9
0
        public producto obtenerProductoID(int id)
        {
            producto producto = null;

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;
                producto = cdt.producto.Include(x => x.TipoCategoria).Include(x => x.proveedor).Include(x => x.productoEstante).Include("productoEstante.estante")
                           .Where(x => x.id == id).FirstOrDefault();
            }
            return(producto);
        }
Пример #10
0
        public IEnumerable <proveedor> buscarProveedorxNombre(string nombre)
        {
            IEnumerable <proveedor> lista = null;

            using (contextData ctx = new contextData())
            {
                ctx.Configuration.LazyLoadingEnabled = false;
                lista = ctx.proveedor.Include(x => x.contactos).Include(x => x.pais).ToList().
                        FindAll(l => l.nombreEmpresa.ToLower().Contains(nombre.ToLower()));
            }
            return(lista);
        }
Пример #11
0
 public IEnumerable <tipoUsuario> listadoPermisos()
 {
     try {
         using (contextData cdt = new contextData())
         {
             return(cdt.tipoUsuario.ToList());
         }
     }
     catch (Exception ex)
     {
         string mensaje = "";
         Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
         throw;
     }
 }
Пример #12
0
        public IEnumerable <TipoCategoria> GetListaTipoCategoria()
        {
            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    return(cdt.TipoCategoria.ToList());
                }
                catch (Exception e)
                {
                    string mensaje = "";
                    Log.Error(e, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #13
0
        public IEnumerable <usuario> listadoUsuario()
        {
            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    return(cdt.usuario.Include(x => x.tipoUsuario).ToList());
                }
                catch (Exception e)
                {
                    string mensaje = "";
                    Log.Error(e, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #14
0
        public estante obtenerEstantePorID(int idEstante)
        {
            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    return(cdt.estante.Where(x => x.id == idEstante).FirstOrDefault());
                }
                catch (Exception e)
                {
                    string mensaje = "";
                    Log.Error(e, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #15
0
        public inventario obtenerInventarioID(int id)
        {
            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    return(cdt.inventario.Include(x => x.TipoMovimiento).Include(x => x.usuario).Include(x => x.tienda).Include("detalleFactura.Producto").Include("detalleFactura.Producto.TipoCategoria").Where(x => x.id == id).FirstOrDefault());
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #16
0
        public void asignarCategoria(TipoCategoria tc)
        {
            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    cdt.TipoCategoria.Add(tc);
                    cdt.SaveChanges();
                }
                catch (Exception e)
                {
                    string mensaje = "";
                    Log.Error(e, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #17
0
        public bool actualizarExistDB(int id, int cantUsu, bool esSalida)
        {
            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;
                try
                {
                    producto oldProd = obtenerProductoID(id);
                    oldProd.TipoCategoria   = null;
                    oldProd.productoEstante = null;
                    oldProd.proveedor       = null;

                    if (esSalida)
                    {
                        oldProd.totalStock -= cantUsu;
                        if (oldProd.totalStock < oldProd.cantMinima)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        oldProd.totalStock += cantUsu;
                        if (oldProd.totalStock > oldProd.cantMaxima)
                        {
                            return(false);
                        }
                    }

                    cdt.producto.Add(oldProd);
                    cdt.Entry(oldProd).State = EntityState.Modified;
                    cdt.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
        public int agregarTipoMovimiento(TipoMovimiento tm)
        {
            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    cdt.TipoMovimiento.Add(tm);
                    cdt.SaveChanges();
                    return(tm.id);
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #19
0
        public List <IGrouping <int, detalleFactura> > listadoProductoMayorSalidas()
        {
            List <IGrouping <int, detalleFactura> > lista = null;

            try {
                using (contextData ctx = new contextData())
                {
                    ctx.Configuration.LazyLoadingEnabled = false;

                    lista = ctx.detalleFactura.GroupBy(x => x.idProducto).OrderByDescending(x => x.Count()).Take(3).ToList();
                }
            }
            catch (Exception ex)
            {
                string mensaje = "";
                Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                throw;
            }
            return(lista);
        }
Пример #20
0
        public void SignIn(usuario usuario)
        {
            usuario user = null;

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    user = cdt.usuario.Add(usuario);
                    cdt.SaveChanges(); //solo es nesesario para insert, delete y update
                }
                catch (Exception e) {
                    string mensaje = "";
                    Log.Error(e, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #21
0
        public IEnumerable <producto> listadoProducto()
        {
            IEnumerable <producto> lista = null;

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    lista = cdt.producto.Include(x => x.TipoCategoria).Where(x => x.totalStock > 0).ToList();
                    return(lista);
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #22
0
        public IEnumerable <contactos> listadoContactos()
        {
            IEnumerable <contactos> lista = null;

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    lista = cdt.contactos.Include(x => x.idProveedor).ToList();
                    return(lista);
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #23
0
        public IEnumerable <producto> listadoProductoReponer()
        {
            IEnumerable <producto> lista = null;

            try
            {
                using (contextData cdt = new contextData())
                {
                    cdt.Configuration.LazyLoadingEnabled = false;

                    lista = cdt.producto.Include(x => x.TipoCategoria).OrderBy(x => x.cantMinima).Take(6).ToList();
                }
            }
            catch (Exception ex)
            {
                string mensaje = "";
                Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                throw;
            }
            return(lista);
        }
Пример #24
0
        public void editarUsuario(usuario usuarioEdicion)
        {
            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    usuarioEdicion.tipoUsuario = null;
                    cdt.usuario.Add(usuarioEdicion);
                    cdt.Entry(usuarioEdicion).State = EntityState.Modified;
                    cdt.SaveChanges();
                }
                catch (Exception e)
                {
                    string mensaje = "";
                    Log.Error(e, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #25
0
        public IEnumerable <inventario> listadoInventario()
        {
            IEnumerable <inventario> lista = null;

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    lista = cdt.inventario.Include(x => x.TipoMovimiento).ToList();
                    return(lista);
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #26
0
        public IEnumerable <estante> GetListaEstante()
        {
            IEnumerable <estante> lista = null;

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    lista = cdt.estante.ToList();
                    return(lista);
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #27
0
        public void GuardarContactos(contactos contactos)
        {
            proveedor proveedor       = repositoryProveedor.obtenerProveedorID(contactos.idProveedor);
            contactos contractoExiste = obtenerContactoID(contactos.id);

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    if (contractoExiste == null)
                    {
                        //Guarda el contacto
                        cdt.contactos.Add(contactos);
                        cdt.SaveChanges();
                    }
                    else
                    {
                        //modifica el contacto modificado
                        if (contractoExiste.nombre != contactos.nombre || contractoExiste.idProveedor != contactos.idProveedor || contractoExiste.numero != contactos.numero)
                        {
                            cdt.contactos.Add(contactos);
                            cdt.Entry(contactos).State = EntityState.Modified;
                            cdt.SaveChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    string mensaje = "";
                    Log.Error(ex, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }
Пример #28
0
 return(new PlaylistTrackIdsWithPositionsBuilder(contextData, routeValuesPrefix, EndpointName, idsWithPositions));
Пример #29
0
        public void guardarProducto(producto producto, String[] idProveedor, String[] idEstante)
        {
            proveedor pro;
            producto  produExist = obtenerProductoID(producto.id);

            using (contextData cdt = new contextData())
            {
                cdt.Configuration.LazyLoadingEnabled = false;

                try
                {
                    if (produExist == null)
                    {
                        //si producto no existe, es nuevo
                        //carga los proveedores a la tabla intermedia
                        foreach (var idPro in idProveedor)
                        {
                            pro = repoPro.obtenerProveedorID(int.Parse(idPro));
                            cdt.proveedor.Attach(pro);
                            producto.proveedor.Add(pro);
                        }

                        //salva el producto
                        cdt.producto.Add(producto);

                        //carga la tabla intermedia de ubicacion
                        foreach (var idEsta in idEstante)
                        {
                            productoEstante pe = new productoEstante();
                            pe.idProducto = producto.id;
                            pe.idEstante  = int.Parse(idEsta);
                            pe.cantidad   = producto.totalStock;
                            producto.productoEstante.Add(pe);
                        }


                        cdt.SaveChanges();
                    }
                    else
                    {
                        //actualiza el producto
                        cdt.producto.Add(producto);
                        cdt.Entry(producto).State = EntityState.Modified;


                        //actualiza los proveedores a la tabla intermedia
                        var proveedoresLista = new HashSet <string>(idProveedor);
                        cdt.Entry(producto).Collection(p => p.proveedor).Load();
                        var nuevoProveedorLista = cdt.proveedor.Where(x => proveedoresLista.Contains(x.id.ToString())).Include(x => x.pais).Include(x => x.contactos).Include(x => x.detalleFactura).ToList();
                        producto.proveedor        = nuevoProveedorLista;
                        cdt.Entry(producto).State = EntityState.Modified;


                        //actualizar tabla intermedia de ubicacion usando muchos a muchos
                        //idEstante arreglo de los identificadores de las ubicaciones o estantes
                        if (idEstante != null)
                        {
                            //Obtener los estantes registrados del producto a modificar
                            List <productoEstante> estantesdelProducto = cdt.productoEstante.Where(x => x.idProducto == producto.id).ToList();
                            // Borrar los estantes existentes del producto
                            foreach (var item in estantesdelProducto)
                            {
                                producto.productoEstante.Remove(item);
                            }
                            //Registrar los estantes especificados
                            foreach (var estante in idEstante)
                            {
                                productoEstante pe = new productoEstante();
                                pe.idProducto = producto.id;
                                pe.idEstante  = int.Parse(estante);
                                pe.cantidad   = 0;
                                cdt.productoEstante.Add(pe);
                            }
                        }
                        cdt.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    string mensaje = "";
                    Log.Error(e, System.Reflection.MethodBase.GetCurrentMethod(), ref mensaje);
                    throw;
                }
            }
        }