Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ParentId,SpeciesId,Percent")] SpeciesBreakdown speciesBreakdown)
        {
            if (ModelState.IsValid)
            {
                // update ratios
                var target = speciesBreakdown.Percent;

                // ensure the old is gotten.
                var old = db.PopulationGroups
                          .Single(x => x.Id == speciesBreakdown.ParentId);

                var spe = db.Species.Single(x => x.Id == speciesBreakdown.SpeciesId);
                // set percents
                old.SetSpeciesPercent(spe, target);

                foreach (var conn in old.SpeciesBreakdown.Where(x => x.SpeciesId != spe.Id))
                {
                    db.Entry(conn).State = EntityState.Modified;
                }

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.ParentId  = new SelectList(db.PopulationGroups, "Id", "Name", speciesBreakdown.ParentId);
            ViewBag.SpeciesId = new SelectList(db.Species, "Id", "Name", speciesBreakdown.SpeciesId);
            return(View(speciesBreakdown));
        }
        public ActionResult Create([Bind(Include = "Id,Name,MarketId,Infants,Children,Adults,Seniors,SkillLevel,PrimaryJobId,Priority")] PopulationGroup populationGroup)
        {
            if (ModelState.IsValid)
            {
                db.PopulationGroups.Add(populationGroup);
                db.SaveChanges();

                // Population Groups default to 100% of some (usually the first)
                // Party, Species, and Culture by default to ensure they have
                // something.

                // get the new pop group.
                var pop = db.PopulationGroups
                          .Single(x => x.MarketId == populationGroup.MarketId &&
                                  x.PrimaryJobId == populationGroup.PrimaryJobId);

                // Set Default Species
                var species = new SpeciesBreakdown
                {
                    ParentId  = pop.Id,
                    SpeciesId = db.Species.First().Id,
                    Percent   = 1
                };

                db.PopSpeciesBreakdowns.Add(species);

                // set default Culture
                var culture = new CultureBreakdown
                {
                    ParentId  = pop.Id,
                    CultureId = db.Cultures.First().Id,
                    Percent   = 1
                };

                db.PopCultureBreakdowns.Add(culture);

                // set Default Political Group
                var party = new PoliticalBreakdown
                {
                    ParentId         = pop.Id,
                    PoliticalGroupId = db.PoliticalGroups.First().Id,
                    Percent          = 1
                };

                db.PopPoliticalBreakdowns.Add(party);

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PrimaryJobId = new SelectList(db.Jobs, "Id", "Name", populationGroup.PrimaryJobId);
            ViewBag.MarketId     = new SelectList(db.Markets, "Id", "Name", populationGroup.MarketId);
            return(View(populationGroup));
        }
Exemplo n.º 3
0
        // GET: SpeciesBreakdowns/Details/5
        public ActionResult Details(int?parentId, int?speciesId)
        {
            if (parentId == null || speciesId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SpeciesBreakdown speciesBreakdown = db.PopSpeciesBreakdowns
                                                .SingleOrDefault(x => x.ParentId == parentId && x.SpeciesId == speciesId);

            if (speciesBreakdown == null)
            {
                return(HttpNotFound());
            }
            return(View(speciesBreakdown));
        }
Exemplo n.º 4
0
        // GET: SpeciesBreakdowns/Edit/5
        public ActionResult Edit(int?parentId, int?speciesId)
        {
            if (parentId == null || speciesId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SpeciesBreakdown speciesBreakdown = db.PopSpeciesBreakdowns
                                                .SingleOrDefault(x => x.ParentId == parentId && x.SpeciesId == speciesId);

            if (speciesBreakdown == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ParentId  = new SelectList(db.PopulationGroups, "Id", "Name", speciesBreakdown.ParentId);
            ViewBag.SpeciesId = new SelectList(db.Species, "Id", "Name", speciesBreakdown.SpeciesId);
            return(View(speciesBreakdown));
        }
Exemplo n.º 5
0
        public ActionResult DeleteConfirmed(int parentId, int speciesId)
        {
            SpeciesBreakdown speciesBreakdown = db.PopSpeciesBreakdowns
                                                .SingleOrDefault(x => x.ParentId == parentId && x.SpeciesId == speciesId);

            db.PopSpeciesBreakdowns.Remove(speciesBreakdown);

            var parent = db.PopulationGroups
                         .Single(x => x.Id == speciesBreakdown.ParentId);

            // after deletion normalize percents to 100 percent splits.
            parent.NormalizeSpecies();

            // Mark all remaining sections as modified so they are updated in the DB.
            foreach (var spe in parent.SpeciesBreakdown)
            {
                db.Entry(spe).State = EntityState.Modified;
            }

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }