Beispiel #1
0
        //CREATE
        public static bool createCompra(Compra compra)
        {
            try
            {
                using (var db = new MercatorEntities())
                {
                    db.Compras.Add(compra);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors)
                {
                    foreach (DbValidationError error in entityErr.ValidationErrors)
                    {
                        Console.WriteLine("Error Property Name {0} : Error Message: {1}",
                                          error.PropertyName, error.ErrorMessage);
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        //DELETE

        public static bool deleteProducto(int id)
        {
            try
            {
                using (var db = new MercatorEntities())
                {
                    // Realizamos la consulta
                    var query = db.Productoes.Where(p => p.IdProducto ==
                                                    id).First();

                    // Eliminamos el cliente
                    db.Productoes.Remove(query);    // Para el Framework 4.0 o inferior

                    // Guardamos los cambios
                    int res = db.SaveChanges();

                    return(res > 0);
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors)
                {
                    foreach (DbValidationError error in entityErr.ValidationErrors)
                    {
                        Console.WriteLine("Error Property Name {0} : Error Message: {1}",
                                          error.PropertyName, error.ErrorMessage);
                    }
                }
            }
            return(false);
        }
Beispiel #3
0
        //UPDATE

        public static bool updateProducto(Producto producto)
        {
            try
            {
                using (var db = new MercatorEntities())
                {
                    db.Entry(producto).State = System.Data.Entity.EntityState.Modified;
                    int changes = db.SaveChanges();

                    if (changes > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors)
                {
                    foreach (DbValidationError error in entityErr.ValidationErrors)
                    {
                        Console.WriteLine("Error Property Name {0} : Error Message: {1}",
                                          error.PropertyName, error.ErrorMessage);
                    }
                }
            }
            return(false);
        }
Beispiel #4
0
        //DELETE

        public static bool deleteProveedor(int idproveedor)
        {
            try
            {
                using (var db = new MercatorEntities())
                {
                    var query = (from p in db.Proveedors
                                 where p.IdProveedor == idproveedor
                                 select p).Single();

                    db.Proveedors.Remove(query);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors)
                {
                    foreach (DbValidationError error in entityErr.ValidationErrors)
                    {
                        Console.WriteLine("Error Property Name {0} : Error Message: {1}",
                                          error.PropertyName, error.ErrorMessage);
                    }
                }
            }
            return(false);
        }