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)); }
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)); }
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)); }
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(Protocal(ErrorType.Unauthorized, "Invalid accesstoken!")); } var channels = await _dbContext .Channels .Where(t => t.AppId == token.ApplyAppId) .ToListAsync(); var viewModel = new ViewMyChannelsViewModel { AppId = token.ApplyAppId, Channel = channels, code = ErrorType.Success, message = "Successfully get your channels!" }; return(Json(viewModel)); }