public async Task <IActionResult> Get() { string jwt = Request.Headers["Authorization"]; string userName = JwtTokenAppService.decodeTokenForUserName(jwt); var userData = await userManager.FindByNameAsync(userName); var cityData = await _cityService.GetCity(userData.City); return(Ok(cityData)); }
public async Task <IActionResult> BuyBuilding([FromBody] newBuildingModel newbuilding) { string jwt = Request.Headers["Authorization"]; string userName = JwtTokenAppService.decodeTokenForUserName(jwt); var userData = await userManager.FindByNameAsync(userName); var cityData = await _cityService.GetCity(userData.City); var result = await _dataRepository.BuyBuilding(newbuilding.BuildingId, cityData.Id); if (!result.Succeeded) { return(BadRequest("Internal error! Can not buy new building")); } return(Ok()); }
public async Task <IActionResult> CreateArmy(object newArmy) { string jwt = Request.Headers["Authorization"]; string userName = JwtTokenAppService.decodeTokenForUserName(jwt); var userData = await userManager.FindByNameAsync(userName); var cityData = await _cityService.GetCity(userData.City); var result = await _dataRepository.CreateArmy(newArmy, cityData.Id); if (!result.Succeeded) { return(BadRequest("Internal error! Can not create new army")); } return(Ok()); }
public async Task <IActionResult> StartUpgrade([FromBody] newUpgradeModel newUpgrade) { string jwt = Request.Headers["Authorization"]; string userName = JwtTokenAppService.decodeTokenForUserName(jwt); var userData = await userManager.FindByNameAsync(userName); var cityData = await _cityService.GetCity(userData.City); var result = await _dataRepository.StartUpgrade(newUpgrade.UpgradeId, cityData.Id); if (!result.Succeeded) { return(BadRequest("Internal error! Can not start new research")); } return(Ok()); }
public async Task <IActionResult> Register([FromBody] RegisterModel model) { var userExists = await userManager.FindByNameAsync(model.User); if (userExists != null) { return(BadRequest("user already exists")); } var cityExists = await _cityService.GetCity(model.City); if (cityExists != null) { return(BadRequest("city name already exists")); } AppUser newUser = new AppUser() { UserName = model.User, City = model.City }; var result = await userManager.CreateAsync(newUser, model.Password); if (result.Succeeded) { IdentityResult InitialCityData = await _dataRepository.CreateCity(model.City); if (!InitialCityData.Succeeded) { return(BadRequest("Internal error! Can not create new user")); } return(Ok()); } else { return(BadRequest("Password must contain at leaset one Uppercase letter and one non-alphanumeric character!")); } }