예제 #1
0
        public IActionResult Create()
        {
            var vm = new CharacterCreateVM();

            vm.RacesList = new List <SelectListItem>();
            foreach (var x in appDbContext.Races)
            {
                vm.RacesList.Add(new SelectListItem(x.Name, x.RaceID.ToString()));
            }
            return(View(vm));
        }
예제 #2
0
        public IActionResult Create(CharacterCreateVM create)
        {
            // TODO polaczenie modelu CharacterCreateVM z listą ras z bazy danych
            if (ModelState.IsValid)
            {
                var newCharacter = new Character
                {
                    Name                    = create.Name,
                    Race                    = appDbContext.Races.FirstOrDefault(x => x.RaceID == create.RaceID),
                    Experience              = 0,
                    Level                   = 1,
                    SilfrQuantity           = startSilfrQuantity,
                    AdditionalAgility       = 0,
                    AdditionalAtttackDamage = 0,
                    AdditionalDefence       = 0,
                    AdditionalDexterity     = 0,
                    AdditionalVitality      = 0,
                    StatPoints              = 0
                };

                _ICharacterRepository.AddCharacter(newCharacter);

                var currentUser = appDbContext.Users.FirstOrDefault(x => x.UserName == HttpContext.User.Identity.Name);
                currentUser.IsCharacterCreated = true;
                currentUser.AccountCharacterID = newCharacter.CharacterID;

                appDbContext.SaveChanges();


                // dodanie startowych itemow
                for (int i = 1; i <= 7; i++)
                {
                    _ICharacterRepository.AddItem(i, currentUser.AccountCharacterID);
                }

                return(RedirectToAction("Index", "Home"));
            }


            create.RacesList = new List <SelectListItem>();
            foreach (var x in appDbContext.Races)
            {
                create.RacesList.Add(new SelectListItem(x.Name, x.RaceID.ToString()));
            }
            return(View(create));
        }