Ejemplo n.º 1
0
        /// <summary>
        /// Updates the LiveSermon to be a special event
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <SystemResponse <LiveStreamingResponse> > UpdateLiveForSpecialEvents(LiveSermonsSpecialEventUpdateRequest request)
        {
            // validate the request
            var validationResponse = request.ValidateRequest();

            if (validationResponse.HasErrors)
            {
                return(new SystemResponse <LiveStreamingResponse>(true, validationResponse.ErrorMessage));
            }

            // Update this object for the requested fields
            var updated = new LiveSermons
            {
                ExpirationTime    = request.SpecialEventTimes.End ?? new DateTime(1990, 01, 01, 11, 20, 0, 0),
                IsLive            = true,
                LastUpdated       = DateTime.UtcNow,
                SpecialEventTimes = request.SpecialEventTimes
            };

            var updateLiveSermonsResponse = await _sermonsRepository.UpdateLiveSermons(updated);

            if (updateLiveSermonsResponse.HasErrors)
            {
                return(new SystemResponse <LiveStreamingResponse>(true, updateLiveSermonsResponse.ErrorMessage));
            }

            var liveResponse = updateLiveSermonsResponse.Result;

            var response = new LiveStreamingResponse
            {
                ExpirationTime    = liveResponse.ExpirationTime.ToUniversalTime(),
                IsLive            = liveResponse.IsLive,
                IsSpecialEvent    = true,
                SpecialEventTimes = request.SpecialEventTimes
            };

            // we are updating this so we should watch for when it expires, when it does we will need to update Mongo
            DetermineIfStreamIsInactive();

            return(new SystemResponse <LiveStreamingResponse>(response, "Success!"));
        }
        public async Task <ActionResult <LiveStreamingResponse> > UpdateLiveForSpecialEvents([FromBody] LiveSermonsSpecialEventUpdateRequest request)
        {
            var response = await _sermonsService.UpdateLiveForSpecialEvents(request);

            if (response.HasErrors)
            {
                return(StatusCode(400));
            }

            return(response.Result);
        }