/// <summary> /// Execute Query[T].Where(query).Single(); /// </summary> public T Single <T>(Query query = null, string collectionName = null) { using (var db = new LiteRepository(_configService.ConnectionString)) { return(db.Single <T>(query, collectionName)); } }
/// <summary> /// Execute Query[T].Where(query).Single(); /// </summary> public T Single <T>(Expression <Func <T, bool> > predicate, string collectionName = null) { using (var db = new LiteRepository(_configService.ConnectionString)) { return(db.Single <T>(predicate, collectionName)); } }
public Result <T> Single(Expression <Func <T, bool> > predicate, string collectionName = null) { var result = new Result <T>(); try { result.ResultObject = _liteRepository.Single(predicate, collectionName); } catch (Exception ex) { result.ResultCode = (int)ResultStatusCode.InternalServerError; result.ResultMessage = "Hata Oluştu => " + ex; result.ResultInnerMessage = "Hata Oluştu => " + ex.InnerException; result.ResultStatus = false; } return(result); }
private static async void NextQuestion(int currentSessionId, LiteRepository db, IHubCallerClients clients, ILogger log) { log.LogWarning("Showing Question"); var currentSession = db.SingleById <GameSession>(currentSessionId); var qi = currentSession.CurrentQuestionIndex; var question = currentSession.Questionnaire.Questions[qi]; var answer = db.Single <Answer>(ans => ans.Question.Id == question.Id); var endTime = DateTime.Now.Add(question.Time).ToUniversalTime(); await Task.WhenAll( clients.Group("Players" + currentSession.JoinCode).SendAsync("CurrentAnswer", answer, endTime), clients.Group("Server" + currentSession.JoinCode).SendAsync("CurrentQuestion", question, endTime), Task.Delay(question.Time)); currentSession.CurrentQuestionIndex++; db.Update(currentSession); LeaderBoards(currentSessionId, db, clients, log); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); }); var repository = new LiteRepository(Configuration.GetConnectionString("MainDatabase")); DbInitializer testData = new DbInitializer(repository); testData.SeedDatabase(); Console.WriteLine(repository.Single <GameSession>(s => s.JoinCode == "abcde").Id); services.AddSingleton(repository); //services.AddCors(options => options.AddPolicy("CorsPolicy", // builder => // { // builder.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin() // .AllowCredentials(); // })); services.AddSignalR(o => o.EnableDetailedErrors = true); }
public async Task <Player> JoinGameSession(string userName, string joinCode) { GameSession session; try { session = _db.Single <GameSession>(gs => gs.JoinCode == joinCode); } catch (InvalidOperationException) { return(null); } var id = _db.Insert(new Player { Name = userName, GameSession = session }); await Groups.AddToGroupAsync(Context.ConnectionId, "Players" + joinCode); await Clients.Groups("Players" + session.JoinCode, "Server" + session.JoinCode) .SendAsync("PlayerCountUpdated", _db.Fetch <Player>().Count(p => p.GameSession.Id == session.Id)); return(_db.SingleById <Player>(id)); }
public T Single(Expression <Func <T, bool> > predicate) { return(_liteRepository.Single(predicate)); }