Пример #1
0
        // ReSharper disable once UnusedMember.Global
        public IActionResult OnGet()
        {
            if (string.IsNullOrWhiteSpace(Request.QueryString.Value))
            {
                throw new Exception("Неверный запрос на получение календаря.");
            }

            var encodedModel = Request.QueryString.Value.Substring(1);

            SettingsModel = CalendarSettingsModel.Deserialize(encodedModel);
            var schedule = GetSchedule(SettingsModel);

            var events = schedule.Matrix
                         .Cast <CalendarDayModel>()
                         .SelectMany(x => x.Events)
                         .ToArray();

            var hiddenLessonIds = events.Where(x => x.IsHiddenByUser)
                                  .Select(x => x.Color.ToString() + x.Date.ToString())
                                  .Distinct()
                                  .ToArray();

            var filteredEvents = events
                                 .DistinctBy(x => x.Color.ToString() + x.Date.ToString())
                                 .Where(x => !hiddenLessonIds.Contains(x.Color.ToString() + x.Date.ToString()))
                                 .ToArray();

            var resultIcal = GetIcalContent(filteredEvents);

            return(Content(resultIcal, "text/plain", Encoding.UTF8));
        }
Пример #2
0
        /// <summary>Обработчик запросов пользоателя.</summary>
        // ReSharper disable once UnusedMember.Global
        public void OnGet()
        {
            var encodedModel = Request.QueryString.Value == string.Empty
                ? string.Empty
                : Request.QueryString.Value.Substring(1);

            encodedModel = encodedModel.Replace("g=", ""); // поддержка старого формата ссылок.
            if (encodedModel.Length < 3 && Request.Cookies.TryGetValue("link", out var link))
            {
                Response.Redirect(link);
            }

            SettingsModel = CalendarSettingsModel.Deserialize(encodedModel); //todo: shadow legend toggler
            CalendarModel = GetSchedule(SettingsModel);

            if (SettingsModel.Items.Any())
            {
                Response.Cookies.Append("link", Request.GetDisplayUrl(), new CookieOptions {
                    MaxAge = TimeSpan.FromDays(365)
                });
            }
            else
            {
                Response.Cookies.Delete("link");
            }
        }