public async Task <ValidationSession> TryGetValidationSessionByIdAsync(int id) { await ApiAuthentication.EnsureAuthenticatedAsync(); int userId = await ApiAuthentication.GetUserIdAsync(); User user = await Context.Users.SingleAsync(x => x.Id == userId); return(await Context.ValidationSessions.SingleOrDefaultAsync(x => x.User == user && x.Id == id)); }
public async Task <IEnumerable <ValidationSession> > GetValidationSessionsAsync() { await ApiAuthentication.EnsureAuthenticatedAsync(); int userId = await ApiAuthentication.GetUserIdAsync(); User user = await Context.Users.SingleAsync(x => x.Id == userId); return(await Context.ValidationSessions.Where(x => x.User == user).ToListAsync()); }
public async Task AddValidationSessionAsync(ValidationSession validationSession) { await ApiAuthentication.EnsureAuthenticatedAsync(); int userId = await ApiAuthentication.GetUserIdAsync(); User user = await Context.Users.SingleAsync(x => x.Id == userId); validationSession.User = user; await Context.ValidationSessions.AddAsync(validationSession); await SaveChangesAsync(); }
public async Task EnsureUserExistsAsync() { await ApiAuthentication.EnsureAuthenticatedAsync(); int userId = await ApiAuthentication.GetUserIdAsync(); User user = await Context.Users.SingleOrDefaultAsync(x => x.Id == userId); if (user == null) { user = new User { Id = userId, Name = await ApiAuthentication.GetUserNameAsync(), }; await Context.Users.AddAsync(user); await SaveChangesAsync(); } }