Beispiel #1
0
        public ActionResult New(WormholeForm form)
        {
            Debug.WriteLine($"POST: Wormhole Controller: New - starsystemID={form.StarsystemID} HexX={form.HexX} HexY={form.HexY}");
            var game = GameState.Game;

            var systemTwo = game.Sector.StarsystemFromHex(new Fotiv_Automator.Models.Tools.HexCoordinate(form.HexX, form.HexY));

            if (systemTwo == null)
            {
                ModelState.AddModelError("Hex Code", "Star System does not exist");
            }

            if (!ModelState.IsValid)
            {
                return(View(form));
            }

            Debug.WriteLine($"POST: Wormhole Controller: New - systemTwo.ID={systemTwo.ID} systemTwo.Hex.X={systemTwo.HexCode.X} systemTwo.Hex.Y={systemTwo.HexCode.Y}");

            DB_wormholes wormhole = new DB_wormholes();

            wormhole.game_id       = game.ID;
            wormhole.system_id_one = form.StarsystemID;
            wormhole.system_id_two = systemTwo.ID;
            wormhole.gmnotes       = form.GMNotes;
            Database.Session.Save(wormhole);

            Database.Session.Flush();
            return(RedirectToRoute("StarMap"));
        }
Beispiel #2
0
        public ActionResult Edit(WormholeForm form)
        {
            Debug.WriteLine($"POST: Wormhole Controller: Edit - wormholeID={form.ID} HexX={form.HexX} HexY={form.HexY}");
            var game = GameState.Game;

            var wormhole = game.Sector.WormholeFromID(form.ID.Value).Info;

            if (wormhole.game_id != game.Info.id)
            {
                return(RedirectToRoute("game", new { gameID = game.Info.id }));
            }

            var systemTwo = game.Sector.StarsystemFromHex(new Fotiv_Automator.Models.Tools.HexCoordinate(form.HexX, form.HexY));

            if (systemTwo == null)
            {
                ModelState.AddModelError("Hex Code", "Star System does not exist");
            }

            if (!ModelState.IsValid)
            {
                return(View(form));
            }

            wormhole.system_id_one = form.StarsystemID;
            wormhole.system_id_two = systemTwo.ID;
            wormhole.gmnotes       = form.GMNotes;
            Database.Session.Update(wormhole);

            Database.Session.Flush();
            return(RedirectToRoute("StarMap"));
        }