示例#1
0
 public ActionResult AddCategory(CategoryViewModel categoryModel)
 {
     if (ModelState.IsValid)
     {
         category = AutoMapper.Mapper.Map <CategoryViewModel, Category>(categoryModel);
         categoryBL.AddCategory(category);
         return(RedirectToAction("CategoryIndex"));
     }
     return(View());
 }
示例#2
0
 internal ActionResult AddCategory(CategoryModel categoryModel) //Add Category [POST]
 {
     if (ModelState.IsValid)
     {
         //Auto Mapper.
         var     mapCategory = new MapperConfiguration(configExpression => { configExpression.CreateMap <CategoryModel, Category>(); });
         IMapper mapper      = mapCategory.CreateMapper();
         var     category    = mapper.Map <CategoryModel, Category>(categoryModel);
         categoryBL.AddCategory(category); //Method call to add category
         return(RedirectToAction("Index", "Movie"));
     }
     return(View());
 }
示例#3
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (selectedCategoryId >= 0 &&
                selectedCategoryName != null &&
                !String.IsNullOrEmpty(nameTextBox.Text))
            {
                Category category = new Category();
                category.Id   = selectedCategoryId;
                category.Name = nameTextBox.Text;
                if (categoriesBl.UpdateCategory(category))
                {
                    MessageBox.Show("Category Updated successfully...");
                    nameTextBox.Clear();
                    selectedCategoryId   = -1;
                    selectedCategoryName = null;
                    CancelButton.Visible = false;
                    SaveButton.Text      = "Save";
                }
                else
                {
                    MessageBox.Show("Category update failed");
                }
            }
            else if (String.IsNullOrEmpty(nameTextBox.Text))
            {
                MessageBox.Show("Please Enter a Category name");
            }
            else
            {
                Category category = new Category();
                category.Name = nameTextBox.Text;
                if (categoriesBl.AddCategory(category))
                {
                    MessageBox.Show("Category Added Successfully...");
                }
                else
                {
                    MessageBox.Show("Category Creation Failed...");
                }
            }

            dataGridView1.DataSource = categoriesBl.GetCategories();
        }
 public ActionResult AddCategory(CategoryViewModel categoryViewModel)
 {
     if (ModelState.IsValid)
     {
         var config = new MapperConfiguration(mapping =>
         {
             mapping.CreateMap <CategoryViewModel, Category>();
         });
         IMapper  mapper   = config.CreateMapper();
         Category category = mapper.Map <CategoryViewModel, Category>(categoryViewModel);
         categoryBL.AddCategory(category);
         return(RedirectToAction("CategoryDetails"));
     }
     else
     {
         ModelState.AddModelError("", "Some error occured");
     }
     return(View());
 }