public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { User user = new User { Email = model.Email, UserName = model.Email, Nickname = model.Nickname, HeroType = model.HeroType }; // добавляем пользователя var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { // установка куки await _signInManager.SignInAsync(user, false); CCultivator newCultivator = new CCultivator() { LocationId = GWorld.World.SubLocations[0].Id }; newCultivator.PlayerId = CultivatorContext.getHex(user.UserName); newCultivator.Name = user.Nickname; newCultivator.Inventory = new CCultivator.CInventory(); newCultivator.HeroType = user.HeroType; switch (user.HeroType) { case "/img/hero1.png": newCultivator.Stats.MainStats.Strength += 5; break; case "/img/hero2.png": newCultivator.Stats.MainStats.Agility += 5; break; case "/img/hero3.png": newCultivator.Stats.MainStats.Intelligence += 5; break; } await cultivatordb.Create(newCultivator); return(RedirectToAction("Profile", "Account")); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } return(View(model)); }
public async Task <ActionResult> Index() { if (User.Identity.IsAuthenticated) { var c = await cultivatordb.GetCultivator(User.Identity.Name); if (c == null) { CCultivator newCultivator = new CCultivator() { LocationId = GWorld.World.SubLocations[0].Id }; newCultivator.PlayerId = CultivatorContext.getHex(User.Identity.Name); newCultivator.Name = User.Identity.Name; newCultivator.Inventory = new CCultivator.CInventory(); newCultivator.HeroType = User.Identity.Name; await cultivatordb.Create(newCultivator); } TempData["Nickname"] = c.Name; TempData["Gold"] = c.Gold; } return(View()); }