예제 #1
0
        public async Task <IActionResult> Save(AdminInputModel input)
        {
            var liveShowDetails = await _liveShowDetails.LoadAsync() ?? new LiveShowDetails();

            if (!ModelState.IsValid)
            {
                // Model validation error, just return and let the error render
                var viewModel = new AdminViewModel();
                UpdateAdminViewModel(viewModel, liveShowDetails);

                return(View(nameof(Index), viewModel));
            }

            if (!string.IsNullOrEmpty(input.LiveShowEmbedUrl) && input.LiveShowEmbedUrl.StartsWith("http://"))
            {
                input.LiveShowEmbedUrl = "https://" + input.LiveShowEmbedUrl.Substring("http://".Length);
            }

            TrackShowEvent(input, liveShowDetails);

            liveShowDetails.LiveShowEmbedUrl = input.LiveShowEmbedUrl;
            liveShowDetails.LiveShowHtml     = input.LiveShowHtml;
            liveShowDetails.NextShowDateUtc  = input.NextShowDateAest?.ConvertFromPtcToUtc();
            liveShowDetails.AdminMessage     = input.AdminMessage;

            await _liveShowDetails.SaveAsync(liveShowDetails);

            TempData[nameof(AdminViewModel.SuccessMessage)] = "Live show details saved successfully!";

            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        public async Task <IActionResult> OnPostAsync(Input input)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Unauthorized());
            }
            var liveShowDetails = await _liveShowDetails.LoadAsync() ?? new LiveShowDetails();

            if (!ModelState.IsValid)
            {
                // Model validation error, just return and let the error render
                UpdateModelProperties(liveShowDetails);

                return(Page());
            }

            if (!string.IsNullOrEmpty(input.LiveShowEmbedUrl) && input.LiveShowEmbedUrl.StartsWith("http://"))
            {
                input.LiveShowEmbedUrl = "https://" + input.LiveShowEmbedUrl.Substring("http://".Length);
            }

            TrackShowEvent(input, liveShowDetails);

            _mapper.Map(input, liveShowDetails);
            liveShowDetails.NextShowDateUtc = input.NextShowDatePst?.ConvertFromCetToUtc();

            await _liveShowDetails.SaveAsync(liveShowDetails);

            SuccessMessage = "Live show details saved successfully!";

            return(RedirectToPage());
        }
예제 #3
0
        public async Task <IActionResult> Save(AdminInputModel input)
        {
            var liveShowDetails = await _liveShowDetails.LoadAsync() ?? new LiveShowDetails();

            if (!ModelState.IsValid)
            {
                // Model validation error, just return and let the error render
                var viewModel = new AdminViewModel();
                UpdateAdminViewModel(viewModel, liveShowDetails);

                return(View(nameof(Index), viewModel));
            }

            if (!string.IsNullOrEmpty(input.LiveShowEmbedUrl))
            {
                // Convert live show url to HTTPS if need be
                if (input.LiveShowEmbedUrl.StartsWith("http://"))
                {
                    input.LiveShowEmbedUrl = "https://" + input.LiveShowEmbedUrl.Substring("http://".Length);
                }

                // Convert watch URL to embed URL
                if (input.LiveShowEmbedUrl.StartsWith("https://www.youtube.com/watch?v=", StringComparison.OrdinalIgnoreCase))
                {
                    var queryIndex   = input.LiveShowEmbedUrl.LastIndexOf("?v=", StringComparison.OrdinalIgnoreCase);
                    var showIdLength = input.LiveShowEmbedUrl.IndexOf('&', queryIndex) - 3 - queryIndex;
                    var showId       = showIdLength > 0 ? input.LiveShowEmbedUrl.Substring(queryIndex + 3, showIdLength) : input.LiveShowEmbedUrl.Substring(queryIndex + 3);
                    input.LiveShowEmbedUrl = $"https://www.youtube.com/embed/{showId}";
                }
            }

            TrackShowEvent(input, liveShowDetails);

            _mapper.Map(input, liveShowDetails);
            liveShowDetails.NextShowDateUtc = input.NextShowDatePst?.ConvertFromPtcToUtc();

            await _liveShowDetails.SaveAsync(liveShowDetails);

            TempData[nameof(AdminViewModel.SuccessMessage)] = "Live show details saved successfully!";

            return(RedirectToAction(nameof(Index)));
        }