public User GetUser(Guid userId)
        {
            var candyRepo = new CandyRepository();
            var offerRepo = new OfferRepository();

            using (var db = new SqlConnection(_connectionString))
            {
                var sql        = @"SELECT *
                            FROM [User]
                            WHERE [Id] = @userId";
                var parameters = new { userId };
                var user       = db.QueryFirst <User>(sql, parameters);
                var candies    = candyRepo.FetchUsersCandyList(user);
                user.CandyOwned = candies;
                var favoriteCandyName = candyRepo.FetchFavoriteCandyName(user);
                user.FavoriteTypeOfCandyName = favoriteCandyName;
                user.OffersIn  = new List <UsersOffersIn>();
                user.OffersOut = new List <UsersOffersOut>();
                foreach (OwnedCandy ownedCandy in candies)
                {
                    var offersOut = offerRepo.FetchUsersOffersOut(ownedCandy.UserCandyId);
                    user.OffersOut.AddRange(offersOut);
                    var offersIn = offerRepo.FetchUsersOffersIn(ownedCandy.UserCandyId);
                    user.OffersIn.AddRange(offersIn);
                }
                return(user);
            }
        }
 public IEnumerable <User> GetAllUsers()
 {
     using (var db = new SqlConnection(_connectionString))
     {
         var candyRepo = new CandyRepository();
         var offerRepo = new OfferRepository();
         var users     = db.Query <User>
                         (
             @"SELECT * 
               FROM [User]"
                         ).ToList();
         foreach (User user in users)
         {
             var candies = candyRepo.FetchUsersCandyList(user);
             user.CandyOwned = candies;
             var favoriteCandyName = candyRepo.FetchFavoriteCandyName(user);
             user.FavoriteTypeOfCandyName = favoriteCandyName;
             user.OffersIn  = new List <UsersOffersIn>();
             user.OffersOut = new List <UsersOffersOut>();
             foreach (OwnedCandy ownedCandy in candies)
             {
                 var offersOut = offerRepo.FetchUsersOffersOut(ownedCandy.UserCandyId);
                 user.OffersOut.AddRange(offersOut);
                 var offersIn = offerRepo.FetchUsersOffersIn(ownedCandy.UserCandyId);
                 user.OffersIn.AddRange(offersIn);
             }
         }
         return(users);
     }
 }
        public User GetUserByEmailAndPassword(string email, string password)
        {
            var candyRepo = new CandyRepository();
            var offerRepo = new OfferRepository();

            using (var db = new SqlConnection(_connectionString))
            {
                var sql          = @"SELECT *
                            FROM [User]
                            WHERE ([Password] = @password AND [Email] = @email)";
                var parameters   = new { email, password };
                var userToReturn = db.QueryFirst <User>(sql, parameters);
                var candies      = candyRepo.FetchUsersCandyList(userToReturn);
                userToReturn.CandyOwned = candies;
                var favoriteCandyName = candyRepo.FetchFavoriteCandyName(userToReturn);
                userToReturn.FavoriteTypeOfCandyName = favoriteCandyName;
                userToReturn.OffersIn  = new List <UsersOffersIn>();
                userToReturn.OffersOut = new List <UsersOffersOut>();
                foreach (OwnedCandy ownedCandy in candies)
                {
                    var offersOut = offerRepo.FetchUsersOffersOut(ownedCandy.UserCandyId);
                    userToReturn.OffersOut.AddRange(offersOut);
                    var offersIn = offerRepo.FetchUsersOffersIn(ownedCandy.UserCandyId);
                    userToReturn.OffersIn.AddRange(offersIn);
                }
                return(userToReturn);
            }
        }
        public User GetUser(Guid userId)
        {
            var candyRepo = new CandyRepository();

            using (var db = new SqlConnection(_connectionString))
            {
                var sql        = @"SELECT *
                            FROM [User]
                            WHERE [Id] = @userId";
                var parameters = new { userId };
                var user       = db.QueryFirst <User>(sql, parameters);
                var candies    = candyRepo.FetchUsersCandyList(user);
                user.CandyOwned = candies;
                var favoriteCandyName = candyRepo.FetchFavoriteCandyName(user);
                user.FavoriteTypeOfCandyName = favoriteCandyName;
                return(user);
            }
        }
        public User GetUserByEmailAndPassword(string email, string password)
        {
            var candyRepo = new CandyRepository();

            using (var db = new SqlConnection(_connectionString))
            {
                var sql          = @"SELECT *
                            FROM [User]
                            WHERE ([Password] = @password AND [Email] = @email)";
                var parameters   = new { email, password };
                var userToReturn = db.QueryFirst <User>(sql, parameters);
                var candies      = candyRepo.FetchUsersCandyList(userToReturn);
                userToReturn.CandyOwned = candies;
                var favoriteCandyName = candyRepo.FetchFavoriteCandyName(userToReturn);
                userToReturn.FavoriteTypeOfCandyName = favoriteCandyName;
                return(userToReturn);
            }
        }
 public IEnumerable <User> GetAllUsers()
 {
     using (var db = new SqlConnection(_connectionString))
     {
         var candyRepo = new CandyRepository();
         var users     = db.Query <User>
                         (
             @"SELECT * 
               FROM [User]"
                         ).ToList();
         foreach (User user in users)
         {
             var candies = candyRepo.FetchUsersCandyList(user);
             user.CandyOwned = candies;
             var favoriteCandyName = candyRepo.FetchFavoriteCandyName(user);
             user.FavoriteTypeOfCandyName = favoriteCandyName;
         }
         return(users);
     }
 }