Esempio n. 1
0
        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> Login([FromBody] LoginModel model)
        {
            var result = await signInManager.PasswordSignInAsync(model.User, model.Password, true, false);

            if (result.Succeeded)
            {
                var jwt = JwtTokenAppService.CreateToken(model);

                return(Ok(jwt));
            }

            return(Unauthorized("Invalid username or password!"));
        }
Esempio n. 3
0
        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());
        }