public Task <List <Event> > GetEventsAsync(string sessionId, string channelId, CancellationToken ct = default(CancellationToken))
        {
            return(new TaskFactory().StartNew(() =>
            {
                var programsTask = new TaskFactory().StartNew(() =>
                {
                    var startTime = DateTime.UtcNow.Date.AddDays(-1);
                    var endTime = DateTime.UtcNow.Date.AddDays(2).AddMilliseconds(-1);

                    return _programsManager.GetByChannelId(channelId).Where(c =>
                                                                            c.StartTime.Between(startTime, endTime) ||
                                                                            (c.StartTime < startTime && c.EndTime.Between(startTime, endTime)));
                }, ct);

                var channelTask = new TaskFactory().StartNew(() => _channelsManager.GetById(channelId), ct);

                var subscribedTask = new TaskFactory().StartNew(() => _channelsManager.GetSubscribedChannelsBySessionId(sessionId), ct);

                var isSubscribed = subscribedTask.Result.Select(c => c.Id).Contains(channelId);

                return programsTask.Result.Select(c => new Event
                {
                    ChannelName = channelTask.Result.Name,
                    IsSubscribed = isSubscribed,
                    ProgramTitle = c.Title,
                    ProgramDescription = c.Description,
                    ProgramStartTime = c.StartTime,
                    ProgramEndTime = c.EndTime
                }).ToList();
            }, ct));
        }
Exemple #2
0
        public HttpResponseMessage GetSubscribedChannels([FromHeader("session-id")] string sessionId)
        {
            if (string.IsNullOrEmpty(sessionId))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid Input"));
            }

            List <Channel> channels = _channelsManager.GetSubscribedChannelsBySessionId(sessionId).ToList();

            if (!channels.Any())
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, channels));
        }