Example #1
0
        public async Task <ActionResult <WeatherForecastApiModel> > Put(int id, [FromBody] WeatherForecastApiModel input,
                                                                        CancellationToken ct = default)
        {
            try
            {
                if (input == null)
                {
                    return(BadRequest());
                }
                if (await _BlazorSupervisor.GetAlbumByIdAsync(id, ct) == null)
                {
                    return(NotFound());
                }

                var errors = JsonConvert.SerializeObject(ModelState.Values
                                                         .SelectMany(state => state.Errors)
                                                         .Select(error => error.ErrorMessage));
                Debug.WriteLine(errors);

                if (await _BlazorSupervisor.UpdateWeatherForecastAsync(input, ct))
                {
                    return(Ok(input));
                }

                return(StatusCode(500));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Example #2
0
        public async Task <WeatherForecastApiModel> AddWeatherForecastAsync(WeatherForecastApiModel newWeatherForecastApiModel,
                                                                            CancellationToken ct = default)
        {
            var WeatherForecast = newWeatherForecastApiModel.Convert();

            WeatherForecast = await _weatherForecastRepository.AddAsync(WeatherForecast, ct);

            newWeatherForecastApiModel.WeatherForecastId = WeatherForecast.WeatherForecastId;
            return(newWeatherForecastApiModel);
        }
Example #3
0
        public async Task <bool> UpdateWeatherForecastAsync(WeatherForecastApiModel WeatherForecastApiModel,
                                                            CancellationToken ct = default)
        {
            var WeatherForecast = await _weatherForecastRepository.GetByIdAsync(WeatherForecastApiModel.WeatherForecastId, ct);

            if (WeatherForecast is null)
            {
                return(false);
            }
            WeatherForecast.WeatherForecastId = WeatherForecastApiModel.WeatherForecastId;

            return(await _weatherForecastRepository.UpdateAsync(WeatherForecast, ct));
        }
Example #4
0
        public async Task <ActionResult <WeatherForecastApiModel> > Post([FromBody] WeatherForecastApiModel input,
                                                                         CancellationToken ct = default)
        {
            try
            {
                if (input == null)
                {
                    return(BadRequest());
                }

                return(StatusCode(201, await _BlazorSupervisor.AddWeatherForecastAsync(input, ct)));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }