Beispiel #1
0
        public UsersRepository(int?userId)
        {
            _context = new CalorieTrackerContext();
            _userId  = userId;
            var currentUser = _context.Users.SingleOrDefault(u => u.Id == userId);

            if (currentUser == null || !currentUser.IsAdmin)
            {
                // current user was deleted from the database or does not have sufficient permissions
                throw new UnauthorizedAccessException();
            }
        }
 /// <summary>
 /// Initializes a new instance of entries repository.
 /// </summary>
 public EntriesRepository(int userId)
 {
     _userId  = userId;
     _context = new CalorieTrackerContext();
 }
Beispiel #3
0
 public AccountRepository(int?userId)
 {
     _context = new CalorieTrackerContext();
     _userId  = userId;
 }