public ActionResult AddBattle(BattleViewModel battleViewModel) { using (var warshipsContext = new WarshipsContext()) { var battle = new Battle { BattleName = battleViewModel.BattleName }; warshipsContext.Battles.Add(battle); warshipsContext.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult AddShip(ShipViewModel ShipViewModel) { using (var warshipContext = new WarshipsContext()) { var ship = new Ship { ShipName = ShipViewModel.ShipName, ShipTypeId = ShipViewModel.ShipTypeId }; warshipContext.Ships.Add(ship); warshipContext.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult DeleteBattle(BattleViewModel battleViewModel) { using (var warshipsContext = new WarshipsContext()) { var battle = warshipsContext.Battles.SingleOrDefault(p => p.BattleId == battleViewModel.BattleId); if (battle != null) { warshipsContext.Battles.Remove(battle); warshipsContext.SaveChanges(); return(RedirectToAction("Index")); } } return(new HttpNotFoundResult()); }
public ActionResult DeleteShip(ShipViewModel shipViewModel) { using (var warshipsContext = new WarshipsContext()) { var ship = warshipsContext.Ships.SingleOrDefault(p => p.ShipId == shipViewModel.ShipId); if (ship != null) { warshipsContext.Ships.Remove(ship); warshipsContext.SaveChanges(); return(RedirectToAction("Index")); } } return(new HttpNotFoundResult()); }
public ActionResult EditShip(ShipViewModel shipViewModel) { using (var warshipsContext = new WarshipsContext()) { var ship = warshipsContext.Ships.SingleOrDefault(p => p.ShipId == shipViewModel.ShipId); if (ship != null) { ship.ShipName = shipViewModel.ShipName; ship.ShipTypeId = shipViewModel.ShipTypeId; warshipsContext.SaveChanges(); return(RedirectToAction("Index")); } } return(new HttpNotFoundResult()); }