Exemplo n.º 1
0
        private async void btnEdit_Click(object sender, EventArgs e)
        {
            if (comboCategory.SelectedValue != null)
            {
                var categories = (Category)comboCategory.SelectedItem;

                categories.CategoryName = txtName.Text;
                categories.Image        = WindowsFormsUtilities.WindowsImageConverter.ConvertImage(pictureBox1.Image);


                var validation = WindowsFormValidationContext.Validated <Category>(categories);
                if (validation.Item1)
                {
                    categoriesRepository.Edit(categories);
                    var result = await categoriesRepository.SaveChangesAsync();

                    if (result > 0)
                    {
                        MessageBox.Show("The Category has been Edit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                }
                else
                {
                    foreach (var item in validation.Item2)
                    {
                        MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        public IActionResult Edit(CategoryEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var categories = new Category()
                {
                    CategoryName = model.CategoryName,
                    CategoryId   = model.CategoryId
                };

                var editCategory = categoriesRepository.Edit(categories);
                if (editCategory != null)
                {
                    return(RedirectToAction("Index", "Categories", new { id = categories.CategoryId }));
                }
            }
            return(View());
        }
Exemplo n.º 3
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (comboUsers.SelectedValue != null)
     {
         Category category = (Category)comboUsers.SelectedItem;
         category.IsDeleted = true;
         categoriesRepository.Edit(category);
         if (categoriesRepository.SaveChanges() > 0)
         {
             MessageBox.Show("The Category has been Deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();
         }
     }
     else
     {
         MessageBox.Show("The Category is not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }