示例#1
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));
        }
        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);
        }