public ActionResult DeclareWar([System.Web.Http.FromBody] WarDeclarationViewModel vm) { var defender = countryRepository.GetById(vm.SelectedCountryID); if (defender == null) { return(RedirectToHomeWithError("Country does not exist!")); } var attacker = countryRepository.GetById(vm.AttackerCountryID); if (attacker == null) { return(RedirectToHomeWithError("Country does not exist!")); } if (isPresident(attacker, SessionHelper.CurrentEntity.EntityID) == false) { return(RedirectToHomeWithError("You are not a president!")); } var result = warService.CanDeclareWar(attacker, defender); if (result.IsError) { AddError(result); return(RedirectBack()); } if (ModelState.IsValid) { var warID = (int)warService.DeclareWar(attacker, defender); AddInfo("War has been declared!"); return(RedirectToAction("View", "War", new { warID = warID })); } var viewVm = new DeclareWarViewModel(attacker, countryRepository); return(View(viewVm)); }
public ActionResult DeclareWar(int countryID) { var country = countryRepository.GetById(countryID); if (country == null) { return(RedirectToHomeWithError("Country does not exist")); } var entityID = SessionHelper.CurrentEntity.EntityID; if (isPresident(country, entityID) == false) { return(RedirectToHomeWithError("You are not a president of this country to declare wars in it's behalf!")); } var regions = country.Regions.ToList(); var vm = new DeclareWarViewModel(country, countryRepository); return(View(vm)); }