Пример #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));
        }
Пример #2
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));
        }
Пример #3
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 }));
        }