コード例 #1
0
        public IBattl GetById(int id)
        {
            IBattl battl      = new Battl();
            string sqlCommand = "battlFind";

            using (DbCommand dbCmd = _dataBase.GetStoredProcCommand(sqlCommand))
            {
                IDataQuery query = new DataQuery();
                query.Where = string.Format(" battlId = {0} ", id);

                _dataBase.AddInParameter(dbCmd, "@fromParam", DbType.String, query.From);
                _dataBase.AddInParameter(dbCmd, "@whereParam", DbType.String, query.Where);
                _dataBase.AddInParameter(dbCmd, "@orderByParam", DbType.String, query.OrderBy);

                // Call the ExecuteReader method with the command.
                using (IDataReader reader = _dataBase.ExecuteReader(dbCmd))
                {
                    while (reader.Read())
                    {
                        battl.BattlId      = Convert.ToInt32(reader["battlId"].ToString());
                        battl.FirstSongId  = Convert.ToInt32(reader["firstSongId"].ToString());
                        battl.SecondSongId = Convert.ToInt32(reader["secondSongId"].ToString());
                        battl.StartTime    = (DateTime)reader["startTime"];
                        battl.EndTime      = (DateTime)reader["endTime"];
                        battl.BattlDate    = (DateTime)reader["battlDate"];
                    }
                }
            }

            return(battl);
        }
コード例 #2
0
        public IList <IBattl> GetTop <IBattlQueryParams>(int top, IBattlQueryParams query)
        {
            _collection = new List <IBattl>();
            string sqlCommand = "battlGetTop";

            using (DbCommand dbCmd = _dataBase.GetStoredProcCommand(sqlCommand))
            {
                _dataBase.AddInParameter(dbCmd, "@topParam", DbType.Int32, top);
                _dataBase.AddInParameter(dbCmd, "@fromParam", DbType.String, ((IDataQuery)query).From);
                _dataBase.AddInParameter(dbCmd, "@whereParam", DbType.String, ((IDataQuery)query).Where);
                _dataBase.AddInParameter(dbCmd, "@orderByParam", DbType.String, ((IDataQuery)query).OrderBy);

                using (IDataReader reader = _dataBase.ExecuteReader(dbCmd))
                {
                    while (reader.Read())
                    {
                        IBattl battl = new Battl();

                        battl.BattlId      = Convert.ToInt32(reader["battlId"].ToString());
                        battl.FirstSongId  = Convert.ToInt32(reader["firstSongId"].ToString());
                        battl.SecondSongId = Convert.ToInt32(reader["secondSongId"].ToString());
                        battl.StartTime    = (DateTime)reader["startTime"];
                        battl.EndTime      = (DateTime)reader["endTime"];
                        battl.BattlDate    = (DateTime)reader["battlDate"];
                        _collection.Add(battl);
                    }
                }
            }

            return(_collection);
        }
コード例 #3
0
        public IList <IBattl> Find <IBattlQueryParams>(IBattlQueryParams query)
        {
            _collection = new List <IBattl>();
            string sqlCommand = "battlFind";

            // Create a suitable command type and add the required parameter.
            using (DbCommand dbCmd = _dataBase.GetStoredProcCommand(sqlCommand))
            {
                _dataBase.AddInParameter(dbCmd, "@fromParam", DbType.String, ((IDataQuery)query).From);
                _dataBase.AddInParameter(dbCmd, "@whereParam", DbType.String, ((IDataQuery)query).Where);
                _dataBase.AddInParameter(dbCmd, "@orderByParam", DbType.String, ((IDataQuery)query).OrderBy);

                // Call the ExecuteReader method with the command.
                using (IDataReader reader = _dataBase.ExecuteReader(dbCmd))
                {
                    while (reader.Read())
                    {
                        IBattl battl = new Battl();

                        battl.BattlId      = Convert.ToInt32(reader["battlId"].ToString());
                        battl.FirstSongId  = Convert.ToInt32(reader["firstSongId"].ToString());
                        battl.SecondSongId = Convert.ToInt32(reader["secondSongId"].ToString());
                        battl.StartTime    = (DateTime)reader["startTime"];
                        battl.EndTime      = (DateTime)reader["endTime"];
                        battl.BattlDate    = (DateTime)reader["battlDate"];
                        battl.Active       = Convert.ToBoolean(reader["active"].ToString());
                        _collection.Add(battl);
                    }
                }
            }

            return(_collection);
        }
