Beispiel #1
0
        public ProduitCommandeDto UpdateProduitCommande(ProduitCommandeDto produitCommandeDto)
        {
            var produitCommande = Context.ProduitCommande.Where(pc => pc.Produit.Id == produitCommandeDto.Produit.Id && pc.Commande.Id == produitCommandeDto.Commande.Id).FirstOrDefault();

            produitCommande.Quantite = produitCommandeDto.Quantite;
            produitCommande.Produit  = Context.Produit.Where(p => p.Id == produitCommandeDto.Produit.Id).FirstOrDefault();
            produitCommande.Commande = Context.Commande.Where(p => p.Id == produitCommandeDto.Commande.Id).FirstOrDefault();

            Context.SaveChanges();

            return(produitCommandeDto);
        }
Beispiel #2
0
        public void CreateNewProduitCommands(ProduitCommandeDto produitCommandeDto)
        {
            ProduitCommande prodCommande = new ProduitCommande()
            {
                Quantite = produitCommandeDto.Quantite,
                Produit  = Context.Produit.Where(p => p.Id == produitCommandeDto.Produit.Id).FirstOrDefault(),
                Commande = Context.Commande.Where(c => c.Id == produitCommandeDto.Commande.Id).FirstOrDefault(),
            };

            Context.ProduitCommande.Add(prodCommande);
            Context.SaveChanges();
        }
Beispiel #3
0
        public void DeleteProduitCommande(ProduitCommandeDto produitCommandeDto)
        {
            var produitCommande = Context.ProduitCommande.Where(pc => pc.Produit.Id == produitCommandeDto.Produit.Id && pc.Commande.Id == produitCommandeDto.Commande.Id).FirstOrDefault();

            if (produitCommande == null)
            {
                return;
            }

            Context.ProduitCommande.Remove(produitCommande);

            Context.SaveChanges();
        }
Beispiel #4
0
        private void ButtonAddProduct_Click(object sender, EventArgs e)
        {
            ProduitDto produit = _produitsService.GetProduits().Where(c => c.Id == Convert.ToInt32(comboBoxProduits.SelectedValue)).FirstOrDefault();

            if (produit != null)
            {
                if (numericUpDownQty.Value >= 1)
                {
                    if (produit.Quantite >= numericUpDownQty.Value)
                    {
                        int    qty    = Decimal.ToInt32(numericUpDownQty.Value);
                        double prixHT = (double)produit.PrixHT;
                        double taxe   = (double)produit.Taxe;
                        totalPriceHT          += Math.Round(qty * prixHT, 2);
                        totalPriceTT          += Math.Round(qty * prixHT * (1 + taxe), 2);
                        labelTotalPrices.Text  = "Prix Total HT : " + totalPriceHT + "€\n";
                        labelTotalPrices.Text += "Prix Total TT : " + totalPriceTT + "€\n";
                        CommandeDto        commande        = _commandesService.GetCommandes().Where(c => c.Id == selectedCommandId).FirstOrDefault();
                        ProduitCommandeDto produitCommande = new ProduitCommandeDto()
                        {
                            Quantite = qty,
                            Produit  = produit,
                            Commande = commande
                        };
                        produitsDansCommande.Add(produitCommande);
                        labelProductInCommand.Text += qty + " " + produit.Libelle + " " + produit.PrixHT * qty + "€\n";
                        numericUpDownQty.Value      = 1;
                        List <ProduitDto> produitRestant = new List <ProduitDto>();
                        var produits = _produitsService.GetProduits().ToList();
                        foreach (ProduitDto prod in produits)
                        {
                            bool isInList = produitsDansCommande.Exists(pc => pc.Produit.Id == prod.Id);
                            if (!isInList)
                            {
                                produitRestant.Add(prod);
                            }
                        }
                        comboBoxProduits.DataSource = produitRestant;
                    }
                    else
                    {
                        MessageBox.Show("La quantité en stock est insuffisante.\nIl reste " + produit.Quantite + " " + produit.Libelle, "ERROR");
                    }
                }
            }
        }