public PartialViewResult CreateCategory()
 {
     using (UnitOfWorkManager.NewUnitOfWork())
     {
         var categoryViewModel = new CreateCategoryViewModel {AllCategories = _categoryService.GetAll().ToList()};
         return PartialView(categoryViewModel);
     }
 }
        public ActionResult CreateCategory(CreateCategoryViewModel categoryViewModel)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        var category = new Category
                                           {
                                               Name = categoryViewModel.Name,
                                               Description = categoryViewModel.Description,
                                               IsLocked = categoryViewModel.IsLocked,
                                               ModeratePosts = categoryViewModel.ModeratePosts,
                                               ModerateTopics = categoryViewModel.ModerateTopics,
                                               SortOrder = categoryViewModel.SortOrder,
                                               PageTitle = categoryViewModel.PageTitle,
                                               MetaDescription = categoryViewModel.MetaDesc
                                           };

                        

                        if (categoryViewModel.ParentCategory != null)
                        {
                            var parentCategory = _categoryService.Get(categoryViewModel.ParentCategory.Value);
                            category.ParentCategory = parentCategory;
                            SortPath(category, parentCategory);
                        }

                        _categoryService.Add(category);

                        // We use temp data because we are doing a redirect
                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                                                                        {
                                                                            Message = "Category Created",
                                                                            MessageType =
                                                                                GenericMessages.success
                                                                        };
                        unitOfWork.Commit();
                    }
                    catch (Exception)
                    {
                        unitOfWork.Rollback();
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "There was an error creating the category");
            }

            return RedirectToAction("Index");
        }
        public ActionResult CreateCategory(CreateCategoryViewModel categoryViewModel)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        var category = new Category
                                           {
                                               Name = categoryViewModel.Name,
                                               Description = categoryViewModel.Description,
                                               IsLocked = categoryViewModel.IsLocked,
                                               SortOrder = categoryViewModel.SortOrder,
                                           };

                        if (categoryViewModel.ParentCategory != null)
                        {
                            category.ParentCategory =
                                _categoryService.Get(categoryViewModel.ParentCategory.Value);
                        }

                        _categoryService.Add(category);

                        // We use temp data because we are doing a redirect
                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                                                                        {
                                                                            Message = "Category Created",
                                                                            MessageType =
                                                                                GenericMessages.success
                                                                        };
                        unitOfWork.Commit();
                    }
                    catch (Exception)
                    {
                        unitOfWork.Rollback();
                    }
                }
            }

            return RedirectToAction("Index");
        }