Пример #1
0
        public async Task <IActionResult> Calendar(long id, CancellationToken cancellationToken)
        {
            var matches = await _appDb.MatchRepository.GetMatchCalendarAsync(_siteContext.MatchPlanTournamentId, id, null, null, cancellationToken);

            if (matches.Count != 1)
            {
                return(NoContent());
            }

            try
            {
                var calendar = new TournamentManager.Match.Calendar
                {
                    WithAlarms = true,
                    Summary    = _localizer["Volleyball Match"],
                    DescriptionGoogleMapsFormat = _localizer["Venue in Google Maps: https://maps.google.com?q={0},{1}"],
                    DescriptionOpponentsFormat  = _localizer["Match '{0}' : '{1}'"],
                    DescriptionFooter           = "\n" + _siteContext.Name + "\n" + _siteContext.HomepageUrl
                };
                var stream = new MemoryStream();
                // RFC5545 sect. 3.4.1: iCal default charset is UTF8.
                // Important: no Byte Order Mark (BOM) for Android, Google, Apple
                var encoding = new UTF8Encoding(false);
                matches.ForEach(m =>
                {
                    // convert to local time
                    m.PlannedStart = _timeZoneConverter.ToZonedTime(m.PlannedStart).DateTimeOffset.DateTime;
                    m.PlannedEnd   = _timeZoneConverter.ToZonedTime(m.PlannedEnd).DateTimeOffset.DateTime;
                });
                calendar.CreateEvents(matches).Serialize(stream, encoding);
                stream.Seek(0, SeekOrigin.Begin);
                return(File(stream, $"text/calendar; charset={encoding.HeaderName}", $"Match_{matches[0].PlannedStart?.ToString("yyyy-MM-dd") ?? string.Empty}_{Guid.NewGuid():N}.ics"));
            }
            catch (Exception e)
            {
                _logger.LogCritical(e, $"Error creating {nameof(Calendar)} for user ID '{0}'", GetCurrentUserId());
                return(NoContent());
            }
        }
Пример #2
0
        public EditFixtureViewModel(PlannedMatchRow plannedMatch, Axuno.Tools.DateAndTime.TimeZoneConverter timeZoneConverter)
        {
            PlannedMatch      = plannedMatch;
            TimeZoneConverter = timeZoneConverter;

            // Set form fields
            if (plannedMatch != null)
            {
                Id      = PlannedMatch.Id;
                VenueId = PlannedMatch.VenueId;
                // set date and time for the current time zone
                var currentDate =
                    TimeZoneConverter.ToZonedTime(PlannedMatch.PlannedStart);
                MatchDate = currentDate?.DateTimeOffset.Date;
                MatchTime = currentDate?.DateTimeOffset.TimeOfDay;

                // mark a list item as selected
                VenueNotSpecifiedKey = null;  // "not specified" will not show in the list
                VenueId = PlannedMatch.VenueId ?? VenueNotSpecifiedKey ?? 0;
            }
        }