コード例 #1
0
        /// <summary>
        /// Crée et ajoute un nouveau produit à la DB
        /// </summary>
        /// <param name="code">Identifiant</param>
        /// <param name="label"> Nom du produit</param>
        /// <param name="catPrice"> <c>CategoryPrice</c> à associer au produit</param>
        /// <param name="quantityStock"> Stock initial </param>
        /// <param name="picturePath"> Représentation picturale du futur produit </param>
        public static void AddProduct(string code, string label, CategoryPrice catPrice, int quantityStock = 0, string picturePath = "")
        {
            Product product = new()
            {
                QuantityStock   = quantityStock,
                Code            = code,
                Label           = label,
                CategoryPriceId = catPrice.CategoryPriceId,
                Picture         = picturePath
            };


            using (MyPopupStoreDBContext db = new())
            {
                try
                {
                    db.Add(product);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new Exception("Produit invalide", e);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Recherche d'un prix dans la DB
 /// </summary>
 /// <param name="ID">Identifiant du prix</param>
 public static CategoryPrice GetPrice(int ID)
 {
     using (MyPopupStoreDBContext db = new())
     {
         CategoryPrice category = db.CategoryPrices.Find(ID);
         if (category == null)
         {
             throw new Exception("Catégorie de prix inexistant");
         }
         return(category);
     }
 }
コード例 #3
0
 public void DeleteCategoryPrice(CategoryPrice categoryPrice)
 {
     try
     {
         CategoryPriceServices.Delete(categoryPrice);
         LoadCategories();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
コード例 #4
0
        /// <summary>
        /// Supprime une catégorie de prix dans la DB
        /// </summary>
        /// <param name="categoryPrice">prix à supprimer</param>
        public static void Delete(CategoryPrice categoryPrice)
        {
            if (CategoryPriceServices.CategoryPriceIsUsed(categoryPrice.CategoryPriceId))
            {
                throw new Exception("Impossible de supprimer un prix appliqué à au moins un produit.");
            }

            using (DB.MyPopupStoreDBContext db = new())
            {
                db.Remove(categoryPrice);
                db.SaveChanges();
            }
        }
コード例 #5
0
 public CategoryPriceManagerViewModel()
 {
     categoryPriceOfProduct = new();
     ListCategories         = new();
     LoadCategories();
 }
コード例 #6
0
 private void SelectPrice_Click(object sender, RoutedEventArgs e)
 {
     ChoiceCat         = (CategoryPrice)((CategoryPriceControl)sender).DataContext;
     this.DialogResult = true;
 }