Example #1
0
        public ParityOfTheWeekViewModel GenerateParityOfTheWeek()
        {
            var dateTimeParam = DateTime.Now;

            var parityOfTheWeekModel = _parityOfTheWeekService.GenerateDataOfTheWeek(dateTimeParam);

            var resultViewModel = _parityOfTheWeekService.PrepareParityOfTheWeekViewModel(parityOfTheWeekModel);

            return(resultViewModel);
        }
Example #2
0
        public IActionResult GenerateParityOfTheWeek([FromBody] ParityOfTheWeekRequestModel requestModel)
        {
            try
            {
                if (requestModel == null)
                {
                    _logger.LogInformation("Request model is null");
                    return(BadRequest("Запрос не содержит данных."));
                }

                _logger.LogInformation("Request: ", requestModel.SelectedDateTime);

                var userAccountRequestData = new UserAccountRequestDataParityOfTheWeek
                {
                    TimeZoneId = TimeZoneInfo.Local.Id //"Russian Standard Time"
                };

                var dateTimeOffsetRequestUtc = requestModel.SelectedDateTime;

                var dateTimeOffsetRequestUser = TimeZoneInfo.ConvertTime(dateTimeOffsetRequestUtc,
                                                                         TimeZoneInfo.FindSystemTimeZoneById(userAccountRequestData.TimeZoneId));

                // генерируем модель с данными о заданном дне.
                var parityOfTheWeekModel = _parityOfTheWeekService.GenerateDataOfTheWeek(dateTimeOffsetRequestUser);

                // подготавливаем модель для отображения (ViewModel)
                var resultViewModel = _parityOfTheWeekService.PrepareViewModel(parityOfTheWeekModel);

                _logger.LogInformation("Response: ", resultViewModel.ToString());
                return(Ok(resultViewModel));
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception: ", ex);
                return(BadRequest(ex));
            }
        }