public async Task <IActionResult> Summary(string location, DateTime startDate, DateTime endDate, string ianaTimeZone) { var dateTimeZone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(ianaTimeZone); if (dateTimeZone == null) { return(BadRequest($"Unknown IANA time zone: {ianaTimeZone}")); } var localStartDate = new LocalDateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0); var localEndDate = new LocalDateTime(endDate.Year, endDate.Month, endDate.Day, 0, 0); if (localStartDate > localEndDate) { return(BadRequest("Given startDate must be less than or equal to given endDate")); } var result = new List <TemperatureSummaryEntity>(); for (var requestStartDate = localStartDate; requestStartDate <= localEndDate; requestStartDate = requestStartDate.PlusDays(1)) { var temperatureRecords = await GetTemperatureEntitiesForDate(location, requestStartDate.InZoneLeniently(dateTimeZone)); var temperatureSummaryEntity = new TemperatureSummaryEntity(location, requestStartDate, temperatureRecords); result.Add(temperatureSummaryEntity); } return(base.Ok(Mapper.Map <List <TemperatureSummaryViewModel> >(result, opts => { opts.Items["DateTimeZone"] = dateTimeZone; }))); }
private object GetLocalDateFromContextOrRowKey(TemperatureSummaryEntity source, TemperatureSummaryViewModel destination, string destMember, ResolutionContext context) { context.Items.TryGetValue("LocalDate", out var localDate); if (localDate is LocalDate) { return(((LocalDate)localDate).ToString("yyyy-MM-dd", null)); } context.Items.TryGetValue("DateTimeZone", out var dateTimeZone); if (dateTimeZone is DateTimeZone && !string.IsNullOrWhiteSpace(source.RowKey)) { return(ReverseTicks.ToZonedDateTime(source.RowKey, (DateTimeZone)dateTimeZone).ToString("yyyy-MM-dd", null)); } return(null); }