public IList <IViewBattl> Find <IViewBattlQueryParams>(IViewBattlQueryParams query) { _collection = new List <IViewBattl>(); string sqlCommand = "viewBattlFind"; // 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()) { IViewBattl viewBattl = new ViewBattl(); viewBattl.BattlId = Convert.ToInt32(reader["battlId"].ToString()); viewBattl.FirstSongId = Convert.ToInt32(reader["firstSongId"].ToString()); viewBattl.FirstArtistId = Convert.ToInt32(reader["firstArtistId"].ToString()); viewBattl.StartTime = (DateTime)reader["startTime"]; viewBattl.EndTime = (DateTime)reader["endTime"]; viewBattl.BattlDate = (DateTime)reader["battlDate"]; viewBattl.FirstSongUrl = reader["firstSoundCloudUrl"].ToString(); viewBattl.FirstAlbumCover = reader["firstAlbumCover"].ToString(); viewBattl.FirstSongName = reader["firstSongName"].ToString(); viewBattl.FirstArtistName = reader["firstArtistName"].ToString(); viewBattl.FirstAlbumName = reader["firstAlbumName"].ToString(); viewBattl.SecondSongId = Convert.ToInt32(reader["secondSongId"].ToString()); viewBattl.SecondSongUrl = reader["secondSoundCloudUrl"].ToString(); viewBattl.SecondArtistId = Convert.ToInt32(reader["secondArtistId"].ToString()); viewBattl.SecondSongName = reader["secondSongName"].ToString(); viewBattl.SecondArtistName = reader["secondArtistName"].ToString(); viewBattl.SecondAlbumCover = reader["secondAlbumCover"].ToString(); viewBattl.SecondAlbumName = reader["secondAlbumName"].ToString(); viewBattl.FirstSongVotes = Convert.ToInt32(reader["firstSongVotes"].ToString()); viewBattl.SecondSongVotes = Convert.ToInt32(reader["secondSongVotes"].ToString()); viewBattl.Active = Convert.ToBoolean(reader["active"].ToString()); _collection.Add(viewBattl); } } } return(_collection); }
public IViewBattl GetById(int id) { IViewBattl viewBattl = new ViewBattl(); string sqlCommand = "viewBattlFind"; using (DbCommand dbCmd = _dataBase.GetStoredProcCommand(sqlCommand)) { IDataQuery query = new DataQuery(); query.Where = string.Format(" viewBattlId = {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()) { viewBattl.BattlId = Convert.ToInt32(reader["battlId"].ToString()); viewBattl.FirstSongId = Convert.ToInt32(reader["firstSongId"].ToString()); viewBattl.StartTime = (DateTime)reader["startTime"]; viewBattl.EndTime = (DateTime)reader["endTime"]; viewBattl.BattlDate = (DateTime)reader["battlDate"]; viewBattl.FirstSongUrl = reader["firstSoundCloudUrl"].ToString(); viewBattl.FirstAlbumCover = reader["firstAlbumCover"].ToString(); viewBattl.FirstSongName = reader["firstSongName"].ToString(); viewBattl.FirstAlbumName = reader["firstAlbumName"].ToString(); viewBattl.SecondSongUrl = reader["secondSoundCloudUrl"].ToString(); viewBattl.SecondSongId = Convert.ToInt32(reader["secondSongId"].ToString()); viewBattl.SecondSongName = reader["secondSongName"].ToString(); viewBattl.SecondAlbumCover = reader["secondAlbumCover"].ToString(); viewBattl.SecondAlbumName = reader["secondAlbumName"].ToString(); viewBattl.Active = Convert.ToInt32(reader["active"].ToString()) > 0; } } } return(viewBattl); }
public IViewBattl CreateBattl() { IDataQuery query = new DataQuery(); query.Where = string.Format("ViewBattl.active=1"); IViewBattl _viewBattl = new ViewBattl(); IList<IViewBattl> col = _viewBattlRepository.Find(query); if (col.Count > 0) { _viewBattl = col[0]; } else { IBattl battl = GetBattlNotPlayedThisWeek(); DateTime battlTime = DateTime.Now; //GetLastBattlTime(); battl.BattlDate = battlTime; battl.StartTime = new DateTime(battlTime.Year, battlTime.Month, battlTime.Day, battlTime.Hour, battlTime.Minute, 0); battl.EndTime = battl.StartTime.AddSeconds(59); battl.Active = true; using (TransactionScope scope = new TransactionScope()) { battl = _battlRepository.Add(battl); query = new DataQuery(); query.Where = string.Format("ViewBattl.BattlId={0} and active=1", battl.BattlId); col = _viewBattlRepository.Find(query); if (col.Count > 0) { _viewBattl = col[0]; } scope.Complete(); } } return _viewBattl; }
public IViewBattl CreateBattl(DateTime time) { IBattl battl = GetBattlNotPlayedThisWeek(); battl.BattlDate = time; battl.StartTime = new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, 0); battl.EndTime = battl.StartTime.AddSeconds(59); battl = _battlRepository.Add(battl); IDataQuery query = new DataQuery(); query.Where = string.Format("ViewBattl.battlId={0}", battl.BattlId); IViewBattl _viewBattl = new ViewBattl(); _viewBattl = _viewBattlRepository.Find(query)[0]; return _viewBattl; }
public IViewBattl GetActiveBattl(IViewBattlQueryParams queryParams) { IDataQuery query = new DataQuery(); query.Where = string.Format("ViewBattl.active =1"); IViewBattl _battl = new ViewBattl(); IList<IViewBattl> col = _viewBattlRepository.Find(query); if (col.Count > 0) { _battl = col[0]; if (BattlHasExperied(_battl)) { EndActiveBattl(); _battl = CreateBattl(); } } else { _battl = CreateBattl(); } return _battl; }