Beispiel #1
0
        public PlayerUsuarioModels ObterPlayerUsuario(int idPlayer)
        {
            SqlConnection conn   = new SqlConnection();
            SqlCommand    sqlCom = new SqlCommand();

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


            StringBuilder cmd = new StringBuilder();

            cmd.Append("select b.Ativo,b.IdGuilda,a.ID idPlayer,d.Id IdUsuario from dbo.Player a ");
            cmd.Append("left join dbo.Guilda_Player b on b.IdPlayer = a.ID ");
            cmd.Append("left join dbo.Guilda c on c.Id = b.IdGuilda ");
            cmd.Append("left join dbo.AspNetUsers d on d.Id = b.IdUsuario ");
            cmd.Append("where a.Id = @id");

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

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

            try
            {
                Models.PlayerUsuarioModels objRetorno = new PlayerUsuarioModels();
                conn.Open();

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


                while (reader.Read())
                {
                    objRetorno = new Models.PlayerUsuarioModels();
                    if (reader["Ativo"].ToString() != string.Empty)
                    {
                        objRetorno.Ativo = bool.Parse(reader["Ativo"].ToString());
                    }

                    if (reader["IdGuilda"].ToString() != string.Empty)
                    {
                        objRetorno.Guilda = new Guilda().ObterGuilda(long.Parse(reader["IdGuilda"].ToString()));
                    }

                    objRetorno.Player = new Player().ObterPlayer(int.Parse(reader["idPlayer"].ToString()));;

                    if (reader["IdUsuario"].ToString() != string.Empty)
                    {
                        objRetorno.Usuario = new Usuario().ObterUsario(reader["IdUsuario"].ToString());
                    }
                }
                conn.Close();
                conn.Dispose();
                return(objRetorno);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public void AtualizarPlayerUsuario(Models.PlayerUsuarioModels objPlayerUsuario)
        {
            SqlConnection conexao = new SqlConnection();
            SqlCommand    command = new SqlCommand();

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

            select.AppendLine("update dbo.Guilda_Player set ativo = @ativo,idUsuario=@idUsuario  where idGuilda = @idGuilda and idPlayer=@idPlayer");

            command.Parameters.Add(new SqlParameter("@idGuilda", System.Data.SqlDbType.BigInt));
            command.Parameters["@idGuilda"].Value = objPlayerUsuario.Guilda.Id;

            command.Parameters.Add(new SqlParameter("@idPlayer", System.Data.SqlDbType.BigInt));
            command.Parameters["@idPlayer"].Value = objPlayerUsuario.Player.Id;

            command.Parameters.Add(new SqlParameter("@ativo", System.Data.SqlDbType.Bit));
            command.Parameters["@ativo"].Value = objPlayerUsuario.Ativo;

            command.Parameters.Add(new SqlParameter("@idUsuario", System.Data.SqlDbType.VarChar));
            command.Parameters["@idUsuario"].Value = objPlayerUsuario.UsuarioCombo.SelectedOption;

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

            conexao.Open();
            command.Connection = conexao;
            command.ExecuteNonQuery();

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