示例#1
0
 //récupération d'une commande par ID avec les produits commandés
 public Commande GetCommandeByID(int ID)
 {
     using (var context = new BBFRContext())
     {
         return(context.Commandes.Where(x => x.ID == ID).Include(x => x.ProduitsCommandes).Include("ProduitsCommandes.Produit").FirstOrDefault());
     }
 }
示例#2
0
 //Permet de récupérer le dernier produit enregistré (Pour le widget de Nouveaux produits sur le Home)
 public List <Produit> GetDernierProduit(int nombreProduits)
 {
     using (var context = new BBFRContext())
     {
         return(context.Produits.OrderByDescending(x => x.ProduitID).Take(nombreProduits).Include(x => x.Type_Produit).ToList());
     }
 }
示例#3
0
 //Permet de récupérer  UNE catégorie par son ID
 public Type_Produit GetType_Produit(int ID)
 {
     using (var context = new BBFRContext())
     {
         return(context.Type_Produits.Find(ID));
     }
 }
示例#4
0
 //Methode permettant de récupérer une Liste de toutes les catégories (Pour la création d'un produit)
 public List <Type_Produit> GetType_Produits()
 {
     using (var context = new BBFRContext())
     {
         return(context.Type_Produits.ToList());
     }
 }
示例#5
0
 //Methode récupérant PLUSIEURS produits, grace a une liste, mais depuis une liste d'IDs (par exemple utiliser les IDs présent dans une catégorie)
 public List <Produit> GetProduits(List <int> IDs)
 {
     using (var context = new BBFRContext())
     {
         return(context.Produits.Where(produit => IDs.Contains(produit.ProduitID)).ToList());
     }
 }
示例#6
0
 //Methode pour récupérer des produits grace a l'ID d'une catégorie
 public List <Produit> GetProduitParCategorie(int type_produitID)
 {
     using (var context = new BBFRContext())
     {
         return(context.Produits.Where(x => x.Type_Produit.Type_ProduitID == type_produitID).OrderByDescending(x => x.Type_ProduitID).Include(x => x.Type_Produit).ToList());
     }
 }
示例#7
0
 //Methode récupérant PLUSIEURS produits, grace a une liste
 public List <Produit> GetProduits()
 {
     using (var context = new BBFRContext())
     {
         return(context.Produits.Include(x => x.Type_Produit).ToList());
     }
 }
示例#8
0
 //Permet de mettre a jour une catégorie dans la BDD
 public void UpdateType_Produit(Type_Produit type_produit)
 {
     using (var context = new BBFRContext())
     {
         context.Entry(type_produit).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#9
0
 //Permet de sauvegarder une catégorie dans la BDD
 public void SaveType_Produit(Type_Produit type_produit)
 {
     using (var context = new BBFRContext())
     {
         context.Type_Produits.Add(type_produit);
         context.SaveChanges();
     }
 }
示例#10
0
 //Methode de sauvegarde commande
 public int SaveCommande(Commande commande)
 {
     using (var context = new BBFRContext())
     {
         context.Commandes.Add(commande);
         return(context.SaveChanges());
     }
 }
示例#11
0
 //Permet de supprimer une catégorie de la BDD
 public void DeleteType_Produit(int ID)
 {
     using (var context = new BBFRContext())
     {
         var type_produit = context.Type_Produits.Find(ID);
         context.Type_Produits.Remove(type_produit);
         context.SaveChanges();
     }
 }
示例#12
0
        //Methode pour sauvegarder un produit
        public void SaveProduit(Produit produit)
        {
            using (var context = new BBFRContext())
            {
                context.Entry(produit.Type_Produit).State = EntityState.Unchanged;

                context.Produits.Add(produit);
                context.SaveChanges();
            }
        }
示例#13
0
        //methode pour mettre a jour le statut de commande depuis le bouton de validation des commande/Détails
        public bool UpdateCommandeStatut(int ID, string statut)
        {
            using (var context = new BBFRContext())
            {
                var commande = context.Commandes.Find(ID);

                commande.Statut = statut;

                context.Entry(commande).State = EntityState.Modified;

                return(context.SaveChanges() > 0);
            }
        }
示例#14
0
 //Non utilisé
 public int GetType_ProduitCount(string search)
 {
     using (var context = new BBFRContext())
     {
         if (!string.IsNullOrEmpty(search))
         {
             return(context.Type_Produits.Where(type_produit => type_produit.Type != null &&
                                                type_produit.Type.ToLower().Contains(search.ToLower())).Count());
         }
         else
         {
             return(context.Type_Produits.Count());
         }
     }
 }
示例#15
0
        //Service de recherche de commandes pour l'affichage, avec l'ID de l'user et le statut en paramétre
        public List <Commande> SearchCommandes(string userID, string statut)
        {
            using (var context = new BBFRContext())
            {
                var commandes = context.Commandes.ToList();

                //recherche de l'ID en mettant les paramétres et la recherche en minuscule
                if (!string.IsNullOrEmpty(userID))
                {
                    commandes = commandes.Where(x => x.UserID.ToLower().Contains(userID.ToLower())).ToList();
                }
                //recherche du statut en mettant les paramétres et la recherche en minuscule
                if (!string.IsNullOrEmpty(statut))
                {
                    commandes = commandes.Where(x => x.Statut.ToLower().Contains(statut.ToLower())).ToList();
                }
                return(commandes.ToList());
            }
        }
示例#16
0
 //Methode pour récupérer une liste de produits depuis une recherche en String
 public List <Produit> GetProduits(string search)
 {
     using (var context = new BBFRContext())
     {
         if (!string.IsNullOrEmpty(search))
         {
             return(context.Produits.Where(produit => produit.Nom != null &&
                                           produit.Nom.ToLower().Contains(search.ToLower()))
                    .OrderBy(x => x.ProduitID)
                    .Include(x => x.Type_Produit)
                    .ToList());
         }
         else
         {
             return(context.Produits
                    .OrderBy(x => x.ProduitID)
                    .Include(x => x.Type_Produit)
                    .ToList());
         }
     }
 }
示例#17
0
        //Methode pour récupérer PLUSIEURS produit dans une liste, grace a une recherche de type string (Non utilisé)
        public List <Produit> SearchProduits(string search, int?type_produitID, int?sortBy)
        {
            using (var context = new BBFRContext())
            {
                var produits = context.Produits.ToList();

                if (type_produitID.HasValue)
                {
                    produits = produits.Where(x => x.Type_Produit.Type_ProduitID == type_produitID.Value).ToList();
                }

                if (!string.IsNullOrEmpty(search))
                {
                    produits = produits.Where(x => x.Nom.ToLower().Contains(search.ToLower())).ToList();
                }
                if (sortBy.HasValue)
                {
                    switch (sortBy.Value)
                    {
                    case 2:
                        produits = produits.OrderByDescending(x => x.ProduitID).ToList();
                        break;

                    case 3:
                        produits = produits.OrderBy(x => x.Prix).ToList();
                        break;

                    default:
                        produits = produits.OrderByDescending(x => x.Prix).ToList();
                        break;
                    }
                }

                return(produits.ToList());
            }
        }