コード例 #1
0
 public ActionResult Add()
 {
     var category = new EditCategory();
     ViewBag.Title = Localisation.Admin.PageContent.Add;
     ViewBag.Category = Localisation.Admin.PageContent.Category;
     return View("Edit", category);
 }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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});
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public JsonResult _CategoriesForProduct(Guid id)
        {
            var categoriesForProduct = categoryService.ListCategoriesForProduct(id);

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