Exemple #1
0
        public ContentResult AddCategory([Bind(Exclude = "Id")] Category category)
        {
            string json;

            if (ModelState.IsValid)
            {
                var id = _blogRepository.AddCategory(category);
                json = JsonConvert.SerializeObject(new
                {
                    id      = id,
                    success = true,
                    message = "Category added successfully."
                });
            }
            else
            {
                json = JsonConvert.SerializeObject(new
                {
                    id      = 0,
                    success = false,
                    message = "Failed to add the category."
                });
            }

            return(Content(json, "application/json"));
        }
Exemple #2
0
 public async Task <IActionResult> Create(CategoriesVm categories)
 {
     if (ModelState.IsValid)
     {
         Categories model = _mapper.Map <Categories>(categories);
         _context.AddCategory(model);
         _context.Commit();
         AddMessage("success", "Added successfully");
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["ParentId"] = new SelectList(_context.GetCategoryList(), "CategoryId", "Title", categories.ParentId);
     return(View(categories));
 }