Exemplo n.º 1
0
        public ActionResult Create(CategoryViewModel categoryViewModel)
        {
            if (ModelState.IsValid)
            {
                Mapper.CreateMap <CategoryViewModel, Category>();
                Category category = Mapper.Map <CategoryViewModel, Category>(categoryViewModel);

                var result = _categoryBusiness.ValidateCategory(category, "I");

                if (!string.IsNullOrEmpty(result))
                {
                    ModelState.AddModelError("", result);
                    return(View(categoryViewModel));
                }
                else
                {
                    category.TokenKey = GlobalMethods.GetToken();
                    bool isSuccess = _categoryBusiness.AddUpdateDeleteCategory(category, "I");
                    if (isSuccess)
                    {
                        TempData["Success"]   = "Category Created Successfully!!";
                        TempData["isSuccess"] = "true";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["Success"]   = "Failed to create category!!";
                        TempData["isSuccess"] = "false";
                    }
                }
            }
            return(View(categoryViewModel));
        }