Exemple #1
0
        public void DeleteAnCategoryWithProducts()
        {
            Product product1 = new Product()
            {
                ProductId  = 1,
                CategoryId = 1,
                Category   = categories.ElementAt(1),
                Image      = "icon.png",
                Name       = "Mantequilla",
                Remarks    = "Muy buena"
            };
            Product product2 = new Product()
            {
                ProductId  = 2,
                CategoryId = 1,
                Category   = categories.ElementAt(2),
                Image      = "icon2.png",
                Name       = "Mantequilla",
                Remarks    = "Muy buena"
            };

            var category = categories.ElementAt(1);

            category.ProductList.Add(product1);
            category.ProductList.Add(product2);


            //Act

            var categoryManager = new CategoriesManager(dataServiceMock.Object);

            Assert.ThrowsException <Exception>(() => categoryManager.Delete(category));
            dataServiceMock.Verify(m => m.Delete(category), Times.Never());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Category category = categoriesManager.Find(x => x.Id == id);

            categoriesManager.Delete(category);
            CacheHelper.GetCategoriesFromCache();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public void DeleteAnCategoryWithoutProducts()
        {
            var category = new Category()
            {
                Description = "Lacteos"
            };


            //Act
            var categoryManager = new CategoriesManager(dataServiceMock.Object);

            categoryManager.Delete(category);

            // Asserts
            var categoryExpected = categoryManager.Categories.Where(c => c.Description == category.Description)
                                   .FirstOrDefault();

            Assert.IsNull(categoryExpected);
            Assert.AreEqual(4, categoryManager.Categories.Count);
            dataServiceMock.Verify(m => m.Delete(category));
        }
Exemple #4
0
        private void RemovB_Click(object sender, EventArgs e)
        {
            CategoryVO current = bindingSource1.Current as CategoryVO;

            if (current != null)
            {
                if (Question("هل أنت متأكد من الحذف؟") == System.Windows.Forms.DialogResult.Yes)
                {
                    if (manager.Delete(current))
                    {
                        bindingSource1.Remove(current);
                        CategoryDataGridView.Refresh();
                        Message("تم الحذف بنجاح");
                        Log(OperationsManager.EDIT_CATEGORIES);
                    }
                    else
                    {
                        Error();
                    }
                }
            }
        }
Exemple #5
0
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                Category _Category = new Category();
                _Category.Code = txtCategoryCode.Text;
                _Category.Name = txtCategoryName.Text;

                if (IdHiddenField.Value != "")
                {
                    int success = _CategoriesManager.Delete(_Category);
                    if (success > 0)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Successefully Delete Category');", true);

                        txtCategoryName.Text = "";
                        IdHiddenField.Value  = "";
                        AddButton.Text       = "Add";
                        DeleteButton.Visible = false;
                        AutoCodeGenerate();
                        LoadCategories();
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Failed delete Category');", true);
                    }
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + ex.Message + "');", true);
            }
        }