Пример #1
0
        public override async Task <CreateWeatherForecastResponse> CreateWeatherForecast(CreateWeatherForecastRequest request, ServerCallContext context)
        {
            var locationId = request.Location.Id;
            var date       = request.Date;

            if (locationId <= 0)
            {
                const string error = "Location id must be a positive integer";
                throw new RpcException(new Status(StatusCode.InvalidArgument, error));
            }

            if (string.IsNullOrEmpty(date))
            {
                const string error = "date cannot be null or empty.";
                throw new RpcException(new Status(StatusCode.InvalidArgument, error));
            }

            var locationStoredData = _mapper.Map <Location, LocationStoredData>(request.Location);

            var forecast = await _repository.CreateWeatherForecast(locationStoredData, date, request.Summary, request.Temperature);

            var result = _mapper.Map <WeatherForecastStoredData, WeatherForecast>(forecast);

            return(new CreateWeatherForecastResponse
            {
                WeatherForecast = result
            });
        }