Example #1
0
        public IActionResult Create(string json)
        {
            Weather newWeather = JsonSerializer.Deserialize <Model.Weather>(json);
            Dictionary <string, object> values = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, object> >(json);

            newWeather.location = JsonSerializer.Deserialize <Model.Location>(values["location"].ToString());
            if (newWeather.temperature.Count() != 24)
            {
                throw new Exception(newWeather.temperature.Count() + " temperature data points provided. Expected 24.");
            }
            for (int i = 0; i < newWeather.temperature.Count(); i++)
            {
                newWeather.temperature[i] = (float)(((int)(newWeather.temperature[i] * 10)) / 10.0);
            }
            bool created = WeatherRepo.Create(newWeather);

            if (!created)
            {
                return(BadRequest());
            }
            Weather createdWeather = WeatherRepo.GetById(newWeather.id);

            Logger.LogInformation("New Weather was created: {@Weather}", createdWeather);
            if (createdWeather != null)
            {
                return(Created(this.Url.ToString(), createdWeather));
            }
            else
            {
                return(BadRequest());
            }
        }
        public async Task <WeatherModel> GetModelAsync(string homeCity, int precision, TemperatureUOM temperatureUOM)
        {
            try
            {
                _repo = new WeatherRepo(homeCity);

                // Get entity from Repository.
                WeatherEntity entity = await _repo.GetEntityAsync();

                // Map entity to model.
                WeatherModel model = MapEntityToModel(entity);

                // Calculate non-mappable values
                model = CalculateUnMappableValues(model, precision, temperatureUOM);

                // Todo: Implement bool if user wants metro or openweather icons
                if (true)
                {
                    model.Icon = ConvertWeatherIcon(model.Icon);
                }

                return(model);
            }
            catch (HttpRequestException ex) { throw ex; }
            catch (Exception ex)
            {
                throw new ArgumentException("Unable to retrieve Weather Model", ex);
            }
        }
Example #3
0
 public WeatherRepo GetWeatherRepo()
 {
     if (_weatherRepo == null)
     {
         _weatherRepo = new WeatherRepo(new WeatherPreferences(Android.App.Application.Context));
         _weatherRepo.Init();
     }
     return _weatherRepo;
 }
Example #4
0
        public IActionResult Update(Weather updatedWeather)
        {
            smallRecord updated = WeatherRepo.UpdateByLocation(updatedWeather);

            if (updated.id != -1)
            {
                return(Ok(updated));
            }
            return(BadRequest());
        }
Example #5
0
 public List <Weather> GetByDate(DateTime date)
 {
     return(WeatherRepo.GetByDate(date));
 }
Example #6
0
 public List <Weather> Get()
 {
     return(WeatherRepo.GetAll());
 }
Example #7
0
 public IActionResult Delete()
 {
     WeatherRepo.EraseContents();
     return(Ok());
 }
Example #8
0
 public WeatherForecastController(ILogger <WeatherForecastController> logger)
 {
     _logger = logger;
     _repo   = new WeatherRepo();
 }
Example #9
0
 public WeatherDataTests()
 {
     //test
     _repo = new WeatherRepo();
 }