示例#1
0
        public IActionResult AddCategory(Category c)
        {
            c.CategoryId = Guid.NewGuid().ToString();
            categorylogic.Add(c);

            return(RedirectToAction(nameof(ListCategories)));
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtCategoryName.Text))
            {
                return;
            }

            if (lblCategoryId.Text == "XX")
            {
                Category addCategory = new Category {
                    Description = txtCategoryName.Text.Trim().ToUpper()
                };
                var result = _categoryLogic.Add(addCategory);

                if (result)
                {
                    MessageBox.Show("Categoria Agregada...");
                }
                else
                {
                    MessageBox.Show("Error Al Agregar La Categoria...");
                }
            }
            else
            {
                int categoryId   = int.Parse(lblCategoryId.Text);
                var editCategory = _categoryLogic.GetById(categoryId);
                editCategory.Description = txtCategoryName.Text.Trim();
                editCategory.Disabled    = !chkEnabled.Checked;

                var result = _categoryLogic.Edit(editCategory);

                if (result)
                {
                    MessageBox.Show("Categoria Actualizada...");
                }
                else
                {
                    MessageBox.Show("Error Al Actualizar La Categoria...");
                }
            }

            if (this.Owner != null && this.Owner.Name == "frmProducts")
            {
                Close();
            }
            Clear();
            FillDatagrid();
        }
示例#3
0
        public void TestAddNewCategory()
        {
            CategoryLogic c = new CategoryLogic(this.categrepo.Object, this.comprepo.Object, this.sponsorrepo.Object);

            Category newc = new Category()
            {
                CategoryId     = Guid.NewGuid().ToString(),
                Name           = CategoryType.ClassicPhysique,
                StartingWeight = 87,
                MaximumWeight  = 111
            };


            categrepo.Setup(x => x.AddNewItem(It.IsAny <Category>()));
            c.Add(newc);

            categrepo.Verify(x => x.AddNewItem(newc), Times.Once);
        }
 public void AddCategory([FromBody] Category item)
 {
     logic.Add(item);
 }