public ActionResult Index(SuperheroRegistrationViewModel model) { if (String.IsNullOrWhiteSpace(model.Name)) { ModelState.AddModelError("Name", "Name cannot be empty."); } if (model.Skills.Count > 3) { ModelState.AddModelError("Skills", "Skills cannot be more than 3."); } if (!model.CurrentTeams.Any()) { ModelState.AddModelError("CurrentTeams", "Superhero must be assigned to a team."); } if (!ModelState.IsValid) { return View("Index", model); } CreateSuperhero(model.Name, model.Skills, model.CurrentTeams); return View("Notification", (Object)"Superhero has been added successfully."); }
public ActionResult Index() { var model = new SuperheroRegistrationViewModel() { AvailableTeams = repository.GetTeams().Select(team => team.Name).ToList() }; return View("Index", model); }
public SuperheroRegistrationViewModel(SuperheroRegistrationViewModel other) { if (other == null) throw new ArgumentNullException(nameof(other)); Name = other.Name; NewSkill = other.NewSkill; Skills = other.Skills; AvailableTeams = other.AvailableTeams; CurrentTeams = other.CurrentTeams; }