Пример #1
0
        public bool HardDeleteProduct(int id)
        {
            using CrmDbContext db = new CrmDbContext();
            ProductManagement prodMangr = new ProductManagement(db);

            return(prodMangr.DeleteProductById(id));
        }
Пример #2
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                string id = ProductDataGridView.CurrentRow.Cells[0].Value.ToString();

                if (!string.IsNullOrEmpty(codeTextBox.Text) && !string.IsNullOrEmpty(unityPriceTextBox.Text))
                {
                    if (MetroMessageBox.Show(this, $"¿Seguro que desea eliminar el Producto?", "Eliminar Prodcuto", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        if (ProductManagement.DeleteProductById(id))
                        {
                            FrmMain.Instance.ToolStripLabel.Text = "Producto eliminado de manera exitosa.";
                            CleanProduct();
                        }
                        else
                        {
                            MetroMessageBox.Show(this, $"Ha ocurrido un error al eliminar el Producto.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MetroMessageBox.Show(this, "Debe seleccionar un Producto para poder eliminarlo.", "Campo vacío", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                FrmMain.Instance.ToolStripLabel.Text = "Error: " + ex.Message;
            }
        }
Пример #3
0
        static void Main2()
        {
            ProductOption prod = new ProductOption
            {
                Name     = "mobile",
                Price    = 300,
                Quantity = 5,
            };

            using CrmDbContext db = new CrmDbContext();
            ProductManagement prodMangr = new ProductManagement(db);


            // product tries
            Product prodFind = prodMangr.FindProduct(2);

            Console.WriteLine(
                $"Id= {prodFind.Id} Name= {prodFind.Name} Price= {prodFind.Price}" +
                $" Quantity= {prodFind.Quantity}");


            //testing reading a customer
            Product pd3 = prod.FindProductById(2);

            Console.WriteLine(
                $"Id= {pd3.Id} Name= {pd3.Name} Price= {pd3.Price} Quantity={pd3.Quantity}");


            //testing updating
            ProductOption prodUpdateName = new ProductOption
            {
                Name = "laptop"
            };
            Product product = prodMangr.Update(prodChangingName, 2);

            pd3 = product;
            Console.WriteLine(
                $"Id= {pd3.Id} Name= {pd3.Name} Price= {pd3.Price} Quantity= {pd3.Quantity}");


            //testing deletion

            bool result = prodMangr.DeleteProductById(3);

            Console.WriteLine($"Result = {result}");
            pd3 = prodMangr.FindProductById(3);
            if (pd3 != null)
            {
                Console.WriteLine(
                    $"Id= {pd3.Id} Name= {pd3.Name} Price= {pd3.Price} Quantity= {pd3.Quantity}");
            }
            else
            {
                Console.WriteLine("The product does not exist");
            }
        }
Пример #4
0
        private static void DeleteProduct(ProductManagement prodMangr)
        {
            bool resultP = prodMangr.DeleteProductById(2);

            Console.WriteLine($"Result = {resultP}");
            Product pd2 = prodMangr.FindProductById(2);

            if (pd2 != null)
            {
                Console.WriteLine(
                    $"Id= {pd2.Id} ProductName= {pd2.ProductName} Price= {pd2.Price} Quantity = {pd2.Quantity}");
            }
            else
            {
                Console.WriteLine("Product Not Found");
            }
        }
 public ActionResult Deleted(int id)
 {
     if (Session["Login"] != null)
     {
         gelen = (AppUsers)Session["Login"];
     }
     else
     {
         return(RedirectToAction("Index", "Home", new { area = "" }));
     }
     if (gelen.Status.Value == 3)
     {
         productManagement.DeleteProductById(id);
         return(RedirectToAction("ProductConfirm", "AdminProductConfirm"));
     }
     else
     {
         return(RedirectToAction("Index", "Admin"));
     }
 }
Пример #6
0
        private void btnDeleteProduct_Click(object sender, EventArgs e)
        {
            string id = dgvProduct.CurrentRow.Cells[0].Value.ToString();

            try
            {
                if (ProductManagement.DeleteProductById(id))
                {
                    dgvProduct.DataSource = ProductManagement.SelectAllProducts();
                    FrmMain.Instance.ToolStripLabel.Text = "Se elimino el producto correctamente";
                }
                else
                {
                    FrmMain.Instance.ToolStripLabel.Text = "Error al eliminar el producto";
                }
            }
            catch (Exception)
            {
                throw;
            }
        }