/// <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!")); }
/// <summary> /// Updates the LiveStreaming object in Mongo /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <SystemResponse <LiveSermons> > UpdateLiveSermons(LiveSermons request) { if (!IsValidObjectId(request.Id)) { return(new SystemResponse <LiveSermons>(true, string.Format(SystemMessages.UnableToFindPropertyForId, "Live Sermon", request.Id))); } var document = await _livestreamCollection.FindOneAndUpdateAsync( Builders <LiveSermons> .Filter .Eq(l => l.Id, request.Id), Builders <LiveSermons> .Update .Set(l => l.LastUpdated, DateTime.UtcNow) .Set(l => l.IsLive, request.IsLive) .Set(l => l.SpecialEventTimes, request.SpecialEventTimes) .Set(l => l.NextLive, request.NextLive) .Set(l => l.ExpirationTime, request.ExpirationTime.ToUniversalTime()) ); if (document == null || document == default(LiveSermons)) { return(new SystemResponse <LiveSermons>(true, string.Format(SystemMessages.UnableToUpdatePropertyForId, "Live Sermon", request.Id))); } // get the object again because it's not updated in memory var updatedDocument = await _livestreamCollection.FindAsync( Builders <LiveSermons> .Filter.Eq(l => l.Id, request.Id)); var response = updatedDocument.FirstOrDefault(); if (response == null || response == default(LiveSermons)) { return(new SystemResponse <LiveSermons>(true, string.Format(SystemMessages.UnableToUpdatePropertyForId, "Live Sermon", request.Id))); } return(new SystemResponse <LiveSermons>(response, "Success!")); }