예제 #1
0
        public async Task <IActionResult> PutWeatherStationClient(long id, WeatherStationClient weatherStationClient)
        {
            if (id != weatherStationClient.WeatherStationClientId)
            {
                return(BadRequest());
            }

            _context.Entry(weatherStationClient).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WeatherStationClientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public void ctrlSearch_Click(object sender, EventArgs e)
        {
            WeatherStationClient weather = new WeatherStationClient();

            string search = ctrlYourCityName.Text;
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("lang", "en");
            dic.Add("units", "metric");
            dic.Add("mode", "json");
            dic.Add("q", search);

            WeatherResponse  res      = weather.GetWeather(dic);
            ForecastResponse Forecast = weather.GetForecast(dic);

            loWeatherInCity.Text = "Weather in: " + Forecast.City.Name + ", " + Forecast.City.Country;

            SetUIValues(res);
            SetNext24Hours(Forecast);
            DegreesSetup(res);
            WindSpeedSetup(res);
            PictureSetup(res, weather);
            NextFiveDays(Forecast.Analysis);
            //SunriseSetup(res.SysInfo.Sunrise);
            //SunsetSetup(res.SysInfo.Sunset);
            ctrlSunrise.Text = DateSetup(res.SysInfo.Sunrise);
            ctrlSunset.Text  = DateSetup(res.SysInfo.Sunset);
        }
예제 #3
0
        public void PictureSetup(WeatherResponse res, WeatherStationClient weather)
        {
            string iconId     = res.Weather[0].Icon;
            string filePath   = AppDomain.CurrentDomain.BaseDirectory + "\\" + iconId + ".png";
            bool   fileExists = File.Exists(filePath);

            string imagePath = "";

            if (fileExists == true)
            {
                imagePath = filePath;
            }
            else
            {
                imagePath = weather.GetIcon(iconId);
            }
            ctrlWeathedData.Image = Image.FromFile(imagePath);
        }
예제 #4
0
        private string GenerateToken(WeatherStationClient vc)
        {
            var claims = new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, vc.WeatherStationClientId.ToString()),
                new Claim(ClaimTypes.Name, vc.SerialNumber),
                new Claim(JwtRegisteredClaimNames.Nbf, new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds().ToString()),
                new Claim(JwtRegisteredClaimNames.Exp, new DateTimeOffset(DateTime.Now).AddDays(1).ToUnixTimeSeconds().ToString())
            };

            var token = new JwtSecurityToken(
                new JwtHeader(new SigningCredentials(
                                  new SymmetricSecurityKey(
                                      Encoding.UTF8.GetBytes(
                                          _configuration["JwtSecret"])),
                                  SecurityAlgorithms.HmacSha256)), new JwtPayload(claims));

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }
예제 #5
0
        public async Task <ActionResult> Register(LoginClient f) //Stod TaskStatus før?
        {
            f.SerialNumber = f.SerialNumber.ToLower();
            var SerialNumberExists = await _context.WeatherStationClient
                                     .Where(c => c.SerialNumber == f.SerialNumber).FirstOrDefaultAsync();

            if (SerialNumberExists != null)
            {
                return(BadRequest(new { errorMessage = "Serial Number already registered" }));
            }

            WeatherStationClient client = new WeatherStationClient();

            client.SerialNumber = f.SerialNumber;
            client.PwHash       = BCrypt.Net.BCrypt.HashPassword(f.Password, BcryptWorkfactor);

            _context.WeatherStationClient.Add(client);
            await _context.SaveChangesAsync();

            var jwtToken = new TokenDto();

            jwtToken.Token = GenerateToken(client);
            return(CreatedAtAction("Get", new { id = client.SerialNumber }, jwtToken));
        }
예제 #6
0
        public async Task <ActionResult <WeatherStationClient> > PostWeatherStationClient(WeatherStationClient weatherStationClient)
        {
            _context.WeatherStationClient.Add(weatherStationClient);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetWeatherStationClient", new { id = weatherStationClient.WeatherStationClientId }, weatherStationClient));
        }