Beispiel #1
0
        public void AjouterArticle(string reference, string designation, decimal prixVente, decimal qteStock, bool sommeil)
        {
            if (reference == null)
            {
                throw new Exception("Reference nulle impossible.");
            }
            if (designation == null || designation.Length < 1)
            {
                throw new Exception("Designation vide impossible.");
            }
            if (prixVente < 0)
            {
                throw new Exception("Prix de vente inférieur à 0 impossible.");
            }
            if (qteStock < 0)
            {
                throw new Exception("Quantité stock inférieur à 0 impossible.");
            }

            using (var context = new DBProdEntities())
            {
                context.DatabaseArticles.Add(new DatabaseArticle()
                {
                    Reference   = reference,
                    Designation = designation,
                    PrixVente   = prixVente,
                    QteStock    = qteStock,
                    Sommeil     = sommeil,
                });

                context.SaveChanges();
            }
        }
Beispiel #2
0
        public void ModifierParRef(string reference, string designation = null, decimal?prixVente = null, decimal?qteStock = null)
        {
            if (prixVente < 0)
            {
                throw new Exception("Prix de vente inférieur à 0 impossible.");
            }
            if (qteStock < 0)
            {
                throw new Exception("Quantité stock inférieur à 0 impossible.");
            }

            using (var context = new DBProdEntities())
            {
                var temp   = context.DatabaseArticles.Where(r => r.Reference == reference);
                var result = temp.FirstOrDefault();
                if (result != null)
                {
                    result.Designation = designation ?? result.Designation;
                    result.PrixVente   = prixVente ?? result.PrixVente;
                    result.QteStock    = qteStock ?? result.QteStock;
                }
                context.SaveChanges();
            }
        }