Exemple #1
0
        public BatalhaModels ObterBatalha(long id)
        {
            SqlConnection conexao = new SqlConnection();
            SqlCommand    command = new SqlCommand();

            conexao.ConnectionString = ConfigurationManager.ConnectionStrings["DB_SW"].ToString();
            StringBuilder select = new StringBuilder();

            select.AppendLine("select Guilda,LIFE,DATA,PontuacaoOponente,PontuacaoGuild,RankGuild,idGuilda,Id,IdGuildaAtacante ");
            select.AppendLine(",(select  case when count(1) > 1 then 1 else 0 end from dbo.lutas b where b.CodBatalhas = a.ID and b.MomentoVitoria = 'Win') Vitoria ");
            select.AppendLine("from dbo.Batalhas a");
            select.AppendLine("where id = @id ");

            command.CommandText = select.ToString();
            command.CommandType = System.Data.CommandType.Text;

            command.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int));
            command.Parameters["@id"].Value = id;

            try
            {
                BatalhaModels objBatalha = new BatalhaModels();

                conexao.Open();

                command.Connection = conexao;
                SqlDataReader reader = command.ExecuteReader();

                Guilda daGuilda = new Guilda();


                while (reader.Read())
                {
                    objBatalha                = new BatalhaModels();
                    objBatalha.Data           = Convert.ToDateTime(reader["Data"].ToString());
                    objBatalha.GuildaAtacante = daGuilda.ObterGuilda(long.Parse(reader["IdGuildaAtacante"].ToString()));
                    objBatalha.GuildaOponente = reader["Guilda"].ToString();
                    objBatalha.RankGuild      = int.Parse(reader["RankGuild"].ToString());
                    objBatalha.Vitoria        = Convert.ToBoolean(int.Parse(reader["Vitoria"].ToString()));
                }

                conexao.Close();
                conexao.Dispose();

                return(objBatalha);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        public List <LutasModels> ListarLutas(int idBatalha, long idGuilda)
        {
            SqlConnection conn   = new SqlConnection();
            SqlCommand    sqlCom = new SqlCommand();

            conn.ConnectionString = ConfigurationManager.ConnectionStrings["DB_SW"].ToString();
            StringBuilder select = new StringBuilder();

            select.AppendLine("select ");
            select.AppendLine("a.ID, a.CodBatalhas,a.CodPlayer,a.CodPlayerOponente,a.Vitoria, a.ValorBarra, a.DataHora, a.MomentoVitoria ");
            select.AppendLine("from dbo.lutas a ");
            select.AppendLine("where a.CodBatalhas = @idBatalha ");

            sqlCom.CommandText = select.ToString();
            sqlCom.CommandType = System.Data.CommandType.Text;

            sqlCom.Parameters.Add(new SqlParameter("@idBatalha", System.Data.SqlDbType.Int));
            sqlCom.Parameters["@idBatalha"].Value = idBatalha;

            List <LutasModels> objRetorno = new List <LutasModels>();

            try
            {
                conn.Open();

                sqlCom.Connection = conn;
                SqlDataReader reader = sqlCom.ExecuteReader();

                LutasModels objLuta = null;

                BatalhaModels objBatalha = new BatalhaModels();
                objBatalha = new DataAccess.Batalha().ObterBatalha(idBatalha);

                //Obter Players
                List <PlayerModels> lstPlayer = new List <PlayerModels>();
                lstPlayer = new Player().ListarPlayers(idGuilda);

                while (reader.Read())
                {
                    objLuta                = new LutasModels();
                    objLuta.Batalhas       = objBatalha;
                    objLuta.DataHora       = Convert.ToDateTime(reader["DataHora"].ToString());
                    objLuta.Id             = Convert.ToInt32(reader["ID"].ToString());
                    objLuta.MomentoVitoria = reader["MomentoVitoria"].ToString();
                    objLuta.Player         = lstPlayer.First(x => x.Id == long.Parse(reader["CodPlayer"].ToString()));
                    objLuta.PlayerOponente = new PlayerOponenteModels()
                    {
                        Id = long.Parse(reader["CodPlayerOponente"].ToString())
                    };
                    objLuta.ValorBarra = int.Parse(reader["ValorBarra"].ToString());
                    objLuta.Vitoria    = int.Parse(reader["Vitoria"].ToString());

                    objRetorno.Add(objLuta);
                }
                conn.Close();
                conn.Dispose();
            }
            catch (Exception)
            {
                throw;
            }


            return(objRetorno);
        }