Beispiel #1
0
        public async Task <IActionResult> GetWeatherReport([FromRoute] string date)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            List <WeatherReport> forecast = new List <WeatherReport>();
            DateTime             reportDate;
            bool isDate;

            WeatherHelper.CheckInputDate(date, out reportDate, out isDate);
            if (!isDate)
            {
                return(BadRequest("Enter valid date in YYYYMMDD format"));
            }
            while (forecast.Count < 5)
            {
                reportDate = await ProcessForecast(forecast, reportDate);
            }
            return(Ok(forecast));
        }
        public IActionResult Post([FromBody] WeatherReport report)
        {
            if (report == null)
            {
                return(BadRequest());
            }
            DateTime reportDate;
            bool     isDate;

            WeatherHelper.CheckInputDate(report.DATE, out reportDate, out isDate);
            if (!isDate)
            {
                return(BadRequest("Enter valid date in YYYYMMDD format"));
            }

            if (db.dailyWeather.Any(x => x.DATE == report.DATE))
            {
                return(BadRequest("Already Exists"));
            }
            db.dailyWeather.Add(report);

            db.SaveChanges();
            return(CreatedAtAction("Get", new { date = report.DATE }, new { DATE = report.DATE }));
        }