Example #1
0
        public ActionResult AddCategory(CategoryModel model)
        {
            if (Session["UserId"] != null && Session["Accountid"] != null)
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        CategoryRepo CatRepo = new CategoryRepo();

                        if (CatRepo.AddCategory(model))
                        {
                            ViewBag.Message = "Category details added successfully";
                        }
                    }

                    return(View(model));
                }
                catch
                {
                    ViewBag.Message = "Category details Addition Failed";
                    return(View(model));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }
Example #2
0
 public ActionResult Create(CategoryModel category)
 {
     try
     {
         if (ModelState.IsValid)
         {
             categories.AddCategory(category);
             if (Request.IsAjaxRequest())
             {
                 return(Json(new { success = true, name = category.Name, id = category.ID }));
             }
             return(RedirectToAction("Index", new { id = category.ID }));
         }
         if (Request.IsAjaxRequest())
         {
             return(Json(new { success = false, errors = ModelState.Values.SelectMany(v => v.Errors) }));
         }
         return(View(category));
     }
     catch (Exception e)
     {
         if (Request.IsAjaxRequest())
         {
             return(Json(new { success = false, error = e.Message }));
         }
         return(View());
     }
 }
    [HttpPost]//dodawnaie formularza
    public void AddCategory([FromForm] Category c)
    {
        CategoryRepo category = new CategoryRepo();

        category.AddCategory(c);
    }
Example #4
0
 public void AddCategory(InputCategoryModel category)
 {
     _categoryRepo.AddCategory(category);
 }