Ejemplo n.º 1
0
        public ActionResult ShipEdit(int id)
        {
            using (var warshipContext = new WarshipsContext())
            {
                var shipTypes = warshipContext.ShipTypes.Select(st => new SelectListItem
                {
                    Value = st.ShipTypeId.ToString(),
                    Text  = st.ShipTypeName
                }).ToList();

                ViewBag.ShipTypes = shipTypes;


                var ship = warshipContext.Ships.SingleOrDefault(p => p.ShipId == id);
                if (ship != null)
                {
                    var shipViewModel = new ShipViewModel
                    {
                        ShipId     = ship.ShipId,
                        ShipTypeId = ship.ShipTypeId,
                        ShipName   = ship.ShipName
                    };

                    return(View("AddEditShip", shipViewModel));
                }
            }

            return(new HttpNotFoundResult());
        }
Ejemplo n.º 2
0
        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"));
        }
Ejemplo n.º 3
0
        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"));
        }
Ejemplo n.º 4
0
        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());
        }
Ejemplo n.º 5
0
        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());
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
        public ActionResult Index()
        {
            using (var warshipsContext = new WarshipsContext())
            {
                var battleList = new BattleListViewModel
                {
                    //Convert each Battle to a BattleViewModel
                    Battles = warshipsContext.Battles.Select(r => new BattleViewModel
                    {
                        BattleId   = r.BattleId,
                        BattleName = r.BattleName,
                    }).ToList()
                };

                battleList.TotalBattles = battleList.Battles.Count;

                return(View(battleList));
            }
        }
Ejemplo n.º 8
0
        public ActionResult BattleEdit(int id)
        {
            using (var warshipsContext = new WarshipsContext())
            {
                var battle = warshipsContext.Battles.SingleOrDefault(p => p.BattleId == id);
                if (battle != null)
                {
                    var battleViewModel = new BattleViewModel
                    {
                        BattleId   = battle.BattleId,
                        BattleName = battle.BattleName,
                    };

                    return(View("AddEditBattle", battleViewModel));
                }
            }

            return(new HttpNotFoundResult());
        }
Ejemplo n.º 9
0
        public ActionResult ShipAdd()
        {
            var shipViewModel = new ShipViewModel();

            using (var warshipContext = new WarshipsContext())
            {
                var shipTypes = warshipContext.ShipTypes.Select(st => new SelectListItem
                {
                    Value = st.ShipTypeId.ToString(),
                    Text  = st.ShipTypeName
                }).ToList();

                ViewBag.ShipTypes = shipTypes;
            }



            return(View("AddEditShip", shipViewModel));
        }
Ejemplo n.º 10
0
        public ActionResult Index()
        {
            using (var warshipContext = new WarshipsContext())
            {
                var shipList = new ShipListViewModel
                {
                    //Convert each Ship to a ShipViewModel
                    Ships = warshipContext.Ships.Select(p => new ShipViewModel
                    {
                        ShipId       = p.ShipId,
                        ShipName     = p.ShipName,
                        ShipTypeName = p.ShipType.ShipTypeName,
                    }).ToList()
                };

                shipList.TotalShips = shipList.Ships.Count;

                return(View(shipList));
            }
        }
Ejemplo n.º 11
0
        public ActionResult ShipDetail(int id)
        {
            using (var warshipsContext = new WarshipsContext())
            {
                //Allows the ship name and type to be displayed
                var ship = warshipsContext.Ships.Include("ShipType").SingleOrDefault(p => p.ShipId == id);
                if (ship != null)
                {
                    var ShipViewModel = new ShipViewModel
                    {
                        ShipId       = ship.ShipId,
                        ShipName     = ship.ShipName,
                        ShipTypeName = ship.ShipType.ShipTypeName
                    };

                    return(View(ShipViewModel));
                }
            }

            return(new HttpNotFoundResult());
        }