예제 #1
0
        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));
        }
예제 #2
0
        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());
        }
예제 #3
0
        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();
        }
예제 #4
0
        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();
            }
        }