Пример #1
0
        // zobrazení stránky Locations
        public async Task <ActionResult> Locations()
        {
            ViewBag.Message = "Locations page.";

            List <TownsDO> towns =
                await TownsDO.GetTownsAsync();

            List <LocationsDO> locations =
                await LocationsDO.GetLocationsAsync(towns[0].TownID);

            ViewBag.Town = towns
                           .Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.TownID.ToString()
            })
                           .ToList();

            ViewBag.Locations = locations;

            LocationModel model = new LocationModel();

            model.TownID = towns[0].TownID;

            return(View(model));
        }
Пример #2
0
        // zobrazení stránky NewBeast
        public async Task <ActionResult> NewBeast()
        {
            List <BeastTypeDO> beastType =
                await BeastTypeDO.GetBeastTypeAsync();

            // hardcoded - allowing to add beasts only outside of towns
            List <LocationsDO> locations =
                await LocationsDO.GetLocationsAsync(1);

            ViewBag.beastType = beastType
                                .Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.Idbeasttype.ToString()
            })
                                .ToList();

            ViewBag.Location = locations
                               .Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.LocationID.ToString()
            })
                               .ToList();

            BeastModel model = new BeastModel();

            return(View(model));
        }
Пример #3
0
        public async Task <ActionResult> NewBeast(BeastModel model)
        {
            List <BeastTypeDO> beastType =
                await BeastTypeDO.GetBeastTypeAsync();

            // hardcoded - povoluje přidat bestie pouze mimo města
            List <LocationsDO> locations =
                await LocationsDO.GetLocationsAsync(0);

            ViewBag.beastType = beastType
                                .Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.Idbeasttype.ToString()
            })
                                .ToList();

            ViewBag.Location = locations
                               .Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.LocationID.ToString()
            })
                               .ToList();

            if (ModelState.IsValid)
            {
                if (model.BeastName != null && model.BeastBio != null)
                {
                    using (fantasyDbEntities context = new fantasyDbEntities())
                    {
                        // Vytvoření nové bestie a načtení hodnot zvolených uživatelem
                        Bestiary beast = new Bestiary();
                        beast.name        = model.BeastName;
                        beast.bio         = model.BeastBio;
                        beast.hp          = model.BeastHp;
                        beast.attack      = model.BeastAttack;
                        beast.defense     = model.BeastDefense;
                        beast.locationid  = model.BeastLocation;
                        beast.beasttypeid = model.BeastTypeID;
                        // Přidání řádku tabulky a uložení změn
                        context.Bestiary.Add(beast);
                        context.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("Bestiary"));
        }