public static bool Post(Producto producto)
 {
     using (var model = new AlmacenDBContext())
     {
         model.Productos.Add(producto);
         model.SaveChanges();
     }
     return(Convert.ToBoolean(producto.ProductoId));
 }
Exemple #2
0
 public static bool Post(Categoria categoria)
 {
     using (var model = new AlmacenDBContext())
     {
         model.Categorias.Add(categoria);
         model.SaveChanges();
     }
     return(Convert.ToBoolean(categoria.CategoriaId));
 }
 public static bool Post(Imagen imagen)
 {
     using (var model = new AlmacenDBContext())
     {
         model.Imagenes.Add(imagen);
         model.SaveChanges();
     }
     return(Convert.ToBoolean(imagen.ImagenId));
 }
 public static bool Post(Bodega bodega)
 {
     using (var model = new AlmacenDBContext())
     {
         model.Bodegas.Add(bodega);
         model.SaveChanges();
     }
     return(Convert.ToBoolean(bodega.BodegaId));
 }
        public static IEnumerable <Imagen> GetImagenes()
        {
            IEnumerable <Imagen> imagenes;

            using (var model = new AlmacenDBContext())
            {
                imagenes = model.Imagenes
                           .OrderBy(i => i.ImagenId)
                           .ToArray();
            }
            return(imagenes);
        }
        public static Imagen GetImagen(int id)
        {
            Imagen imagen = new Imagen();

            using (var model = new AlmacenDBContext())
            {
                imagen = model.Imagenes
                         .Where(i => i.ImagenId == id)
                         .FirstOrDefault();
            }
            return(imagen);
        }
        public static Bodega GetBodega(int id)
        {
            Bodega bodega = new Bodega();

            using (var model = new AlmacenDBContext())
            {
                bodega = model.Bodegas.Include(b => b.Imagen)
                         .Include(b => b.Productos)
                         .Where(b => b.BodegaId == id)
                         .FirstOrDefault();
            }
            return(bodega);
        }
        public static IEnumerable <Bodega> GetBodegas()
        {
            IEnumerable <Bodega> bodegas;

            using (var model = new AlmacenDBContext())
            {
                bodegas = model.Bodegas.OrderBy(b => b.BodegaId)
                          .Include(b => b.Imagen)
                          .Include(b => b.Productos)
                          .ToArray();
            }
            return(bodegas);
        }
Exemple #9
0
        public static Categoria GetCategoria(int id)
        {
            Categoria categoria = new Categoria();

            using (var model = new AlmacenDBContext())
            {
                categoria = model.Categorias
                            .Include(c => c.Nombre)
                            .Include(c => c.CategoriaProductos)
                            .Where(c => c.CategoriaId == id)
                            .FirstOrDefault();
            }
            return(categoria);
        }
Exemple #10
0
        public static IEnumerable <Categoria> GetCategorias()
        {
            IEnumerable <Categoria> categorias;

            using (var model = new AlmacenDBContext())
            {
                categorias = model.Categorias
                             .OrderBy(c => c.CategoriaId)
                             .Include(c => c.Nombre)
                             .Include(c => c.CategoriaProductos)
                             .ToArray();
            }
            return(categorias);
        }
        public static IEnumerable <Producto> GetProductos()
        {
            IEnumerable <Producto> productos;

            using (var model = new AlmacenDBContext())
            {
                productos = model.Productos.OrderBy(p => p.ProductoId)
                            .Include(p => p.Bodega)
                            .Include(p => p.Imagen)
                            .Include(p => p.CategoriasProducto)
                            .ToArray();
            }
            return(productos);
        }
Exemple #12
0
        public static bool Put(Imagen imagen)
        {
            int returnValue;

            using (var model = new AlmacenDBContext())
            {
                model.Attach(imagen);
                model.Entry(imagen).Property("Tipo").IsModified = (imagen.Tipo != 0);
                model.SaveChanges();
                model.Imagenes.Add(imagen);
                returnValue = model.SaveChanges();
            }
            return(Convert.ToBoolean(returnValue));
        }
Exemple #13
0
        public static bool Delete(int id)
        {
            int    returnValue;
            Imagen imagen = new Imagen()
            {
                ImagenId = id
            };

            using (var model = new AlmacenDBContext())
            {
                model.Remove(imagen);
                returnValue = model.SaveChanges();
            }
            return(Convert.ToBoolean(returnValue));
        }
Exemple #14
0
        public static bool Delete(int id)
        {
            int    returnValue;
            Bodega bodega = new Bodega()
            {
                BodegaId = id
            };

            using (var model = new AlmacenDBContext())
            {
                model.Remove(bodega);
                returnValue = model.SaveChanges();
            }
            return(Convert.ToBoolean(returnValue));
        }
Exemple #15
0
        public static bool Delete(int id)
        {
            int       returnValue;
            Categoria categoria = new Categoria()
            {
                CategoriaId = id
            };

            using (var model = new AlmacenDBContext())
            {
                model.Remove(categoria);
                returnValue = model.SaveChanges();
            }
            return(Convert.ToBoolean(returnValue));
        }
Exemple #16
0
        public static bool Put(Categoria categoria)
        {
            int returnValue;

            using (var model = new AlmacenDBContext())
            {
                model.Attach(categoria);
                model.Entry(categoria).Property("Nombre").IsModified             = !(String.IsNullOrEmpty(categoria.Nombre));
                model.Entry(categoria).Property("CategoriaProductos").IsModified = (categoria.CategoriaProductos != null);
                model.SaveChanges();
                model.Categorias.Add(categoria);
                returnValue = model.SaveChanges();
            }
            return(Convert.ToBoolean(returnValue));
        }
        public static bool Delete(int id)
        {
            int      returnValue;
            Producto producto = new Producto()
            {
                ProductoId = id
            };

            using (var model = new AlmacenDBContext())
            {
                model.Remove(producto);
                returnValue = model.SaveChanges();
            }
            return(Convert.ToBoolean(returnValue));
        }
        public static Producto GetProducto(int id)
        {
            Producto producto = new Producto();

            using (var model = new AlmacenDBContext())
            {
                producto = model.Productos
                           .Include(p => p.Bodega)
                           .Include(p => p.Imagen)
                           .Include(p => p.CategoriasProducto)
                           .Where(p => p.ProductoId == id)
                           .FirstOrDefault();
            }
            return(producto);
        }
Exemple #19
0
        public static bool Put(Bodega bodega)
        {
            int returnValue;

            using (var model = new AlmacenDBContext())
            {
                model.Attach(bodega);
                model.Entry(bodega).Property("Nombre").IsModified    = !(String.IsNullOrEmpty(bodega.Nombre));
                model.Entry(bodega).Property("Imagen").IsModified    = (bodega.Imagen != null);
                model.Entry(bodega).Property("Productos").IsModified = (bodega.Productos != null);
                model.SaveChanges();
                model.Bodegas.Add(bodega);
                returnValue = model.SaveChanges();
            }
            return(Convert.ToBoolean(returnValue));
        }
        public static bool Put(Producto producto)
        {
            int returnValue;

            using (var model = new AlmacenDBContext())
            {
                model.Attach(producto);
                model.Entry(producto).Property("Nombre").IsModified             = !(String.IsNullOrEmpty(producto.Nombre));
                model.Entry(producto).Property("Descripcion").IsModified        = !(String.IsNullOrEmpty(producto.Descripcion));
                model.Entry(producto).Property("Precio").IsModified             = (producto.Precio != null);
                model.Entry(producto).Property("Imagen").IsModified             = (producto.Imagen != null);
                model.Entry(producto).Property("Bodega").IsModified             = (producto.Bodega != null);
                model.Entry(producto).Property("CategoriasProducto").IsModified = (producto.CategoriasProducto != null);
                model.SaveChanges();
                model.Productos.Add(producto);
                returnValue = model.SaveChanges();
            }
            return(Convert.ToBoolean(returnValue));
        }