Beispiel #1
0
        //List<int> ReadIdList(IDataReader reader)
        //{
        //    try
        //    {
        //        List<int> list = new List<int>();
        //        int column = reader.GetOrdinal("id");

        //        while (reader.Read())
        //        {
        //            //check for the null value and than add
        //            if (!reader.IsDBNull(column))
        //                list.Add(reader.GetInt32(column));
        //        }

        //        return list;
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error("UserTeamChip Repository (ReadIdList) error: " + ex.Message);
        //        throw ex;
        //    }
        //}

        List <UserTeamChipId> ReadUserTeamChipIdList(IDataReader reader)
        {
            try
            {
                List <UserTeamChipId> list = new List <UserTeamChipId>();
                int column1 = reader.GetOrdinal("userteamid");
                int column2 = reader.GetOrdinal("gameweekid");
                int column3 = reader.GetOrdinal("chipid");

                //UserTeamChipId userTeamChipId = new UserTeamChipId(0, 0, 0);
                //UserTeamChipId userTeamChipId = new UserTeamChipId();

                while (reader.Read())
                {
                    //check for the null value and than add
                    if (!reader.IsDBNull(column1))
                    {
                        UserTeamChipId userTeamChipId = new UserTeamChipId(0, 0, 0);

                        userTeamChipId.userteamid = reader.GetInt32(column1);
                        userTeamChipId.gameweekid = reader.GetInt32(column2);
                        userTeamChipId.chipid     = reader.GetInt32(column3);
                        list.Add(userTeamChipId);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                Logger.Error("UserTeamChip Repository (GetChipIdFromName) error: " + ex.Message);
                throw ex;
            }
        }
        public static void GetUserTeamChipJson(int userTeamId, UserTeamChips userTeamChipsInsert, UserTeamGameweekHistoryData userTeamHistoryData, SqlConnection db)
        {
            try
            {
                //Logger.Out("GetUserTeamChipJson: Gameweek " + Convert.ToString(gameweekId) + " - starting");

                //Load UserTeamChip data
                UserTeamChipRepository userTeamChipRepository = new UserTeamChipRepository();

                List <UserTeamChipId> userTeamChipIds = new List <UserTeamChipId>();

                //List<UserTeamChipId> userTeamChipIds = userTeamChipRepository.GetAllUserTeamChipIdsForUserTeamId(userTeamId, db);
                userTeamChipIds = userTeamChipRepository.GetAllUserTeamChipIdsForUserTeamId(userTeamId, db);

                foreach (UserTeamChip userTeamChip in userTeamHistoryData.chips)
                {
                    userTeamChip.userteamid = userTeamId;
                    userTeamChip.chip       = userTeamChipRepository.GetChipIdFromName(userTeamChip.name, db);

                    UserTeamChipId userTeamChipId = new UserTeamChipId
                                                    (
                        userTeamId,
                        userTeamChip.@event,
                        userTeamChip.chip
                                                    );

                    //UserTeamChipIds = userTeamChipRepository.GetAllUserTeamPickIdsForUserTeamIdAndGameweekIdAndChipId(userTeamChipId);

                    //needed if want to assign value from parent to add into db table
                    //userTeamChip.entry = userTeamId;

                    userTeamChipId.gameweekid = userTeamChip.@event;
                    userTeamChipId.chipid     = userTeamChip.chip;

                    if (!userTeamChipIds.Contains(userTeamChipId) && !userTeamChipsInsert.Contains(userTeamChip))
                    {
                        userTeamChipsInsert.Add(userTeamChip);
                    }
                    //else
                    //{
                    //    userTeamChipRepository.UpdateUserTeamChip(userTeamChip);
                    //}
                }
                //Logger.Out("GetUserTeamChipJson: Gameweek " + Convert.ToString(gameweekId) + " - completed");
            }
            catch (Exception ex)
            {
                Logger.Error("GetUserTeamChipJson data exception (UserTeamId: " + userTeamId.ToString() + "): " + ex.Message);
                throw new Exception("GetUserTeamChipJson data exception (UserTeamId: " + userTeamId.ToString() + "): " + ex.Message);
                //GetUserTeamChipJson(userTeamId, userTeamChipsInsert, userTeamHistoryData);
            }
        }
Beispiel #3
0
        //public List<int> GetAllUserTeamChipIdsForUserTeamId(int userTeamId, SqlConnection db)
        //{
        //    try
        //    {
        //        string selectQuery = @"SELECT chipid FROM dbo.UserTeamChip WHERE UserTeamId = @UserTeamId;";

        //        IDataReader reader = db.ExecuteReader(selectQuery, new { UserTeamId = userTeamId }, commandTimeout: 0);

        //        List<int> result = ReadList(reader);

        //        return result;
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error("UserTeamChip Repository (GetAllUserTeamChipIdsForUserTeamId) error: " + ex.Message);
        //        throw ex;
        //    }
        //}

        public List <UserTeamChipId> GetAllUserTeamChipIdsForUserTeamIdAndGameweekIdAndChipId(UserTeamChipId userTeamChipId, SqlConnection db)
        {
            try
            {
                int userTeamId, gameweekId, chipId;

                userTeamId = userTeamChipId.userteamid;
                gameweekId = userTeamChipId.gameweekid;
                chipId     = userTeamChipId.chipid;

                using (IDbCommand cmd = db.CreateCommand())
                {
                    cmd.Connection     = db;
                    cmd.CommandTimeout = 0;
                    cmd.CommandType    = CommandType.StoredProcedure;
                    cmd.CommandText    = "GetAllUserTeamChipIdsForUserTeamIdAndGameweekIdAndChipId";

                    IDataParameter param1 = cmd.CreateParameter();
                    param1.ParameterName = "@UserTeamId";
                    param1.Value         = userTeamId;
                    cmd.Parameters.Add(param1);

                    IDataParameter param2 = cmd.CreateParameter();
                    param2.ParameterName = "@GameweekId";
                    param2.Value         = gameweekId;
                    cmd.Parameters.Add(param2);

                    IDataParameter param3 = cmd.CreateParameter();
                    param3.ParameterName = "@ChipId";
                    param3.Value         = chipId;
                    cmd.Parameters.Add(param3);
                    cmd.Parameters.Add(param3);

                    //string selectQuery = @"SELECT DISTINCT userteamid, gameweekid, chipid FROM dbo.UserTeamChip WHERE userteamid = @UserTeamId AND gameweekid = @GameweekId AND chipid = @ChipId;";

                    using (IDataReader reader = cmd.ExecuteReader())
                    {
                        //IDataReader reader = db.ExecuteReader(selectQuery, new { UserTeamId = userTeamId, GameweekId = gameweekId, ChipId = chipId });

                        List <UserTeamChipId> result = ReadUserTeamChipIdList(reader);

                        reader.Close();
                        reader.Dispose();

                        return(result);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("UserTeamChip Repository (GetAllUserTeamChipIdsForUserTeamIdAndGameweekIdAndChipId) error: " + ex.Message);
                throw ex;
            }
        }