Esempio n. 1
0
        private Notification ConvertToOperationsServiceMessageDto(ServiceMessageDto serviceMessageDto)
        {
            var now = _dateTimeProvider.GetNowUtc();

            var      localStartDateTime = _dateTimeProvider.ConvertUtcToUk(serviceMessageDto.StartDateTimeUtc);
            DateTime?localEnDateTime    = serviceMessageDto.EndDateTimeUtc.HasValue ?
                                          _dateTimeProvider.ConvertUtcToUk(serviceMessageDto.EndDateTimeUtc
                                                                           .GetValueOrDefault()) : (DateTime?)null;

            return(new Notification()
            {
                Id = serviceMessageDto.Id,
                Headline = serviceMessageDto.Headline,
                Message = serviceMessageDto.Message,
                StartDate = localStartDateTime,
                EndDate = localEnDateTime,
                StartTime = localStartDateTime,
                EndTime = localEnDateTime,
                IsActive = serviceMessageDto.StartDateTimeUtc <= now && (!serviceMessageDto.EndDateTimeUtc.HasValue || serviceMessageDto.EndDateTimeUtc >= now)
            });
        }
Esempio n. 2
0
        public async Task <bool> SaveNotificationAsync(CancellationToken cancellationToken, Notification model)
        {
            var startDateTime = model.StartDate.Date.Add(model.StartTime.TimeOfDay);
            var endDateTime   = model.EndDate.GetValueOrDefault().Date.Add(model.EndTime.GetValueOrDefault().TimeOfDay);

            var data = new ServiceMessageDto
            {
                Headline         = model.Headline,
                Message          = model.Message,
                StartDateTimeUtc = _dateTimeProvider.ConvertUkToUtc(startDateTime),
                EndDateTimeUtc   = endDateTime == DateTime.MinValue ? (DateTime?)null : _dateTimeProvider.ConvertUkToUtc(endDateTime),
                Id        = model.Id,
                IsEnabled = true,
            };

            var response = await _httpClientService.SendDataAsyncRawResponse($"{_baseUrl}/api/service-message", data, cancellationToken);

            if (!response.IsSuccess)
            {
                _logger.LogError($"Web Operations. Error occured saving notification");
            }

            return(response.IsSuccess);
        }