コード例 #1
0
ファイル: CategoryController.cs プロジェクト: kostyrin/FNHMVC
        public ActionResult Save(CategoryFormModel form)
        {
            if (ModelState.IsValid)
            {
                //TODO: Create Automapper form => command
                var command = new CreateOrUpdateCategoryCommand()
                {
                    CategoryId = form.CategoryId,
                    Name = form.Name,
                    Description = form.Description
                };

                IEnumerable<ValidationResult> errors = commandBus.Validate(command);
                ModelState.AddModelErrors(errors);
                if (ModelState.IsValid)
                {
                    var result = commandBus.Submit(command);
                    if (result.Success) return RedirectToAction("Index");
                }
            }

            if (form.CategoryId == 0)
                return View("Create", form);
            else
                return View("Edit", form);
        }
コード例 #2
0
ファイル: CategoryController.cs プロジェクト: kostyrin/FNHMVC
 public ActionResult Edit(int id)
 {
     var category = categoryRepository.GetById(id);
     var viewModel = new CategoryFormModel(category);
     return View(viewModel);
 }