private void Button1_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(textBox1.Text) && !String.IsNullOrEmpty(textBox2.Text) && !String.IsNullOrEmpty(textBox3.Text) && !String.IsNullOrEmpty(textBox4.Text))
            {
                var          categories = _categorieService.GetCategories();
                CategorieDto cat        = categories.Where(c => c.Id == Convert.ToInt32(comboBoxCategories.SelectedValue)).FirstOrDefault();
                ProduitDto   prod       = new ProduitDto()
                {
                    Libelle   = textBox1.Text,
                    PrixHT    = Convert.ToDouble(textBox2.Text),
                    Quantite  = Convert.ToInt32(textBox3.Text),
                    Taxe      = Convert.ToDouble(textBox4.Text),
                    Categorie = cat
                };

                _produitsService.CreateNewProduit(prod);

                this.UpdateDataGrid();

                textBox1.ResetText();
                textBox2.ResetText();
                textBox3.ResetText();
                textBox4.ResetText();
            }
        }
 public IActionResult Put([FromRoute] long id, [FromBody] ProduitDto produit)
 {
     if (produit != null)
     {
         try
         {
             if (id != produit.Id)
             {
                 return(BadRequest());
             }
             else
             {
                 _produitDao.UpdateProduit(produit, id);
             }
         }
         catch (DbUpdateConcurrencyException)
         {
             if (produit == null)
             {
                 return(NotFound());
             }
             else
             {
                 return(StatusCode(StatusCodes.Status500InternalServerError));
             }
         }
     }
     return(NoContent());
 }
 private void GridProducts_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 6)
     {
         int                 id               = Convert.ToInt32(gridProducts.Rows[e.RowIndex].Cells[0].Value);
         ProduitDto          produit          = _produitsService.GetProduits().Where(p => p.Id == id).FirstOrDefault();
         List <MouvementDto> mouvements       = _mouvementsService.GetMouvements().Where(m => m.Produit.Id == id).ToList();
         string              mouvementsToShow = "ID       Quantité                    Date\n";
         if (mouvements.Count > 0)
         {
             foreach (MouvementDto mvt in mouvements)
             {
                 string qte;
                 if (mvt.Quantite.ToString().Length == 1)
                 {
                     qte = "0" + mvt.Quantite.ToString();
                 }
                 else
                 {
                     qte = mvt.Quantite.ToString();
                 }
                 mouvementsToShow += mvt.Id + "        " + qte + "                    " + mvt.DateCreation + "\n";
             }
             MessageBox.Show(mouvementsToShow, "Mouvements de " + produit.Libelle);
         }
         else
         {
             MessageBox.Show("Il n'y a pas de mouvements");
         }
     }
 }
        private void GridProducts_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            ProduitDto prod = new ProduitDto();
            int        id   = Convert.ToInt32(gridProducts.Rows[e.RowIndex].Cells[0].Value);

            prod         = _produitsService.GetProduits().Where(p => p.Id == id).FirstOrDefault();
            prod.Libelle = gridProducts.Rows[e.RowIndex].Cells[1].Value.ToString();
            prod.PrixHT  = Convert.ToDouble(gridProducts.Rows[e.RowIndex].Cells[2].Value);
            prod.Taxe    = Convert.ToDouble(gridProducts.Rows[e.RowIndex].Cells[3].Value);
            prod         = this._produitsService.UpdateProduit(prod);
        }
 public IActionResult Post([FromBody] ProduitDto produit)
 {
     if (_produitDao.CreateProduit(produit))
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Beispiel #6
0
 public bool UpdateProduit(ProduitDto Dto, long id)
 {
     try
     {
         return(_repository.Update(Dto, id));
     }
     catch (ApiException e)
     {
         this._logger.LogError(e.Message);
         return(false);
     }
 }
Beispiel #7
0
 public bool CreateProduit(ProduitDto Dto)
 {
     try
     {
         return(_repository.Create(Dto));
     }
     catch (ApiException e)
     {
         this._logger.LogError(e.Message);
         return(false);
     }
 }
        public void CreateNewProduit(ProduitDto produit)
        {
            Produit prod = new Produit();

            prod.Libelle   = produit.Libelle;
            prod.PrixHT    = produit.PrixHT;
            prod.Quantite  = (int)produit.Quantite;
            prod.Taxe      = produit.Taxe;
            prod.Categorie = Context.Categorie.Where(x => x.Id == produit.Categorie.Id).FirstOrDefault();
            Context.Produit.Add(prod);
            Context.SaveChanges();
        }
        public ProduitDto UpdateProduit(ProduitDto produitDto)
        {
            var produit = Context.Produit.Where(p => p.Id == produitDto.Id).FirstOrDefault();;

            produit.Libelle           = produitDto.Libelle;
            produit.PrixHT            = produitDto.PrixHT;
            produit.Taxe              = produitDto.Taxe;
            produit.Categorie.Libelle = produitDto.Categorie.Libelle;

            Context.SaveChanges();

            return(produitDto);
        }
Beispiel #10
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");
                    }
                }
            }
        }
Beispiel #11
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(stokTextBox.Text))
            {
                ProduitDto   prod = _produitsService.GetProduits().Where(p => p.Id == Convert.ToInt32(comboBoxProducts.SelectedValue)).FirstOrDefault();
                MouvementDto mouv = new MouvementDto();
                mouv.Produit      = prod;
                mouv.Quantite     = Convert.ToInt32(stokTextBox.Text);
                mouv.DateCreation = DateTime.Now;

                _mouvementsService.CreateNewMouvement(mouv);

                this.UpdateDataGrid();

                stokTextBox.ResetText();
            }
        }