Esempio n. 1
0
        public ActionResult New(CivilizationInfrastructureForm form)
        {
            Debug.WriteLine($"POST: Civilization Infrastructure Controller: New");
            DB_users user = Auth.User;
            var      game = GameState.Game;

            var planet   = game.Sector.PlanetFromID(form.PlanetID.Value);
            var dbStruct = game.GameStatistics.InfrastructureRaw
                           .Where(x => x.id == form.SelectedInfrastructureID.Value)
                           .FirstOrDefault();

            if (planet == null || dbStruct == null)
            {
                return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
            }

            DB_civilization_infrastructure infrastructure = new DB_civilization_infrastructure();

            infrastructure.game_id         = game.ID;
            infrastructure.civilization_id = form.CivilizationID.Value;
            infrastructure.planet_id       = planet.PlanetID;
            infrastructure.struct_id       = dbStruct.id;
            infrastructure.name            = form.Name;
            infrastructure.current_health  = dbStruct.base_health;
            infrastructure.experience      = 0;
            infrastructure.can_upgrade     = form.CanUpgrade;
            infrastructure.is_military     = form.IsMilitary;
            infrastructure.gmnotes         = form.GMNotes;
            Database.Session.Save(infrastructure);

            Database.Session.Flush();
            return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
        }
Esempio n. 2
0
        public ActionResult Edit(CivilizationInfrastructureForm form)
        {
            Debug.WriteLine($"POST: Civilization Infrastructure Controller: Edit");
            DB_users user = Auth.User;
            var      game = GameState.Game;

            DB_civilization_infrastructure infrastructure = FindCivilizationInfrastructure(form.ID).CivilizationInfo;

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

            var planet   = game.Sector.PlanetFromID(form.PlanetID.Value);
            var dbStruct = game.GameStatistics.InfrastructureRaw
                           .Where(x => x.id == form.SelectedInfrastructureID.Value)
                           .FirstOrDefault();

            if (planet == null || dbStruct == null)
            {
                return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
            }

            infrastructure.name = form.Name;
            if (RequireGMAdminAttribute.IsGMOrAdmin())
            {
                infrastructure.civilization_id = form.CivilizationID.Value;
                infrastructure.planet_id       = planet.PlanetID;
                infrastructure.struct_id       = dbStruct.id;
                infrastructure.current_health  = form.CurrentHealth;
                infrastructure.experience      = form.Experience;
                infrastructure.can_upgrade     = form.CanUpgrade;
                infrastructure.is_military     = form.IsMilitary;
                infrastructure.gmnotes         = form.GMNotes;
            }
            Database.Session.Update(infrastructure);

            Database.Session.Flush();
            return(RedirectToRoute("ViewCivilization", new { civilizationID = form.CivilizationID.Value }));
        }