コード例 #4
0
        public IBattl Update(IBattl battl)
        {
            IBattl battlUpdated = new Battl();
            string sqlCommand   = "battlUpdate";

            using (DbCommand dbCmd = _dataBase.GetStoredProcCommand(sqlCommand))
            {
                _dataBase.AddInParameter(dbCmd, "@battlId", DbType.Int32, battl.BattlId);
                _dataBase.AddInParameter(dbCmd, "@firstSongId", DbType.Int32, battl.FirstSongId);
                _dataBase.AddInParameter(dbCmd, "@secondSongId", DbType.Int32, battl.SecondSongId);
                _dataBase.AddInParameter(dbCmd, "@startTime", DbType.DateTime, battl.StartTime);
                _dataBase.AddInParameter(dbCmd, "@endTime", DbType.DateTime, battl.EndTime);
                _dataBase.AddInParameter(dbCmd, "@battlDate", DbType.DateTime, battl.BattlDate);
                _dataBase.AddInParameter(dbCmd, "@active", DbType.Int32, battl.Active ? 1 : 0);

                _dataBase.ExecuteScalar(dbCmd);

                battlUpdated = this.GetById(battlUpdated.BattlId);
            }

            return(battlUpdated);
        }
コード例 #5
0
ファイル: BattlBLL.cs プロジェクト: iondrimba/musicbattl
        private DateTime GetLastBattlTime()
        {
            IDataQuery query = new DataQuery();
            query.OrderBy = " battlId DESC ";

            IBattl battl = new Battl();
            IList<IBattl> collection = _battlRepository.GetTop(1, query);

            if (collection.Count == 0)
            {
                battl.EndTime = DateTime.Now;
            }
            else
            {
                battl.EndTime = collection[0].EndTime;
            }

            return battl.EndTime;
        }
コード例 #6
0
ファイル: BattlBLL.cs プロジェクト: iondrimba/musicbattl
        private IBattl GetBattlNotPlayedThisWeek()
        {
            IBattl battl = new Battl();
            IDataQuery query = new DataQuery();

            DateTime date = DateTime.Now;
            int daysRange = 6;
            int dayWeek = (int)date.DayOfWeek;
            DateTime lastMonday = date.AddDays(-daysRange);
            DateTime lastSunday = date;

            IRepositoryBLL<ISong> repo = new SongRepositoryBLL(new SongRepository(_dataBase));
            ISongBLL songBLL = new SongBLL(repo);

            ISong fisrtSong = songBLL.GetRandomSong(0);
            ISong secondSong = songBLL.GetRandomSong(fisrtSong.SongId);

            battl.FirstSongId = fisrtSong.SongId;
            battl.SecondSongId = secondSong.SongId;

            return battl;
        }
コード例 #7
0
ファイル: BattlBLL.cs プロジェクト: iondrimba/musicbattl
        public IBattl CreateTestBattl(DateTime date)
        {
            DateTime lastBattlTime = date;

            IRepositoryBLL<ISong> repo = new SongRepositoryBLL(new SongRepository(_dataBase));
            ISongBLL songBLL = new SongBLL(repo);
            ISong fisrtSong = songBLL.GetRandomSong(0);
            ISong secondSong = songBLL.GetRandomSong(fisrtSong.SongId);

            IBattl battl = new Battl();
            battl.FirstSongId = fisrtSong.SongId;
            battl.SecondSongId = secondSong.SongId;
            battl.BattlDate = lastBattlTime.AddHours(1);
            battl.StartTime = battl.BattlDate.AddMinutes(5);
            battl.EndTime = battl.StartTime.AddMinutes(5);

            battl = _battlRepository.Add(battl);

            return battl;
        }