private void Products_CurrentItemChanged(ProductExtended oldProduct, ProductExtended newProduct)
 {
     if (newProduct != null)
     {
         newProduct.PropertyChanged += Product_PropertyChanged;
     }
     if (oldProduct != null)
     {
         oldProduct.PropertyChanged -= Product_PropertyChanged;
     }
 }
Exemple #2
0
        private void btnRemoveProduct_Click(object sender, EventArgs e)
        {
            //nothing selected, return.
            if (dtgProducts.SelectedRows.Count == 0)
            {
                return;
            }

            ProductExtended product = (ProductExtended)dtgProducts.CurrentRow.DataBoundItem;

            RemoveProductInPackage(PackageSelected.PackageId, product.ProductSupplierId);
        }
        private void ValidateUniqueName(ProductExtended product)
        {
            string errorMessage = "The product name must be unique.";

            if (!IsProductNameUnique(product))
            {
                product.ExternalErrors.Add(errorMessage);
            }
            else
            {
                product.ExternalErrors.Remove(errorMessage);
            }
        }
Exemple #4
0
 public ProductReposotory()
 {
     if (_products == null)
     {
         _products = new List <ProductExtended> {
             ProductExtended.Generate(1, "Product 1", 10.50m, "Product 1 description"),
             ProductExtended.Generate(2, "Product 2", 10.50m, "Product 2 description"),
             ProductExtended.Generate(3, "Product 3", 10.50m, "Product 3 description"),
             ProductExtended.Generate(4, "Product 4", 10.50m, "Product 4 description")
         }
     }
     ;
 }
Exemple #5
0
 public DmResult Post([FromBody] ProductExtended cp)
 {
     using (var db = GetDatabase())
     {
         db.Products.Add(cp.Product);
         cp.Categories.ForEach(c => db.ProductCategories.Add(new ProductCategory {
             ProductId = cp.Product.Id, CategoryId = c.Id
         }));
         db.SaveChanges();
         return(new DmResult
         {
             Success = true,
             Id = cp.Product.Id
         });
     }
 }
        public List <LineExtended> GetAllLines(long billQuotation_id)
        {
            var listLineExtended = lineBLL.GetLineBillQuotation(billQuotation_id).Select(l => new LineExtended(l, true)).ToList();

            var listProductNotIncluded = productBLL.getListProductIncludedOrNot(billQuotation_id).Where(p => !p.included);

            foreach (var p in listProductNotIncluded)
            {
                var product = new ProductExtended(p, billQuotation_id);
                var line    = new BILL_LineBillQuotation
                {
                    BILL_Product     = productBLL.GetProductByID(product.Product_Id),
                    Quantite         = 0,
                    BillQuotation_Id = billQuotation_id
                };
                listLineExtended.Add(new LineExtended(line, false));
            }

            return(listLineExtended);
        }
        /// <summary>
        /// removes the selected datagrid product from the database
        /// </summary>
        private void RemoveProduct()
        {
            //nothing selected, return.
            if (dtgProducts.SelectedRows.Count == 0)
            {
                return;
            }

            ProductExtended product = (ProductExtended)dtgProducts.CurrentRow.DataBoundItem;

            try
            {
                ProductExtendedDB.DeletePackageProductsById(PackageSelected.PackageId, product.ProductSupplierId);
                GetBindedPackageProducts(PackageSelected.PackageId);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Unable to delete product", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #8
0
        public DmResult Put(int id, [FromBody] ProductExtended cp)
        {
            using (var db = GetDatabase())
            {
                var categories = db.ProductCategories.Where(pc => pc.ProductId == id).ToList();
                db.ProductCategories.RemoveRange(categories);
                db.SaveChanges();

                cp.Product.Id = id;
                db.Products.Update(cp.Product);
                cp.Categories.ForEach(c => db.ProductCategories.Add(new ProductCategory {
                    ProductId = cp.Product.Id, CategoryId = c.Id
                }));
                db.SaveChanges();
                return(new DmResult
                {
                    Success = true,
                    Id = cp.Product.Id
                });
            }
        }
 private bool IsProductNameUnique(ProductExtended product) =>
 !Products.Any(p => p.Id != product.Id &&
               !string.IsNullOrEmpty(p.Name) && p.Name == product.Name);
 private bool IsProductNameUnique(ProductExtended product) => Products.Count(p => p.Id != product.Id && p.Name != string.Empty && p.Name == product.Name) == 0;