コード例 #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();
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of entries repository.
 /// </summary>
 public EntriesRepository(int userId)
 {
     _userId  = userId;
     _context = new CalorieTrackerContext();
 }
コード例 #3
0
 public AccountRepository(int?userId)
 {
     _context = new CalorieTrackerContext();
     _userId  = userId;
 }