コード例 #1
0
        public async Task <IActionResult> ViewMyChannels(ViewMyChannelsAddressModel model)
        {
            var appid    = _tokenManager.ValidateAccessToken(model.AccessToken);
            var appLocal = await _dbContext.Apps.SingleOrDefaultAsync(t => t.Id == appid);

            if (appLocal == null)
            {
                appLocal = new StargateApp
                {
                    Id       = appid,
                    Channels = new List <Channel>()
                };
                _dbContext.Apps.Add(appLocal);
                await _dbContext.SaveChangesAsync();
            }
            var channels = await _dbContext
                           .Channels
                           .Where(t => t.AppId == appid)
                           .ToListAsync();

            var viewModel = new ViewMyChannelsViewModel
            {
                AppId    = appLocal.Id,
                Channels = channels
                           .Select(t => new ChannelDetail(t,
                                                          _connectedCountService.GetConnectedCount(t.Id),
                                                          _lastAccessService.GetLastAccessTime(t.Id)))
                           .ToList(),
                Code    = ErrorType.Success,
                Message = "Successfully get your channels!"
            };

            return(Json(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> ViewMyChannels(ViewMyChannelsAddressModel model)
        {
            var appid    = _tokenManager.ValidateAccessToken(model.AccessToken);
            var appLocal = await _dbContext.Apps.SingleOrDefaultAsync(t => t.Id == appid);

            if (appLocal == null)
            {
                appLocal = new StargateApp
                {
                    Id = appid
                };
                await _dbContext.Apps.AddAsync(appLocal);

                await _dbContext.SaveChangesAsync();
            }
            var channels = _stargateMemory
                           .GetChannelsUnderApp(appid);
            var viewModel = new ViewMyChannelsViewModel
            {
                AppId    = appid,
                Channels = channels,
                Code     = ErrorType.Success,
                Message  = "Successfully get your channels!"
            };

            return(Ok(viewModel));
        }
コード例 #3
0
        public async Task <IActionResult> ViewMyChannels(ViewMyChannelsAddressModel model)
        {
            var app = await ApiService.ValidateAccessTokenAsync(model.AccessToken);

            var appLocal = await _dbContext.Apps.SingleOrDefaultAsync(t => t.Id == app.AppId);

            if (appLocal == null)
            {
                appLocal = new StargateApp
                {
                    Id       = app.AppId,
                    Channels = new List <Channel>()
                };
                _dbContext.Apps.Add(appLocal);
                await _dbContext.SaveChangesAsync();
            }
            var channels = await _dbContext
                           .Channels
                           .Where(t => t.AppId == app.AppId)
                           .ToListAsync();

            var viewModel = new ViewMyChannelsViewModel
            {
                AppId   = appLocal.Id,
                Channel = channels,
                code    = ErrorType.Success,
                message = "Successfully get your channels!"
            };

            return(Json(viewModel));
        }
コード例 #4
0
        public async Task <IActionResult> ViewMyChannels(ViewMyChannelsAddressModel model)
        {
            var token = await _dbContext.AccessTokens.Include(t => t.ApplyApp).SingleOrDefaultAsync(t => t.Value == model.AccessToken);

            if (token == null || token.ApplyApp == null)
            {
                return(this.Protocol(ErrorType.Unauthorized, "Invalid accesstoken!"));
            }
            var channels = await _dbContext
                           .Channels
                           .Where(t => t.AppId == token.ApplyAppId)
                           .ToListAsync();

            return(this.Protocol(new ViewMyChannelsViewModel
            {
                AppId = token.ApplyAppId,
                Channel = channels,
                Code = ErrorType.Success,
                Message = "Successfully get your channels!"
            }));
        }