Ejemplo n.º 1
0
        public static int AddUpdateProduct(product ob)
        {
            int _Productid = 0;
            using (InventoryEntities db = new InventoryEntities())
            {
                if (ob.id > 0)
                {
                    product temp = db.products.Where(u => u.id == ob.id).FirstOrDefault();
                    if (temp != null)
                    {
                        temp.id = ob.id;
                        temp.product_name = ob.product_name;
                        temp.category = ob.category;
                        temp.image_url = ob.image_url;
                        temp.brand = ob.brand;
                        temp.sub_category = ob.sub_category;
                        temp.sell_price = ob.sell_price;
                        temp.cost_price = ob.cost_price;
                        temp.weight = ob.weight;
                        temp.status = ob.status;
                        temp.Stock = ob.Stock;
                    }

                }
                else
                {
                    db.products.Add(ob);
                }
                int x = db.SaveChanges();
                if (x > 0)
                {
                    _Productid = ob.id;
                }

            }
            return _Productid;
        }
Ejemplo n.º 2
0
 public static int AddUpdateProduct(product ob)
 {
     return ProductProvider.AddUpdateProduct(ob);
 }
        public void SaveProduct(object parameter)
        {
            try
            {
                path = InventoryHelper.GetSaveFilePath() + "\\" + ProductName + System.IO.Path.GetExtension(SelectedPath);
                if (SelectedPath != InventoryHelper.ImageNA)
                {

                    worker.DoWork += worker_DoWork;
                    worker.RunWorkerCompleted += worker_RunWorkerCompleted;
                    worker.RunWorkerAsync();

                }
                product temp = new product();
                temp.id = ProductId;
                temp.product_name = ProductName.Trim();
                if (!ProductServices.CheckProductNameAvailable(temp.product_name) && (ProductServices.GetProduct(temp.id).product_name != temp.product_name))
                {
                    InventoryHelper.SimpleAlert("Warning", "Product Name is Already taken");
                    return;
                }
                temp.brand = Brand == null ? "" : Brand;
                temp.sub_category = SelectedSubCategory.id;
                temp.category = SelectedCategory.id;
                temp.sell_price = SellingPrice;
                temp.cost_price = CostPrice;
                temp.image_url = SelectedPath == InventoryHelper.ImageNA ? "" : path;
                temp.weight = Weight == null ? "" : Weight;
                temp.status = true;
                ProductId = ProductServices.AddUpdateProduct(temp);
                if (ProductId > 0)
                {
                    //MessageBox.Show("Product Edited");
                    InventoryHelper.SuccessAlert("Success", "Product Edited");
                  
                }
                Close = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Product Entry Fails:" + ex.ToString());
                //InventoryHelper.SimpleAlert("Warning", "Product Entry Fails:" + ex.ToString());
                   
            }

        }
        public void SaveProduct(object parameter)
        {
            try
            {
                string path = InventoryHelper.GetSaveFilePath() + "\\" + ProductName + System.IO.Path.GetExtension(SelectedPath);
                if (SelectedPath != InventoryHelper.ImageNA)
                {
                    System.IO.File.Copy(SelectedPath, path, true);
                }
                product temp = new product();
                temp.product_name = ProductName.Trim();
                if (!ProductServices.CheckProductNameAvailable(temp.product_name))
                {
                    InventoryHelper.SimpleAlert("Warning", "Product Name is Already taken");
                    return;
                }
                temp.brand = Brand == null ? "" : Brand;
                temp.sub_category = SelectedSubCategory.id;
                temp.category = SelectedCategory.id;
                temp.sell_price = SellingPrice;
                temp.cost_price = CostPrice;
                temp.image_url = SelectedPath == InventoryHelper.ImageNA ? "" : path;
                temp.weight = Weight == null ? "" : Weight;
                temp.Stock = 0;
                temp.status = true;
                int productId = ProductServices.AddUpdateProduct(temp);
                if (productId > 0)
                {
                   // MessageBox.Show("Product Added");
                    InventoryHelper.SuccessAlert("Success", "Product Added");
                    Brand = "";
                    SellingPrice = 0;
                    CostPrice = 0;
                    Weight = "";
                    SelectedPath = InventoryHelper.ImageNA;
                    ProductName = "";
                    SelectedSubCategory = null;
                    SelectedCategory = null;
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Product Entry Fails:" + ex.ToString());
            }

        }
        protected ProductSellingEntity CoverttoProductSellingEntity(product ob)
        {

            ProductSellingEntity tempproduct = new ProductSellingEntity();
            tempproduct.ProductId = ob.id;
            tempproduct.ProductName = ob.product_name;
            tempproduct.Quantity = Quantity;
            tempproduct.SellingPrice = ob.sell_price;
            tempproduct.Amount = tempproduct.SellingPrice * Quantity;
            return tempproduct;
        }