public ActionResult Add()
 {
     var category = new EditCategory();
     ViewBag.Title = Localisation.Admin.PageContent.Add;
     ViewBag.Category = Localisation.Admin.PageContent.Category;
     return View("Edit", category);
 }
        public void ToEntity_should_map_properties()
        {
            var category = new EditCategory {Description = "Category 2 Description", Name = "Category 2 Name"};

            var categoryEntity = category.ToEntity();

            Assert.That(categoryEntity.Name, Is.EqualTo(category.Name));
            Assert.That(categoryEntity.Description, Is.EqualTo(category.Description));
        }
        public void FromEntity_should_map_properties()
        {
            var categoryEntity = new Category {Name = "Category 1", Description = "Category 1 Description"};
            var category = new EditCategory();

            category.FromEntity(categoryEntity);

            Assert.That(category.Name, Is.EqualTo(categoryEntity.Name));
            Assert.That(category.Description, Is.EqualTo(categoryEntity.Description));
        }
        public ViewResult Edit(Guid id)
        {
            var categoryEntity = categoryService.GetSingle(id) ?? new Category();
            if (categoryEntity.Id == Guid.Empty)
            {
               ModelState.AddModelError("", Localisation.ViewModels.EditCategory.CategoryNotFound);
            }

            var category = new EditCategory();
            category.FromEntity(categoryEntity);
            ViewBag.Title = Localisation.Admin.PageContent.Edit;
            ViewBag.Category = Localisation.Admin.PageContent.Category;
            return View(category);
        }
        public ActionResult Add(EditCategory category)
        {
            var categoryEntity = new Category();
            if (ModelState.IsValid)
            {
                categoryEntity = category.ToEntity();
                if (!categoryService.TryAdd(categoryEntity))
                {
                    AddModelStateErrors(categoryEntity.Errors);
                }
            }

            if (!ModelState.IsValid)
            {
                ViewBag.Title = Localisation.Admin.PageContent.Add;
                ViewBag.Category = Localisation.Admin.PageContent.Category;
                return View("Edit", category);
            }

            return RedirectToAction("Edit", new {id = categoryEntity.Id});
        }
        public JsonResult _Add(EditCategory category)
        {
            var categoryEntity = new Category();
            if (ModelState.IsValid)
            {
                categoryEntity = category.ToEntity();
                if (!categoryService.TryAdd(categoryEntity))
                {
                    AddModelStateErrors(categoryEntity.Errors);
                }
            }

            if (!ModelState.IsValid)
            {
                return Json(categoryEntity.Errors);
            }

            return Json(categoryEntity.Id);
        }
        public JsonResult _CategoriesForSelectDialog(Guid id)
        {
            var categoriesForProduct = categoryService.ListCategoriesForProduct(id);
            var allCategories = categoryService.List();
            var allCategoriesForDialog = new EditCategory().CategoryList(allCategories, id,
                                                                                    categoriesForProduct);

            return Json(allCategoriesForDialog, JsonRequestBehavior.AllowGet);
        }
        public JsonResult _CategoriesForProduct(Guid id)
        {
            var categoriesForProduct = categoryService.ListCategoriesForProduct(id);

            var categories = new EditCategory().CategoryList(categoriesForProduct, id);
            return Json(categories, JsonRequestBehavior.AllowGet);
        }