コード例 #1
0
        public IEnumerable <User> GetAll()
        {
            using (var db = new SqlConnection(ConnectionString))
            {
                var users = db.Query <User>("select username, password, id from users").ToList();

                var targets = new TargetRepository().GetAll();

                foreach (var user in users)
                {
                    var matchingTargets = targets.Where(target => target.UserId == user.Id).ToList();
                    user.Targets = matchingTargets;
                }

                //var targets = new TargetRepository().GetAll().GroupBy(target => target.UserId);

                //foreach (var user in users)
                //{
                //    var matchingTargets = targets.FirstOrDefault(grouping => grouping.Key == user.Id);

                //    user.Targets = matchingTargets?.ToList();
                //}

                return(users);
            }
        }
コード例 #2
0
 public UserRepository(TargetRepository targetRepository)
 {
     _targetRepository = targetRepository;
 }
コード例 #3
0
 public UserRepository(TargetRepository targetRepository, IOptions <DbConfiguration> dbConfig)
 {
     _targetRepository = targetRepository;
     _connectionString = dbConfig.Value.ConnectionString;
 }