Exemplo n.º 1
0
        private void View_OnCategoriesUpdateItem(object sender, CategoriesManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(CategoriesManagementEventArgs));
            }

            var category = this.categoriesServices.GetCategory(e.Id);

            if (category == null)
            {
                this.View.ModelState.AddModelError(
                    ErrorMessages.MODEL_ERROR_KEY,
                    string.Format(ErrorMessages.MODEL_ERROR_MESSAGE, e.Id));

                return;
            }

            this.View.TryUpdateModel(category);

            if (this.View.ModelState.IsValid)
            {
                this.categoriesServices.UpdateCategory(e.Id, category);
            }
        }
Exemplo n.º 2
0
        private void View_OnCategoriesDeleteItem(object sender, CategoriesManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(CategoriesManagementEventArgs));
            }

            this.categoriesServices.DeleteCategory(e.Id);
        }
Exemplo n.º 3
0
        private void View_OnCategoriesAddItem(object sender, CategoriesManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(CategoriesManagementEventArgs));
            }

            var category = new Category()
            {
                Name = e.Name
            };

            e.Id = this.categoriesServices.AddCategory(category);
        }
Exemplo n.º 4
0
        public void AddItemShouldAddCategoryAndReturnIdWhenOnAddItemEventIsRaised()
        {
            var name = "Test Name";
            var categoryEventArgs = new CategoriesManagementEventArgs()
            {
                Name = name
            };

            this.categoriesView.Raise(c => c.OnCategoriesAddItem += null, categoryEventArgs);

            var expectedId = 1;

            this.categoriesServices.Verify(c => c.AddCategory(It.Is <Category>(m => m.Name == name)), Times.Once);

            Assert.AreEqual(expectedId, categoryEventArgs.Id);
        }
Exemplo n.º 5
0
        protected void CreateCategoryBtn_Click(object sender, EventArgs e)
        {
            if (this.Page.IsValid)
            {
                var categoryEventArgs = new CategoriesManagementEventArgs()
                {
                    Name = this.CategoryNameTextBox.Text
                };

                this.OnCategoriesAddItem?.Invoke(sender, categoryEventArgs);

                this.SuccessPanel.Visible        = true;
                this.AddedCategoryIdLiteral.Text = categoryEventArgs.Id.ToString();

                this.ClearFields();
            }
        }