Пример #1
0
        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
 public ActionResult Edit(int id)
 {
     var category = categoryRepository.GetById(id);
     var viewModel = new CategoryFormModel(category);
     return View(viewModel);
 }