From d4e8b1241a57e0f6fd8041992f7785f17e13dac3 Mon Sep 17 00:00:00 2001 From: Wesley schuab Vieira <58818125+WesleySchuab@users.noreply.github.com> Date: Sun, 10 Mar 2024 18:29:59 -0300 Subject: [PATCH 01/85] Create README.md Passos para executar o projeto --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..3263ee0 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Primeiro passo é instalar o pacote: Microsoft.Data.SqlClient +No Visual Studio, vamos em "Ferramentas > Gerenciador de Pacotes do NuGet > Gerenciar Pacotes do NuGet para a Solução…". Na aba "Procurar", vamos pesquisar por "SQL Client". + +O primeiro exibido será o Microsoft.Data.SqlClient, o qual utilizaremos em nosso projeto para estabelecer o vínculo do banco de dados com o projeto em si. À direita, vamos marcar o projeto ScreenSound e clicar em "Instalar". Para concluir, devemos aceitar as licenças. From 973ce1e9d3e207ba92e756170f2aac92f9c18019 Mon Sep 17 00:00:00 2001 From: Wesley schuab Vieira <58818125+WesleySchuab@users.noreply.github.com> Date: Sun, 10 Mar 2024 18:48:50 -0300 Subject: [PATCH 02/85] corrigindo readme --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3263ee0..f814303 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ -Primeiro passo é instalar o pacote: Microsoft.Data.SqlClient +Primeiro passo é criar o banco de dados +Criando o banco de dados ScreenSound : Para criarmos um banco para utilizar na nossa aplicação, vamos em "Exibir > Pesquisador de Objetos do SQL Server". Ao clicar nele, abrirá uma janela na lateral esquerda do Visual Studio. + +Nessa janela do Pesquisador de Objetos é onde vamos conseguir gerenciar o nosso banco. Teremos a pasta "Banco de Dados", e clicando com o botão direito sobre ela, temos a opção "Adicionar Novo Banco de Dados". Vamos selecionar essa opção e criar um banco de dados com o nome do nosso projeto. Portanto, vamos chamá-lo de ScreenSound. + +Após pressionar "Enter" ou clicar em "OK", aparecerá na lista de bancos à esquerda todos os bancos disponíveis, inclusive o ScreenSound que acabamos de criar. +Segundo Passo +instalar o pacote: Microsoft.Data.SqlClient No Visual Studio, vamos em "Ferramentas > Gerenciador de Pacotes do NuGet > Gerenciar Pacotes do NuGet para a Solução…". Na aba "Procurar", vamos pesquisar por "SQL Client". O primeiro exibido será o Microsoft.Data.SqlClient, o qual utilizaremos em nosso projeto para estabelecer o vínculo do banco de dados com o projeto em si. À direita, vamos marcar o projeto ScreenSound e clicar em "Instalar". Para concluir, devemos aceitar as licenças. From cd60e0212ebe6a7ffc0ba0d59b38d7c5b5b42208 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 10 Mar 2024 19:59:43 -0300 Subject: [PATCH 03/85] =?UTF-8?q?Mensagem=20de=20aguarde=20na=20fun=C3=A7?= =?UTF-8?q?=C3=A3o=20registrar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Menus/MenuRegistrarArtista.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ScreenSound/Menus/MenuRegistrarArtista.cs b/ScreenSound/Menus/MenuRegistrarArtista.cs index e01bfd7..f99bb9e 100644 --- a/ScreenSound/Menus/MenuRegistrarArtista.cs +++ b/ScreenSound/Menus/MenuRegistrarArtista.cs @@ -15,6 +15,7 @@ public override void Executar(Dictionary artistasRegistrados) Artista artista = new Artista(nomeDoArtista, bioDoArtista); artistasRegistrados.Add(nomeDoArtista, artista); Console.WriteLine($"O artista {nomeDoArtista} foi registrado com sucesso!"); + Console.WriteLine("Aguarde"); Thread.Sleep(4000); Console.Clear(); } From af5a01a0d051609d176cea6d76c151f6129fbdba Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 10 Mar 2024 20:36:10 -0300 Subject: [PATCH 04/85] Removendo a msg de teste --- ScreenSound/Menus/MenuRegistrarArtista.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/ScreenSound/Menus/MenuRegistrarArtista.cs b/ScreenSound/Menus/MenuRegistrarArtista.cs index f99bb9e..e01bfd7 100644 --- a/ScreenSound/Menus/MenuRegistrarArtista.cs +++ b/ScreenSound/Menus/MenuRegistrarArtista.cs @@ -15,7 +15,6 @@ public override void Executar(Dictionary artistasRegistrados) Artista artista = new Artista(nomeDoArtista, bioDoArtista); artistasRegistrados.Add(nomeDoArtista, artista); Console.WriteLine($"O artista {nomeDoArtista} foi registrado com sucesso!"); - Console.WriteLine("Aguarde"); Thread.Sleep(4000); Console.Clear(); } From 00283339fc378d39dac8db7f153c6e65c16e3408 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 10 Mar 2024 21:55:02 -0300 Subject: [PATCH 05/85] Adiciondo a pasta banco e a classe Connection --- ScreenSound/Banco/Connection.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ScreenSound/Banco/Connection.cs diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs new file mode 100644 index 0000000..26ecb28 --- /dev/null +++ b/ScreenSound/Banco/Connection.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ScreenSound.Banco +{ + internal class Connection + { + } +} From 7fbb3ed4ff18b39c984142df119b1978ad582cac Mon Sep 17 00:00:00 2001 From: Wesley schuab Vieira <58818125+WesleySchuab@users.noreply.github.com> Date: Sat, 16 Mar 2024 10:16:12 -0300 Subject: [PATCH 06/85] =?UTF-8?q?Como=20fazer=20a=20conex=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Detalhes de como criar a string de conexão --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index f814303..9908a1c 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,8 @@ instalar o pacote: Microsoft.Data.SqlClient No Visual Studio, vamos em "Ferramentas > Gerenciador de Pacotes do NuGet > Gerenciar Pacotes do NuGet para a Solução…". Na aba "Procurar", vamos pesquisar por "SQL Client". O primeiro exibido será o Microsoft.Data.SqlClient, o qual utilizaremos em nosso projeto para estabelecer o vínculo do banco de dados com o projeto em si. À direita, vamos marcar o projeto ScreenSound e clicar em "Instalar". Para concluir, devemos aceitar as licenças. +Para fazer a conexão, precisamos passar o caminho onde está o banco de dados e mais algumas outras informações de configuração. Para localizar essas informações, vamos ao Pesquisador de Objetos do SQL Server, clicamos com o botão direito sobre o banco de dados ScreenSound e vamos em "Propriedades". + +Na lateral direita, aparecerão várias informações de propriedade. Precisamos da "Cadeia de conexão". Vamos copiar as informações desse campo para usá-las na classe Connection. + +Feito isso, precisamos trazer essas informações. Elas serão a nossa string de conexão. Portanto, podemos criar um private string que se chamará connectionString. Após o igual (=), passaremos todas as informações copiadas das propriedades do banco. Vamos apenas remover o Connect Timeout que vem por padrão 30, para que a execução seja um pouco mais rápida. From 59307ab3d1481e928e9eb98f13b70df91aec7e16 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 16 Mar 2024 13:35:37 -0300 Subject: [PATCH 07/85] =?UTF-8?q?Criando=20string=20de=20conex=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/Connection.cs | 3 +++ ScreenSound/ScreenSound.csproj | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index 26ecb28..df2e789 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -8,5 +8,8 @@ namespace ScreenSound.Banco { internal class Connection { + private string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ScreenSound;" + + "Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + + "Multi Subnet Failover=False"; } } diff --git a/ScreenSound/ScreenSound.csproj b/ScreenSound/ScreenSound.csproj index ebc9f8f..3997c71 100644 --- a/ScreenSound/ScreenSound.csproj +++ b/ScreenSound/ScreenSound.csproj @@ -11,4 +11,8 @@ + + + + From b27f21a8b5db9cd4ef1caef26f2f4e58a989344f Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 16 Mar 2024 13:53:22 -0300 Subject: [PATCH 08/85] adicionando aspcore.net no git ignore --- .gitignore | 532 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 531 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9491a2f..0ed7bca 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,534 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +# Created by https://www.toptal.com/developers/gitignore/api/visualstudio,aspnetcore +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio,aspnetcore + +### ASPNETCore ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ + +### VisualStudio ### +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser + +# User-specific files (MonoDevelop/Xamarin Studio) + +# Mono auto generated files +mono_crash.* + +# Build results +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +# Uncomment if you have tasks that create the project's static files in wwwroot + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results + +# NUnit +nunit-*.xml + +# Build Results of an ATL Project + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_h.h +*.iobj +*.ipdb +*_wpftmp.csproj +*.tlog + +# Chutzpah Test files + +# Visual C++ cache files + +# Visual Studio profiler + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace + +# Guidance Automation Toolkit + +# ReSharper is a .NET coding add-in + +# TeamCity is a build add-in + +# DotCover is a Code Coverage Tool + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results + +# NCrunch + +# MightyMoose + +# Web workbench (sass) + +# Installshield output folder + +# DocProject is a documentation generator add-in + +# Click-Once directory + +# Publish Web Output +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted + +# NuGet Packages +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files + +# Microsoft Azure Build Output + +# Microsoft Azure Emulator + +# Windows Store app package directories and files +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) + +# RIA/Silverlight projects + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.ndf + +# Business Intelligence projects +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes + +# GhostDoc plugin setting file + +# Node.js Tools for Visual Studio + +# Visual Studio 6 build log + +# Visual Studio 6 workspace options file + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output + +# Paket dependency manager + +# FAKE - F# Make + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider + +### VisualStudio Patch ### +# Additional files built by Visual Studio + +# End of https://www.toptal.com/developers/gitignore/api/visualstudio,aspnetcore \ No newline at end of file From 5ee358e3fbb343c4daafe79d70405dba1d2bad90 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 16 Mar 2024 14:06:23 -0300 Subject: [PATCH 09/85] retirando o timeout para agilizar os estudos --- ScreenSound/Banco/Connection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index df2e789..90d4cef 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -9,7 +9,7 @@ namespace ScreenSound.Banco internal class Connection { private string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ScreenSound;" + - "Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + + "Integrated Security=True;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + "Multi Subnet Failover=False"; } } From 9b60ce8f68e109c2057519114e10dc3565e86824 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 16 Mar 2024 14:18:03 -0300 Subject: [PATCH 10/85] =?UTF-8?q?criando=20o=20metodo=20de=20conex=C3=A3o?= =?UTF-8?q?=20com=20o=20banco=20de=20dados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/Connection.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index 90d4cef..a926c57 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Data.SqlClient; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -11,5 +12,10 @@ internal class Connection private string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ScreenSound;" + "Integrated Security=True;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + "Multi Subnet Failover=False"; + + public SqlConnection ObterConexao () + { + return new SqlConnection (connectionString); + } } } From f0ea7520819adff891530a2716cb73edbad97da6 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 16 Mar 2024 14:23:09 -0300 Subject: [PATCH 11/85] =?UTF-8?q?testando=20a=20conex=C3=A3o=20com=20banco?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Program.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index 3e7588a..8d17552 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -1,5 +1,17 @@ -using ScreenSound.Menus; +using ScreenSound.Banco; +using ScreenSound.Menus; using ScreenSound.Modelos; +try +{ + using var connection = new Connection().ObterConexao(); + connection.Open(); + Console.WriteLine(connection.State); +} +catch (Exception ex) +{ + Console.WriteLine(ex.Message); +} +return; Artista ira = new Artista("Ira!", "Banda Ira!"); Artista beatles = new("The Beatles", "Banda The Beatles"); From ed6771b64fbd61de564bd47b52ce979d939a6255 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 16 Mar 2024 15:54:55 -0300 Subject: [PATCH 12/85] criando o metodo listar --- ScreenSound/Banco/Connection.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index a926c57..80b8ba5 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -1,4 +1,5 @@ using Microsoft.Data.SqlClient; +using ScreenSound.Modelos; using System; using System.Collections.Generic; using System.Linq; @@ -17,5 +18,12 @@ public SqlConnection ObterConexao () { return new SqlConnection (connectionString); } + + public IEnumerable Listar() + { + var lista = new List(); + using var connection = ObterConexao(); + connection.Open (); + } } } From bafb69d8439e8178b661001c06a834be33aad1d9 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 17 Mar 2024 14:29:25 -0300 Subject: [PATCH 13/85] criando o objeto sql command --- ScreenSound/Banco/Connection.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index 80b8ba5..23a5008 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -24,6 +24,10 @@ public IEnumerable Listar() var lista = new List(); using var connection = ObterConexao(); connection.Open (); + + string sql = "SELECT * FROM Artistas"; + + SqlCommand command = new SqlCommand (sql, connection); } } } From 5f3936cc58516e70267967a08d1be9b6ddfe00fa Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 17 Mar 2024 14:46:31 -0300 Subject: [PATCH 14/85] =?UTF-8?q?lendo=20os=20dados=20do=20banco=20com=20u?= =?UTF-8?q?m=20la=C3=A7o=20while?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/Connection.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index 23a5008..e2a3af6 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -28,6 +28,14 @@ public IEnumerable Listar() string sql = "SELECT * FROM Artistas"; SqlCommand command = new SqlCommand (sql, connection); + + using SqlDataReader dataReader = command.ExecuteReader (); + while (dataReader.Read ()) + { + string nomeArtista = Convert.ToString(dataReader["Nome"]); + string bioArtista = Convert.ToString(dataReader["Bio"]); + int idArtista = Convert.ToInt32(dataReader["ID"]); + } } } } From 19625770cbe5d99128493b70db3813aef5322fdf Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 17 Mar 2024 14:48:22 -0300 Subject: [PATCH 15/85] =?UTF-8?q?Criando=20obj=20do=20tipo=20artista=20par?= =?UTF-8?q?a=20salvar=20as=20informa=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/Connection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index e2a3af6..c0da0b8 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -35,7 +35,7 @@ public IEnumerable Listar() string nomeArtista = Convert.ToString(dataReader["Nome"]); string bioArtista = Convert.ToString(dataReader["Bio"]); int idArtista = Convert.ToInt32(dataReader["ID"]); - } + Artista artista = new(nomeArtista, bioArtista) { Id = idArtista }; } } } From e5d60c36445c60f70df878b9914166169f7452f7 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 17 Mar 2024 14:49:43 -0300 Subject: [PATCH 16/85] salvando o objeto em uma lista --- ScreenSound/Banco/Connection.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index c0da0b8..344677b 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -35,7 +35,9 @@ public IEnumerable Listar() string nomeArtista = Convert.ToString(dataReader["Nome"]); string bioArtista = Convert.ToString(dataReader["Bio"]); int idArtista = Convert.ToInt32(dataReader["ID"]); + Artista artista = new(nomeArtista, bioArtista) { Id = idArtista }; + lista.Add(artista); } } } From a9c1f4d4bd0bbea2020c3f2f6c4e9c253d367d7a Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 17 Mar 2024 14:58:20 -0300 Subject: [PATCH 17/85] Adicionando um colhete que faltava --- ScreenSound/Banco/Connection.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index 344677b..49113c3 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -14,23 +14,23 @@ internal class Connection "Integrated Security=True;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + "Multi Subnet Failover=False"; - public SqlConnection ObterConexao () + public SqlConnection ObterConexao() { - return new SqlConnection (connectionString); + return new SqlConnection(connectionString); } public IEnumerable Listar() { var lista = new List(); using var connection = ObterConexao(); - connection.Open (); + connection.Open(); string sql = "SELECT * FROM Artistas"; - SqlCommand command = new SqlCommand (sql, connection); + SqlCommand command = new SqlCommand(sql, connection); - using SqlDataReader dataReader = command.ExecuteReader (); - while (dataReader.Read ()) + using SqlDataReader dataReader = command.ExecuteReader(); + while (dataReader.Read()) { string nomeArtista = Convert.ToString(dataReader["Nome"]); string bioArtista = Convert.ToString(dataReader["Bio"]); @@ -38,6 +38,8 @@ public IEnumerable Listar() Artista artista = new(nomeArtista, bioArtista) { Id = idArtista }; lista.Add(artista); + } + return lista; } } } From 69145444e0cc4c50e6ed127073eff94da8531a24 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 17 Mar 2024 15:17:54 -0300 Subject: [PATCH 18/85] utilizando o metodo listar no programa principal --- ScreenSound/Banco/Connection.cs | 9 +++++---- ScreenSound/Program.cs | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index 49113c3..ce13b08 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -26,20 +26,21 @@ public IEnumerable Listar() connection.Open(); string sql = "SELECT * FROM Artistas"; - SqlCommand command = new SqlCommand(sql, connection); - using SqlDataReader dataReader = command.ExecuteReader(); + while (dataReader.Read()) { string nomeArtista = Convert.ToString(dataReader["Nome"]); string bioArtista = Convert.ToString(dataReader["Bio"]); - int idArtista = Convert.ToInt32(dataReader["ID"]); - + int idArtista = Convert.ToInt32(dataReader["Id"]); Artista artista = new(nomeArtista, bioArtista) { Id = idArtista }; + lista.Add(artista); } + return lista; } + } } diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index 8d17552..80aa354 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -1,11 +1,15 @@ using ScreenSound.Banco; using ScreenSound.Menus; using ScreenSound.Modelos; + try { - using var connection = new Connection().ObterConexao(); - connection.Open(); - Console.WriteLine(connection.State); + var connection = new Connection(); + var listaArtistas = connection.Listar(); + foreach ( var artist in listaArtistas ) + { + Console.WriteLine( artist ); + } } catch (Exception ex) { From 164d7cc6554e735cff285472ab9729df9310f214 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 17 Mar 2024 15:32:31 -0300 Subject: [PATCH 19/85] =?UTF-8?q?modificando=20nosso=20padr=C3=A3o=20p?= =?UTF-8?q?=C3=A1ra=20utilizar=20o=20DAL=20(Data=20Access=20Layer)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/Connection.cs | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/Connection.cs index ce13b08..2a9dbd1 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/Connection.cs @@ -19,28 +19,7 @@ public SqlConnection ObterConexao() return new SqlConnection(connectionString); } - public IEnumerable Listar() - { - var lista = new List(); - using var connection = ObterConexao(); - connection.Open(); - - string sql = "SELECT * FROM Artistas"; - SqlCommand command = new SqlCommand(sql, connection); - using SqlDataReader dataReader = command.ExecuteReader(); - - while (dataReader.Read()) - { - string nomeArtista = Convert.ToString(dataReader["Nome"]); - string bioArtista = Convert.ToString(dataReader["Bio"]); - int idArtista = Convert.ToInt32(dataReader["Id"]); - Artista artista = new(nomeArtista, bioArtista) { Id = idArtista }; - - lista.Add(artista); - } - - return lista; - } + } } From b0316aa848e8e7c4b3c8f6343eb866ae4fab2b4b Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 17 Mar 2024 16:05:28 -0300 Subject: [PATCH 20/85] Metodo Adionar itens no banco de dados --- ScreenSound/Banco/ArtistaDAl.cs | 49 +++++++++++++++++++++++++++++++++ ScreenSound/Program.cs | 7 +++-- 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 ScreenSound/Banco/ArtistaDAl.cs diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs new file mode 100644 index 0000000..3218bd5 --- /dev/null +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -0,0 +1,49 @@ +using Microsoft.Data.SqlClient; +using ScreenSound.Modelos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ScreenSound.Banco +{ + internal class ArtistaDAl + { + public IEnumerable Listar() + { + var lista = new List(); + using var connection = new Connection().ObterConexao(); + connection.Open(); + + string sql = "SELECT * FROM Artistas"; + SqlCommand command = new SqlCommand(sql, connection); + using SqlDataReader dataReader = command.ExecuteReader(); + + while (dataReader.Read()) + { + string nomeArtista = Convert.ToString(dataReader["Nome"]); + string bioArtista = Convert.ToString(dataReader["Bio"]); + int idArtista = Convert.ToInt32(dataReader["Id"]); + Artista artista = new(nomeArtista, bioArtista) { Id = idArtista }; + + lista.Add(artista); + } + + return lista; + } + public void Adicionar(Artista artista) + { + using var connection = new Connection().ObterConexao(); + connection.Open(); + string sql = "INSERT INTO Artistas(Nome, FotoPerfil, bio) VALUES (@nome, @perfilPadrao, @bio)"; + SqlCommand command = new SqlCommand(sql, connection); + + command.Parameters.AddWithValue("@nome", artista.Nome); + command.Parameters.AddWithValue("@perfilPadrao", artista.FotoPerfil); + command.Parameters.AddWithValue("@bio", artista.Bio); + int retorno = command.ExecuteNonQuery(); + Console.WriteLine($"Linhas afetadas {retorno}"); + } + } +} diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index 80aa354..dc2e3a2 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -4,8 +4,11 @@ try { - var connection = new Connection(); - var listaArtistas = connection.Listar(); + var artistaDAL = new ArtistaDAl(); + artistaDAL.Adicionar(new Artista("Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995.")); + + var listaArtistas = artistaDAL.Listar(); + foreach ( var artist in listaArtistas ) { Console.WriteLine( artist ); From f742e7aeee795823078ec4807c1bda14149081b8 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sun, 17 Mar 2024 23:55:56 -0300 Subject: [PATCH 21/85] =?UTF-8?q?Alterando=20nome=20da=20classe=20para=20p?= =?UTF-8?q?adr=C3=A3o=20entity=20framework?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/ArtistaDAl.cs | 14 ++++++++++++-- .../Banco/{Connection.cs => ScreenSoundContext.cs} | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) rename ScreenSound/Banco/{Connection.cs => ScreenSoundContext.cs} (94%) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 3218bd5..5f9d628 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -13,7 +13,7 @@ internal class ArtistaDAl public IEnumerable Listar() { var lista = new List(); - using var connection = new Connection().ObterConexao(); + using var connection = new ScreenSoundContext().ObterConexao(); connection.Open(); string sql = "SELECT * FROM Artistas"; @@ -34,7 +34,7 @@ public IEnumerable Listar() } public void Adicionar(Artista artista) { - using var connection = new Connection().ObterConexao(); + using var connection = new ScreenSoundContext().ObterConexao(); connection.Open(); string sql = "INSERT INTO Artistas(Nome, FotoPerfil, bio) VALUES (@nome, @perfilPadrao, @bio)"; SqlCommand command = new SqlCommand(sql, connection); @@ -45,5 +45,15 @@ public void Adicionar(Artista artista) int retorno = command.ExecuteNonQuery(); Console.WriteLine($"Linhas afetadas {retorno}"); } + //public void Atualizar(Artista artista ) + //{ + // using var connection = new ScreenSoundContext().ObterConexao(); + // connection.Open(); + // string sql = "UPDATE Artistas SET (Nome = @nome, Bio = @bio WHERE Id = @id )"; + // SqlCommand command = new SqlCommand(sql, connection); + + + + //} } } diff --git a/ScreenSound/Banco/Connection.cs b/ScreenSound/Banco/ScreenSoundContext.cs similarity index 94% rename from ScreenSound/Banco/Connection.cs rename to ScreenSound/Banco/ScreenSoundContext.cs index 2a9dbd1..0028875 100644 --- a/ScreenSound/Banco/Connection.cs +++ b/ScreenSound/Banco/ScreenSoundContext.cs @@ -8,7 +8,7 @@ namespace ScreenSound.Banco { - internal class Connection + internal class ScreenSoundContext { private string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ScreenSound;" + "Integrated Security=True;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + From 6da2065a056fd2f9c4d152860785d553d3b990c0 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Mon, 18 Mar 2024 00:02:57 -0300 Subject: [PATCH 22/85] =?UTF-8?q?Rescrevendo=20o=20metodo=20de=20conex?= =?UTF-8?q?=C3=A3o=20com=20banco=20de=20dados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/ScreenSoundContext.cs | 11 +++++------ ScreenSound/ScreenSound.csproj | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ScreenSound/Banco/ScreenSoundContext.cs b/ScreenSound/Banco/ScreenSoundContext.cs index 0028875..fbea653 100644 --- a/ScreenSound/Banco/ScreenSoundContext.cs +++ b/ScreenSound/Banco/ScreenSoundContext.cs @@ -1,4 +1,5 @@ using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; using ScreenSound.Modelos; using System; using System.Collections.Generic; @@ -8,18 +9,16 @@ namespace ScreenSound.Banco { - internal class ScreenSoundContext + internal class ScreenSoundContext: DbContext { private string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ScreenSound;" + "Integrated Security=True;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + "Multi Subnet Failover=False"; - - public SqlConnection ObterConexao() + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - return new SqlConnection(connectionString); + optionsBuilder.UseSqlServer(connectionString); } - - + } } diff --git a/ScreenSound/ScreenSound.csproj b/ScreenSound/ScreenSound.csproj index 3997c71..e4122e6 100644 --- a/ScreenSound/ScreenSound.csproj +++ b/ScreenSound/ScreenSound.csproj @@ -13,6 +13,7 @@ + From 510dfa9490e93841ce6a479825a80d559909612a Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Mon, 18 Mar 2024 00:26:40 -0300 Subject: [PATCH 23/85] mapeandoa tabela Artistas com o DbSet --- ScreenSound/Banco/ArtistaDAl.cs | 4 ++-- ScreenSound/Banco/ScreenSoundContext.cs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 5f9d628..d853113 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -32,7 +32,7 @@ public IEnumerable Listar() return lista; } - public void Adicionar(Artista artista) + /* public void Adicionar(Artista artista) { using var connection = new ScreenSoundContext().ObterConexao(); connection.Open(); @@ -44,7 +44,7 @@ public void Adicionar(Artista artista) command.Parameters.AddWithValue("@bio", artista.Bio); int retorno = command.ExecuteNonQuery(); Console.WriteLine($"Linhas afetadas {retorno}"); - } + }*/ //public void Atualizar(Artista artista ) //{ // using var connection = new ScreenSoundContext().ObterConexao(); diff --git a/ScreenSound/Banco/ScreenSoundContext.cs b/ScreenSound/Banco/ScreenSoundContext.cs index fbea653..71113d2 100644 --- a/ScreenSound/Banco/ScreenSoundContext.cs +++ b/ScreenSound/Banco/ScreenSoundContext.cs @@ -11,6 +11,8 @@ namespace ScreenSound.Banco { internal class ScreenSoundContext: DbContext { + public DbSet Artistas { get; set; } + private string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ScreenSound;" + "Integrated Security=True;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + "Multi Subnet Failover=False"; From 6b7ced4e0de3a0c926a59f44c4b0e45fb87f9ac9 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Mon, 18 Mar 2024 00:51:25 -0300 Subject: [PATCH 24/85] Refatorando metodo listar --- ScreenSound/Banco/ArtistaDAl.cs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index d853113..e571ff3 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -13,24 +13,9 @@ internal class ArtistaDAl public IEnumerable Listar() { var lista = new List(); - using var connection = new ScreenSoundContext().ObterConexao(); - connection.Open(); - - string sql = "SELECT * FROM Artistas"; - SqlCommand command = new SqlCommand(sql, connection); - using SqlDataReader dataReader = command.ExecuteReader(); - - while (dataReader.Read()) - { - string nomeArtista = Convert.ToString(dataReader["Nome"]); - string bioArtista = Convert.ToString(dataReader["Bio"]); - int idArtista = Convert.ToInt32(dataReader["Id"]); - Artista artista = new(nomeArtista, bioArtista) { Id = idArtista }; - - lista.Add(artista); - } - - return lista; + using var context = new ScreenSoundContext(); + + return context.Artistas.ToList(); } /* public void Adicionar(Artista artista) { From cf04dae632182fb7f6569d64bc5ad5e321a492db Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Tue, 19 Mar 2024 18:55:39 -0300 Subject: [PATCH 25/85] =?UTF-8?q?Modificano=20metodo=20adicionar=20para=20?= =?UTF-8?q?padr=C3=A3o=20ORM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/ArtistaDAl.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index e571ff3..f993ea6 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -17,19 +17,12 @@ public IEnumerable Listar() return context.Artistas.ToList(); } - /* public void Adicionar(Artista artista) + public void Adicionar(Artista artista) { - using var connection = new ScreenSoundContext().ObterConexao(); - connection.Open(); - string sql = "INSERT INTO Artistas(Nome, FotoPerfil, bio) VALUES (@nome, @perfilPadrao, @bio)"; - SqlCommand command = new SqlCommand(sql, connection); - - command.Parameters.AddWithValue("@nome", artista.Nome); - command.Parameters.AddWithValue("@perfilPadrao", artista.FotoPerfil); - command.Parameters.AddWithValue("@bio", artista.Bio); - int retorno = command.ExecuteNonQuery(); - Console.WriteLine($"Linhas afetadas {retorno}"); - }*/ + using var context = new ScreenSoundContext(); + context.Artistas.Add(artista); + context.SaveChanges(); + } //public void Atualizar(Artista artista ) //{ // using var connection = new ScreenSoundContext().ObterConexao(); From db50207cfcc9d4892d1faf014a018b0d518a3e22 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Tue, 19 Mar 2024 19:14:02 -0300 Subject: [PATCH 26/85] Refatorando metodo adicionar para modelo ORM --- ScreenSound/Banco/ArtistaDAl.cs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index f993ea6..021eb62 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -10,28 +10,22 @@ namespace ScreenSound.Banco { internal class ArtistaDAl { - public IEnumerable Listar() + private readonly ScreenSoundContext context; + + public ArtistaDAl(ScreenSoundContext context) { - var lista = new List(); - using var context = new ScreenSoundContext(); - + this.context = context; + } + + public IEnumerable Listar() + { return context.Artistas.ToList(); } public void Adicionar(Artista artista) { - using var context = new ScreenSoundContext(); context.Artistas.Add(artista); context.SaveChanges(); } - //public void Atualizar(Artista artista ) - //{ - // using var connection = new ScreenSoundContext().ObterConexao(); - // connection.Open(); - // string sql = "UPDATE Artistas SET (Nome = @nome, Bio = @bio WHERE Id = @id )"; - // SqlCommand command = new SqlCommand(sql, connection); - - - - //} + } } From eab62c4f3fe1d798fe4fdcb2dcb9add89ea2d217 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Tue, 19 Mar 2024 19:14:39 -0300 Subject: [PATCH 27/85] Metodo atualizar e deletar modelo ORM --- ScreenSound/Banco/ArtistaDAl.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 021eb62..4797aa0 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -26,6 +26,14 @@ public void Adicionar(Artista artista) context.Artistas.Add(artista); context.SaveChanges(); } - + public void Atualizar(Artista artista) + { + context.Artistas.Update(artista); + context.SaveChanges(); + } + public void Deletar(Artista artista) + { + context.Artistas.Remove(artista); + } } } From 8e5def7d01f6793ab23df1c3b626850e25dedc84 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Tue, 19 Mar 2024 19:16:56 -0300 Subject: [PATCH 28/85] Passando o context para ArtistaDAL --- ScreenSound/Program.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index dc2e3a2..540833a 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -4,7 +4,9 @@ try { - var artistaDAL = new ArtistaDAl(); + var context = new ScreenSoundContext(); + var artistaDAL = new ArtistaDAl(context); + artistaDAL.Adicionar(new Artista("Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995.")); var listaArtistas = artistaDAL.Listar(); From ec77c0547487a5dad5147979bb4c99f6d231e00c Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Tue, 19 Mar 2024 19:19:34 -0300 Subject: [PATCH 29/85] Adicionando um novo artista --- ScreenSound/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index 540833a..87505a2 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -7,8 +7,9 @@ var context = new ScreenSoundContext(); var artistaDAL = new ArtistaDAl(context); - artistaDAL.Adicionar(new Artista("Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995.")); + var novoArtista = new Artista("Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995."); + artistaDAL.Adicionar(novoArtista); var listaArtistas = artistaDAL.Listar(); foreach ( var artist in listaArtistas ) From f3a56f5109c80f7502482792027f18f93a270760 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Tue, 19 Mar 2024 19:30:12 -0300 Subject: [PATCH 30/85] Corrigindo metodo Deletar --- ScreenSound/Banco/ArtistaDAl.cs | 1 + ScreenSound/Program.cs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 4797aa0..daf841d 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -34,6 +34,7 @@ public void Atualizar(Artista artista) public void Deletar(Artista artista) { context.Artistas.Remove(artista); + context.SaveChanges(); } } } diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index 87505a2..4abf616 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -7,9 +7,12 @@ var context = new ScreenSoundContext(); var artistaDAL = new ArtistaDAl(context); - var novoArtista = new Artista("Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995."); + //var novoArtista = new Artista("Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995."); + var novoArtista = new Artista("Gilberto Gil", "Gilberto Passos Gil Moreira é um cantor, compositor, multi-instrumentista, produtor musical, político e escritor brasileiro.") { Id = 3}; - artistaDAL.Adicionar(novoArtista); + + //artistaDAL.Adicionar(novoArtista); + artistaDAL.Deletar(novoArtista); var listaArtistas = artistaDAL.Listar(); foreach ( var artist in listaArtistas ) From c5f6ab0131c7a40a0c74c33f7804445445682599 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Tue, 19 Mar 2024 20:40:37 -0300 Subject: [PATCH 31/85] Realizando uma busca pelo nome --- ScreenSound/Banco/ArtistaDAl.cs | 5 +++++ ScreenSound/Program.cs | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index daf841d..5c523b6 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -36,5 +36,10 @@ public void Deletar(Artista artista) context.Artistas.Remove(artista); context.SaveChanges(); } + + public Artista? RecuperarPeloNome(string nome) + { + return context.Artistas.FirstOrDefault(a => a.Nome.Equals(nome)); + } } } diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index 4abf616..b23a8c4 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -12,7 +12,10 @@ //artistaDAL.Adicionar(novoArtista); - artistaDAL.Deletar(novoArtista); + //artistaDAL.Deletar(novoArtista); + artistaDAL.RecuperarPeloNome("Foo Fighters"); + var artistaRecuperado = artistaDAL.RecuperarPeloNome("Foo Fighters"); + Console.WriteLine($" Artista Recuperado {artistaRecuperado}"); var listaArtistas = artistaDAL.Listar(); foreach ( var artist in listaArtistas ) From 1e015bb8fe62ecedddec90fc0fac7635a87d5e46 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 08:50:54 -0300 Subject: [PATCH 32/85] Alterando assinatura do metodo executar do menu --- ScreenSound/Banco/ArtistaDAl.cs | 4 ++-- ScreenSound/Menus/Menu.cs | 6 ++++-- ScreenSound/Menus/MenuMostrarArtistas.cs | 7 ++++--- ScreenSound/Menus/MenuMostrarMusicas.cs | 7 ++++--- ScreenSound/Menus/MenuRegistrarArtista.cs | 7 ++++--- ScreenSound/Menus/MenuRegistrarMusica.cs | 7 ++++--- ScreenSound/Menus/MenuSair.cs | 5 +++-- ScreenSound/Program.cs | 4 ++-- 8 files changed, 27 insertions(+), 20 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 5c523b6..973114c 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -8,11 +8,11 @@ namespace ScreenSound.Banco { - internal class ArtistaDAl + internal class ArtistaDAL { private readonly ScreenSoundContext context; - public ArtistaDAl(ScreenSoundContext context) + public ArtistaDAL(ScreenSoundContext context) { this.context = context; } diff --git a/ScreenSound/Menus/Menu.cs b/ScreenSound/Menus/Menu.cs index 25db9e7..490202d 100644 --- a/ScreenSound/Menus/Menu.cs +++ b/ScreenSound/Menus/Menu.cs @@ -1,4 +1,5 @@ -using ScreenSound.Modelos; +using ScreenSound.Banco; +using ScreenSound.Modelos; namespace ScreenSound.Menus; @@ -12,8 +13,9 @@ public void ExibirTituloDaOpcao(string titulo) Console.WriteLine(titulo); Console.WriteLine(asteriscos + "\n"); } - public virtual void Executar(Dictionary nusicasRegistradas) + public virtual void Executar(ArtistaDAL artistaDAL) { Console.Clear(); } + } diff --git a/ScreenSound/Menus/MenuMostrarArtistas.cs b/ScreenSound/Menus/MenuMostrarArtistas.cs index 07d992c..1f0a58d 100644 --- a/ScreenSound/Menus/MenuMostrarArtistas.cs +++ b/ScreenSound/Menus/MenuMostrarArtistas.cs @@ -1,12 +1,13 @@ -using ScreenSound.Modelos; +using ScreenSound.Banco; +using ScreenSound.Modelos; namespace ScreenSound.Menus; internal class MenuMostrarArtistas : Menu { - public override void Executar(Dictionary musicasRegistradas) + public override void Executar(ArtistaDAL artistaDAL) { - base.Executar(musicasRegistradas); + base.Executar(artistaDAL); ExibirTituloDaOpcao("Exibindo todos os artistas registradas na nossa aplicação"); foreach (string artista in musicasRegistradas.Keys) diff --git a/ScreenSound/Menus/MenuMostrarMusicas.cs b/ScreenSound/Menus/MenuMostrarMusicas.cs index f176506..2db4502 100644 --- a/ScreenSound/Menus/MenuMostrarMusicas.cs +++ b/ScreenSound/Menus/MenuMostrarMusicas.cs @@ -1,12 +1,13 @@ -using ScreenSound.Modelos; +using ScreenSound.Banco; +using ScreenSound.Modelos; namespace ScreenSound.Menus; internal class MenuMostrarMusicas : Menu { - public override void Executar(Dictionary artistasRegistrados) + public override void Executar(ArtistaDAL artistaDAL) { - base.Executar(artistasRegistrados); + base.Executar(artistaDAL); ExibirTituloDaOpcao("Exibir detalhes do artista"); Console.Write("Digite o nome do artista que deseja conhecer melhor: "); string nomeDoArtista = Console.ReadLine()!; diff --git a/ScreenSound/Menus/MenuRegistrarArtista.cs b/ScreenSound/Menus/MenuRegistrarArtista.cs index e01bfd7..00edab8 100644 --- a/ScreenSound/Menus/MenuRegistrarArtista.cs +++ b/ScreenSound/Menus/MenuRegistrarArtista.cs @@ -1,12 +1,13 @@ -using ScreenSound.Modelos; +using ScreenSound.Banco; +using ScreenSound.Modelos; namespace ScreenSound.Menus; internal class MenuRegistrarArtista : Menu { - public override void Executar(Dictionary artistasRegistrados) + public override void Executar(ArtistaDAL artistaDAL) { - base.Executar(artistasRegistrados); + base.Executar(artistaDAL); ExibirTituloDaOpcao("Registro dos Artistas"); Console.Write("Digite o nome do artista que deseja registrar: "); string nomeDoArtista = Console.ReadLine()!; diff --git a/ScreenSound/Menus/MenuRegistrarMusica.cs b/ScreenSound/Menus/MenuRegistrarMusica.cs index 023caff..ed7564c 100644 --- a/ScreenSound/Menus/MenuRegistrarMusica.cs +++ b/ScreenSound/Menus/MenuRegistrarMusica.cs @@ -1,12 +1,13 @@ -using ScreenSound.Modelos; +using ScreenSound.Banco; +using ScreenSound.Modelos; namespace ScreenSound.Menus; internal class MenuRegistrarMusica : Menu { - public override void Executar(Dictionary artistasRegistrados) + public override void Executar(ArtistaDAL artistaDAL) { - base.Executar(artistasRegistrados); + base.Executar(artistaDAL); ExibirTituloDaOpcao("Registro de músicas"); Console.Write("Digite o artista cuja música deseja registrar: "); string nomeDoArtista = Console.ReadLine()!; diff --git a/ScreenSound/Menus/MenuSair.cs b/ScreenSound/Menus/MenuSair.cs index 0c10e75..5d8c0a8 100644 --- a/ScreenSound/Menus/MenuSair.cs +++ b/ScreenSound/Menus/MenuSair.cs @@ -1,10 +1,11 @@ -using ScreenSound.Modelos; +using ScreenSound.Banco; +using ScreenSound.Modelos; namespace ScreenSound.Menus; internal class MenuSair : Menu { - public override void Executar(Dictionary artistasRegistrados) + public override void Executar(ArtistaDAL artistaDAL) { Console.WriteLine("Tchau tchau :)"); } diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index b23a8c4..54d9eef 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -5,7 +5,7 @@ try { var context = new ScreenSoundContext(); - var artistaDAL = new ArtistaDAl(context); + var artistaDAL = new ArtistaDAL(context); //var novoArtista = new Artista("Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995."); var novoArtista = new Artista("Gilberto Gil", "Gilberto Passos Gil Moreira é um cantor, compositor, multi-instrumentista, produtor musical, político e escritor brasileiro.") { Id = 3}; @@ -73,7 +73,7 @@ void ExibirOpcoesDoMenu() if (opcoes.ContainsKey(opcaoEscolhidaNumerica)) { Menu menuASerExibido = opcoes[opcaoEscolhidaNumerica]; - menuASerExibido.Executar(artistasRegistrados); + menuASerExibido.Executar(artistaDAL); if (opcaoEscolhidaNumerica > 0) ExibirOpcoesDoMenu(); } else From d16734b95ac570bfaad8fd085bd0b4878b92999d Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 08:51:35 -0300 Subject: [PATCH 33/85] Refatorando o metodo mostrar artistas --- ScreenSound/Menus/MenuMostrarArtistas.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScreenSound/Menus/MenuMostrarArtistas.cs b/ScreenSound/Menus/MenuMostrarArtistas.cs index 1f0a58d..16d557f 100644 --- a/ScreenSound/Menus/MenuMostrarArtistas.cs +++ b/ScreenSound/Menus/MenuMostrarArtistas.cs @@ -10,7 +10,7 @@ public override void Executar(ArtistaDAL artistaDAL) base.Executar(artistaDAL); ExibirTituloDaOpcao("Exibindo todos os artistas registradas na nossa aplicação"); - foreach (string artista in musicasRegistradas.Keys) + foreach (var artista in artistaDAL.Listar()) { Console.WriteLine($"Artista: {artista}"); } From e1460f7ecaf9bf791f5e3715eca49cc8daeb70d9 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 08:53:44 -0300 Subject: [PATCH 34/85] Refatorando o metodo mostrar musicas --- ScreenSound/Menus/MenuMostrarMusicas.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ScreenSound/Menus/MenuMostrarMusicas.cs b/ScreenSound/Menus/MenuMostrarMusicas.cs index 2db4502..7a2b31f 100644 --- a/ScreenSound/Menus/MenuMostrarMusicas.cs +++ b/ScreenSound/Menus/MenuMostrarMusicas.cs @@ -11,11 +11,11 @@ public override void Executar(ArtistaDAL artistaDAL) ExibirTituloDaOpcao("Exibir detalhes do artista"); Console.Write("Digite o nome do artista que deseja conhecer melhor: "); string nomeDoArtista = Console.ReadLine()!; - if (artistasRegistrados.ContainsKey(nomeDoArtista)) + var artistaRecuperado = artistaDAL.RecuperarPeloNome(nomeDoArtista); + if (artistaRecuperado is not null) { - Artista artista = artistasRegistrados[nomeDoArtista]; Console.WriteLine("\nDiscografia:"); - artista.ExibirDiscografia(); + artistaRecuperado.ExibirDiscografia(); Console.WriteLine("\nDigite uma tecla para voltar ao menu principal"); Console.ReadKey(); Console.Clear(); From 34ba9b0221605231e00fd5f0d6968dc98f3eff8f Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 08:56:17 -0300 Subject: [PATCH 35/85] Refatorando o metodo registrar artista --- ScreenSound/Menus/MenuRegistrarArtista.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScreenSound/Menus/MenuRegistrarArtista.cs b/ScreenSound/Menus/MenuRegistrarArtista.cs index 00edab8..cb83b81 100644 --- a/ScreenSound/Menus/MenuRegistrarArtista.cs +++ b/ScreenSound/Menus/MenuRegistrarArtista.cs @@ -14,7 +14,7 @@ public override void Executar(ArtistaDAL artistaDAL) Console.Write("Digite a bio do artista que deseja registrar: "); string bioDoArtista = Console.ReadLine()!; Artista artista = new Artista(nomeDoArtista, bioDoArtista); - artistasRegistrados.Add(nomeDoArtista, artista); + artistaDAL.Adicionar(artista); Console.WriteLine($"O artista {nomeDoArtista} foi registrado com sucesso!"); Thread.Sleep(4000); Console.Clear(); From 4eb03f236c1c1d4c06b64eaa66c77ff0c3ae8ea7 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 08:59:20 -0300 Subject: [PATCH 36/85] Refatorando o metodo registrar musica --- ScreenSound/Menus/MenuRegistrarMusica.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ScreenSound/Menus/MenuRegistrarMusica.cs b/ScreenSound/Menus/MenuRegistrarMusica.cs index ed7564c..8e3bdc8 100644 --- a/ScreenSound/Menus/MenuRegistrarMusica.cs +++ b/ScreenSound/Menus/MenuRegistrarMusica.cs @@ -11,12 +11,13 @@ public override void Executar(ArtistaDAL artistaDAL) ExibirTituloDaOpcao("Registro de músicas"); Console.Write("Digite o artista cuja música deseja registrar: "); string nomeDoArtista = Console.ReadLine()!; - if (artistasRegistrados.ContainsKey(nomeDoArtista)) + var artistaRecuperado = artistaDAL.RecuperarPeloNome(nomeDoArtista); + if (artistaRecuperado is not null) { Console.Write("Agora digite o título da música: "); string tituloDaMusica = Console.ReadLine()!; - Artista artista = artistasRegistrados[nomeDoArtista]; - artista.AdicionarMusica(new Musica(tituloDaMusica)); + + artistaRecuperado.AdicionarMusica(new Musica(tituloDaMusica)); Console.WriteLine($"A música {tituloDaMusica} de {nomeDoArtista} foi registrada com sucesso!"); Thread.Sleep(4000); Console.Clear(); From 85fae1aa7fdf05f8dbfbe6b95a99c4508c2b08dd Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 09:11:54 -0300 Subject: [PATCH 37/85] Refatorando programa princiapal --- ScreenSound/Program.cs | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index 54d9eef..ad27376 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -2,39 +2,8 @@ using ScreenSound.Menus; using ScreenSound.Modelos; -try -{ - var context = new ScreenSoundContext(); - var artistaDAL = new ArtistaDAL(context); - - //var novoArtista = new Artista("Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995."); - var novoArtista = new Artista("Gilberto Gil", "Gilberto Passos Gil Moreira é um cantor, compositor, multi-instrumentista, produtor musical, político e escritor brasileiro.") { Id = 3}; - - - //artistaDAL.Adicionar(novoArtista); - //artistaDAL.Deletar(novoArtista); - artistaDAL.RecuperarPeloNome("Foo Fighters"); - var artistaRecuperado = artistaDAL.RecuperarPeloNome("Foo Fighters"); - Console.WriteLine($" Artista Recuperado {artistaRecuperado}"); - var listaArtistas = artistaDAL.Listar(); - - foreach ( var artist in listaArtistas ) - { - Console.WriteLine( artist ); - } -} -catch (Exception ex) -{ - Console.WriteLine(ex.Message); -} -return; - -Artista ira = new Artista("Ira!", "Banda Ira!"); -Artista beatles = new("The Beatles", "Banda The Beatles"); - -Dictionary artistasRegistrados = new(); -artistasRegistrados.Add(ira.Nome, ira); -artistasRegistrados.Add(beatles.Nome, beatles); +var context = new ScreenSoundContext(); +var artistaDAL = new ArtistaDAL(context); Dictionary opcoes = new(); opcoes.Add(1, new MenuRegistrarArtista()); From 9dc501c90bc683c96488d31b9692acb75aea48de Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 14:28:54 -0300 Subject: [PATCH 38/85] Criando a classe MusicaDAL --- ScreenSound/Banco/MusicaDAL.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ScreenSound/Banco/MusicaDAL.cs diff --git a/ScreenSound/Banco/MusicaDAL.cs b/ScreenSound/Banco/MusicaDAL.cs new file mode 100644 index 0000000..cbb056c --- /dev/null +++ b/ScreenSound/Banco/MusicaDAL.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ScreenSound.Banco +{ + internal class MusicaDAL + { + + } +} From ffd2dbb337f4f9815875d4677296b66e8dcdb37f Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 14:31:52 -0300 Subject: [PATCH 39/85] =?UTF-8?q?Criando=20a=20variav=C3=A9l=20para=20o=20?= =?UTF-8?q?context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/MusicaDAL.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScreenSound/Banco/MusicaDAL.cs b/ScreenSound/Banco/MusicaDAL.cs index cbb056c..51ea15e 100644 --- a/ScreenSound/Banco/MusicaDAL.cs +++ b/ScreenSound/Banco/MusicaDAL.cs @@ -8,6 +8,6 @@ namespace ScreenSound.Banco { internal class MusicaDAL { - + private readonly ScreenSoundContext context; } } From fddcb5d6cb062a444453f4a7a224175375bbae73 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 14:48:46 -0300 Subject: [PATCH 40/85] =?UTF-8?q?Mapear=20o=20nome=20da=20classe=20como=20?= =?UTF-8?q?o=20nome=20da=20tabela=20atrav=C3=A9s=20do=20DbSet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/ScreenSoundContext.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ScreenSound/Banco/ScreenSoundContext.cs b/ScreenSound/Banco/ScreenSoundContext.cs index 71113d2..c26ce53 100644 --- a/ScreenSound/Banco/ScreenSoundContext.cs +++ b/ScreenSound/Banco/ScreenSoundContext.cs @@ -12,6 +12,7 @@ namespace ScreenSound.Banco internal class ScreenSoundContext: DbContext { public DbSet Artistas { get; set; } + public DbSet Musica { get; set; } private string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ScreenSound;" + "Integrated Security=True;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + From ea26482c21f440a607d055d78d7c2ef112c37571 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Wed, 20 Mar 2024 14:52:54 -0300 Subject: [PATCH 41/85] =?UTF-8?q?gerando=20construtor=20que=20ir=C3=A1=20p?= =?UTF-8?q?assar=20o=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/MusicaDAL.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ScreenSound/Banco/MusicaDAL.cs b/ScreenSound/Banco/MusicaDAL.cs index 51ea15e..0c3c0f1 100644 --- a/ScreenSound/Banco/MusicaDAL.cs +++ b/ScreenSound/Banco/MusicaDAL.cs @@ -9,5 +9,10 @@ namespace ScreenSound.Banco internal class MusicaDAL { private readonly ScreenSoundContext context; + + public MusicaDAL(ScreenSoundContext context) + { + this.context = context; + } } } From 0138ee22b2695ad2b61c7cb15986cdb5d268c81c Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 10:57:52 -0300 Subject: [PATCH 42/85] metodos Adicionar, Listar, Atualizar, deletar, Recuperar pelo nome para musica --- ScreenSound/Banco/MusicaDAL.cs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Banco/MusicaDAL.cs b/ScreenSound/Banco/MusicaDAL.cs index 0c3c0f1..39b688c 100644 --- a/ScreenSound/Banco/MusicaDAL.cs +++ b/ScreenSound/Banco/MusicaDAL.cs @@ -1,4 +1,5 @@ -using System; +using ScreenSound.Modelos; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,5 +15,28 @@ public MusicaDAL(ScreenSoundContext context) { this.context = context; } + public IEnumerable Listar() + { + return context.Musica.ToList(); + } + public void Adicionar(Musica musica) + { + context.Musica.Add(musica); + context.SaveChanges(); + } + public void Atualizar (Musica musica) + { + context.Musica.Update(musica); + context.SaveChanges(); + } + public void Deletar(Musica musica) + { + context.Musica.Remove(musica); + context.SaveChanges(); + } + public Musica? RecuperarPeloNome(string nome) + { + return context.Musica.FirstOrDefault(a => a.Equals(nome)); + } } } From 8d2d7a22c039e41cd4019975cdf98638db6b250e Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 11:12:29 -0300 Subject: [PATCH 43/85] Criando uma classe generica --- ScreenSound/Banco/DAL.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ScreenSound/Banco/DAL.cs diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs new file mode 100644 index 0000000..775ad4d --- /dev/null +++ b/ScreenSound/Banco/DAL.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ScreenSound.Banco +{ + internal class DAL + { + } +} From 68a53f8d5008b17efdaa2789f92f8327838a951d Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 11:13:23 -0300 Subject: [PATCH 44/85] Tornando a classe abstrata --- ScreenSound/Banco/DAL.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index 775ad4d..3d94409 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -6,7 +6,8 @@ namespace ScreenSound.Banco { - internal class DAL + internal abstract class DAL { + } } From 717f6ec0a92caa99587f04bc77b7464d5588b971 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 11:14:36 -0300 Subject: [PATCH 45/85] Fazendo a classe Artista herdar da classe DAL --- ScreenSound/Banco/ArtistaDAl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 973114c..702569d 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -8,7 +8,7 @@ namespace ScreenSound.Banco { - internal class ArtistaDAL + internal class ArtistaDAL : DAL { private readonly ScreenSoundContext context; From 4da719805660fddd1da94004395e70a9365859b0 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 21:42:10 -0300 Subject: [PATCH 46/85] criando os metodos abstratos da classe DAL --- ScreenSound/Banco/ArtistaDAl.cs | 4 ++-- ScreenSound/Banco/DAL.cs | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 702569d..1d94f3d 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -8,7 +8,7 @@ namespace ScreenSound.Banco { - internal class ArtistaDAL : DAL + internal class ArtistaDAL : DAL { private readonly ScreenSoundContext context; @@ -17,7 +17,7 @@ public ArtistaDAL(ScreenSoundContext context) this.context = context; } - public IEnumerable Listar() + public override IEnumerable Listar() { return context.Artistas.ToList(); } diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index 3d94409..289528f 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -1,4 +1,5 @@ -using System; +using ScreenSound.Modelos; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,8 +7,14 @@ namespace ScreenSound.Banco { - internal abstract class DAL + internal abstract class DAL { + public abstract IEnumerable Listar(); + public abstract void Adicionar(T objeto); + + public abstract void Atualizar(T objeto); + + public abstract void Deletar(T objeto); } } From 367f282d2c2f3d97aa2bd16ff84673d5b92c1987 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 21:48:33 -0300 Subject: [PATCH 47/85] =?UTF-8?q?informando=20que=20o=20DAL=20ser=C3=A1=20?= =?UTF-8?q?do=20tipo=20=20e=20sobrescrevendo=20os=20metodos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/ArtistaDAl.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 1d94f3d..4adcfb1 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -8,7 +8,7 @@ namespace ScreenSound.Banco { - internal class ArtistaDAL : DAL + internal class ArtistaDAL: DAL { private readonly ScreenSoundContext context; @@ -21,17 +21,17 @@ public override IEnumerable Listar() { return context.Artistas.ToList(); } - public void Adicionar(Artista artista) + public override void Adicionar(Artista artista) { context.Artistas.Add(artista); context.SaveChanges(); } - public void Atualizar(Artista artista) + public override void Atualizar(Artista artista) { context.Artistas.Update(artista); context.SaveChanges(); } - public void Deletar(Artista artista) + public override void Deletar(Artista artista) { context.Artistas.Remove(artista); context.SaveChanges(); From 8e5e46590e844058d2e41208fef8309ef4d45ce1 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 21:59:24 -0300 Subject: [PATCH 48/85] trazendo context de Artista para classe DAL --- ScreenSound/Banco/ArtistaDAL.cs | 45 +++++++++++++++++++++++++++++++++ ScreenSound/Banco/DAL.cs | 4 ++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 ScreenSound/Banco/ArtistaDAL.cs diff --git a/ScreenSound/Banco/ArtistaDAL.cs b/ScreenSound/Banco/ArtistaDAL.cs new file mode 100644 index 0000000..e694605 --- /dev/null +++ b/ScreenSound/Banco/ArtistaDAL.cs @@ -0,0 +1,45 @@ +using Microsoft.Data.SqlClient; +using ScreenSound.Modelos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ScreenSound.Banco +{ + internal class ArtistaDAL: DAL + { + + + public ArtistaDAL(ScreenSoundContext context) + { + this.context = context; + } + + public override IEnumerable Listar() + { + return context.Artistas.ToList(); + } + public override void Adicionar(Artista artista) + { + context.Artistas.Add(artista); + context.SaveChanges(); + } + public override void Atualizar(Artista artista) + { + context.Artistas.Update(artista); + context.SaveChanges(); + } + public override void Deletar(Artista artista) + { + context.Artistas.Remove(artista); + context.SaveChanges(); + } + + public Artista? RecuperarPeloNome(string nome) + { + return context.Artistas.FirstOrDefault(a => a.Nome.Equals(nome)); + } + } +} diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index 289528f..c266d23 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -8,7 +8,9 @@ namespace ScreenSound.Banco { internal abstract class DAL - { + { + private readonly ScreenSoundContext context; + public abstract IEnumerable Listar(); public abstract void Adicionar(T objeto); From 33008d718a7be935a2d73ea296bc4da834d020f4 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 21:59:48 -0300 Subject: [PATCH 49/85] criando cosntrutor na classe DAL --- ScreenSound/Banco/ArtistaDAl.cs | 2 +- ScreenSound/Banco/DAL.cs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 4adcfb1..e694605 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -10,7 +10,7 @@ namespace ScreenSound.Banco { internal class ArtistaDAL: DAL { - private readonly ScreenSoundContext context; + public ArtistaDAL(ScreenSoundContext context) { diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index c266d23..d74ed01 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -10,7 +10,12 @@ namespace ScreenSound.Banco internal abstract class DAL { private readonly ScreenSoundContext context; - + + protected DAL(ScreenSoundContext context) + { + this.context = context; + } + public abstract IEnumerable Listar(); public abstract void Adicionar(T objeto); From 55d236ca43c8aae8dfc629edb8b7b9c01c40c5c8 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 22:01:22 -0300 Subject: [PATCH 50/85] Fazendo o construtor de Artista herdar o context --- ScreenSound/Banco/ArtistaDAL.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAL.cs b/ScreenSound/Banco/ArtistaDAL.cs index e694605..28a0f4c 100644 --- a/ScreenSound/Banco/ArtistaDAL.cs +++ b/ScreenSound/Banco/ArtistaDAL.cs @@ -9,13 +9,9 @@ namespace ScreenSound.Banco { internal class ArtistaDAL: DAL - { - + { - public ArtistaDAL(ScreenSoundContext context) - { - this.context = context; - } + public ArtistaDAL(ScreenSoundContext context) : base(context) { } public override IEnumerable Listar() { From c0ebbd69b8cc366d9141ba8397b33106b2035fb7 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 22:16:43 -0300 Subject: [PATCH 51/85] metodo listar generico --- ScreenSound/Banco/ArtistaDAl.cs | 8 ++------ ScreenSound/Banco/DAL.cs | 5 ++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index e694605..28a0f4c 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -9,13 +9,9 @@ namespace ScreenSound.Banco { internal class ArtistaDAL: DAL - { - + { - public ArtistaDAL(ScreenSoundContext context) - { - this.context = context; - } + public ArtistaDAL(ScreenSoundContext context) : base(context) { } public override IEnumerable Listar() { diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index d74ed01..3ac8582 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -16,7 +16,10 @@ protected DAL(ScreenSoundContext context) this.context = context; } - public abstract IEnumerable Listar(); + public IEnumerable Listar() + { + return context.Set().ToList(); + } public abstract void Adicionar(T objeto); public abstract void Atualizar(T objeto); From a3636c158dd82fb2ede1ffd7be98376b34641664 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 22:18:26 -0300 Subject: [PATCH 52/85] =?UTF-8?q?Informando=20que=20o=20T=20ser=C3=A1=20um?= =?UTF-8?q?a=20clase=20dentro=20da=20nossa=20aplica=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/DAL.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index 3ac8582..4ba02a7 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -7,7 +7,7 @@ namespace ScreenSound.Banco { - internal abstract class DAL + internal abstract class DAL where T : class { private readonly ScreenSoundContext context; From e776aec96fa59c399491e08ede9bbe102ddfc7bb Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 22:27:15 -0300 Subject: [PATCH 53/85] trazendo os outros metodos do Artista para a classe generica DAL --- ScreenSound/Banco/ArtistaDAL.cs | 22 +--------------------- ScreenSound/Banco/DAL.cs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAL.cs b/ScreenSound/Banco/ArtistaDAL.cs index 28a0f4c..8c0900d 100644 --- a/ScreenSound/Banco/ArtistaDAL.cs +++ b/ScreenSound/Banco/ArtistaDAL.cs @@ -11,27 +11,7 @@ namespace ScreenSound.Banco internal class ArtistaDAL: DAL { - public ArtistaDAL(ScreenSoundContext context) : base(context) { } - - public override IEnumerable Listar() - { - return context.Artistas.ToList(); - } - public override void Adicionar(Artista artista) - { - context.Artistas.Add(artista); - context.SaveChanges(); - } - public override void Atualizar(Artista artista) - { - context.Artistas.Update(artista); - context.SaveChanges(); - } - public override void Deletar(Artista artista) - { - context.Artistas.Remove(artista); - context.SaveChanges(); - } + public ArtistaDAL(ScreenSoundContext context) : base(context) { } public Artista? RecuperarPeloNome(string nome) { diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index 4ba02a7..912ed59 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -20,11 +20,23 @@ public IEnumerable Listar() { return context.Set().ToList(); } - public abstract void Adicionar(T objeto); + public void Adicionar(T objeto) + { + context.Set().Add(objeto); + context.SaveChanges(); + } - public abstract void Atualizar(T objeto); + public void Atualizar(T objeto) + { + context.Set().Update(objeto); + context.SaveChanges(); + } - public abstract void Deletar(T objeto); + public void Deletar(T objeto) + { + context.Set().Remove(objeto); + context.SaveChanges(); + } } } From d8bfeb7ba5929dfa439067f3c8bba6f2203b0537 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 22 Mar 2024 22:28:11 -0300 Subject: [PATCH 54/85] mudando o context para protected para ser visivel na classe Artista --- ScreenSound/Banco/ArtistaDAl.cs | 22 +--------------------- ScreenSound/Banco/DAL.cs | 2 +- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs index 28a0f4c..8c0900d 100644 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ b/ScreenSound/Banco/ArtistaDAl.cs @@ -11,27 +11,7 @@ namespace ScreenSound.Banco internal class ArtistaDAL: DAL { - public ArtistaDAL(ScreenSoundContext context) : base(context) { } - - public override IEnumerable Listar() - { - return context.Artistas.ToList(); - } - public override void Adicionar(Artista artista) - { - context.Artistas.Add(artista); - context.SaveChanges(); - } - public override void Atualizar(Artista artista) - { - context.Artistas.Update(artista); - context.SaveChanges(); - } - public override void Deletar(Artista artista) - { - context.Artistas.Remove(artista); - context.SaveChanges(); - } + public ArtistaDAL(ScreenSoundContext context) : base(context) { } public Artista? RecuperarPeloNome(string nome) { diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index 912ed59..4a2c2d6 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -9,7 +9,7 @@ namespace ScreenSound.Banco { internal abstract class DAL where T : class { - private readonly ScreenSoundContext context; + protected readonly ScreenSoundContext context; protected DAL(ScreenSoundContext context) { From b6f3a29758ed97e7a168351b5be128c67187ef60 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 23 Mar 2024 19:16:14 -0300 Subject: [PATCH 55/85] Criando o metodo recuperar por --- ScreenSound/Banco/ArtistaDAL.cs | 5 ----- ScreenSound/Banco/DAL.cs | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ScreenSound/Banco/ArtistaDAL.cs b/ScreenSound/Banco/ArtistaDAL.cs index 8c0900d..fe49919 100644 --- a/ScreenSound/Banco/ArtistaDAL.cs +++ b/ScreenSound/Banco/ArtistaDAL.cs @@ -12,10 +12,5 @@ internal class ArtistaDAL: DAL { public ArtistaDAL(ScreenSoundContext context) : base(context) { } - - public Artista? RecuperarPeloNome(string nome) - { - return context.Artistas.FirstOrDefault(a => a.Nome.Equals(nome)); - } } } diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index 4a2c2d6..bfacad1 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -37,6 +37,10 @@ public void Deletar(T objeto) context.Set().Remove(objeto); context.SaveChanges(); } + public T? RecuperarPor(Func condicao) + { + return context.Set().FirstOrDefault(condicao); + } } } From b6f16c222ebb325d2ae4f3c61257291eb4f6e2b8 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 23 Mar 2024 19:31:39 -0300 Subject: [PATCH 56/85] =?UTF-8?q?excluindo=20metodos=20desnecess=C3=A1rios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/ArtistaDAL.cs | 16 ------------- ScreenSound/Banco/MusicaDAL.cs | 42 --------------------------------- 2 files changed, 58 deletions(-) delete mode 100644 ScreenSound/Banco/ArtistaDAL.cs delete mode 100644 ScreenSound/Banco/MusicaDAL.cs diff --git a/ScreenSound/Banco/ArtistaDAL.cs b/ScreenSound/Banco/ArtistaDAL.cs deleted file mode 100644 index fe49919..0000000 --- a/ScreenSound/Banco/ArtistaDAL.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.Data.SqlClient; -using ScreenSound.Modelos; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ScreenSound.Banco -{ - internal class ArtistaDAL: DAL - { - - public ArtistaDAL(ScreenSoundContext context) : base(context) { } - } -} diff --git a/ScreenSound/Banco/MusicaDAL.cs b/ScreenSound/Banco/MusicaDAL.cs deleted file mode 100644 index 39b688c..0000000 --- a/ScreenSound/Banco/MusicaDAL.cs +++ /dev/null @@ -1,42 +0,0 @@ -using ScreenSound.Modelos; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ScreenSound.Banco -{ - internal class MusicaDAL - { - private readonly ScreenSoundContext context; - - public MusicaDAL(ScreenSoundContext context) - { - this.context = context; - } - public IEnumerable Listar() - { - return context.Musica.ToList(); - } - public void Adicionar(Musica musica) - { - context.Musica.Add(musica); - context.SaveChanges(); - } - public void Atualizar (Musica musica) - { - context.Musica.Update(musica); - context.SaveChanges(); - } - public void Deletar(Musica musica) - { - context.Musica.Remove(musica); - context.SaveChanges(); - } - public Musica? RecuperarPeloNome(string nome) - { - return context.Musica.FirstOrDefault(a => a.Equals(nome)); - } - } -} From f52bc0501023ce94510fe70b446285c7920ffad2 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 23 Mar 2024 19:41:29 -0300 Subject: [PATCH 57/85] =?UTF-8?q?a=20classe=20DAL=20n=C3=A3o=20=C3=A9=20am?= =?UTF-8?q?is=20abstrata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/ArtistaDAl.cs | 21 --------------------- ScreenSound/Banco/DAL.cs | 2 +- 2 files changed, 1 insertion(+), 22 deletions(-) delete mode 100644 ScreenSound/Banco/ArtistaDAl.cs diff --git a/ScreenSound/Banco/ArtistaDAl.cs b/ScreenSound/Banco/ArtistaDAl.cs deleted file mode 100644 index 8c0900d..0000000 --- a/ScreenSound/Banco/ArtistaDAl.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.Data.SqlClient; -using ScreenSound.Modelos; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ScreenSound.Banco -{ - internal class ArtistaDAL: DAL - { - - public ArtistaDAL(ScreenSoundContext context) : base(context) { } - - public Artista? RecuperarPeloNome(string nome) - { - return context.Artistas.FirstOrDefault(a => a.Nome.Equals(nome)); - } - } -} diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index bfacad1..be75a04 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -7,7 +7,7 @@ namespace ScreenSound.Banco { - internal abstract class DAL where T : class + public class DAL where T : class { protected readonly ScreenSoundContext context; From 9bdd2485260eca1405e2b334eb86ab02affe36d6 Mon Sep 17 00:00:00 2001 From: Wesley schuab Vieira <58818125+WesleySchuab@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:18:16 -0300 Subject: [PATCH 58/85] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Detalhando dependências que precisam ser instaladas --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9908a1c..f5d2a16 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,12 @@ Nessa janela do Pesquisador de Objetos é onde vamos conseguir gerenciar o nosso Após pressionar "Enter" ou clicar em "OK", aparecerá na lista de bancos à esquerda todos os bancos disponíveis, inclusive o ScreenSound que acabamos de criar. Segundo Passo -instalar o pacote: Microsoft.Data.SqlClient -No Visual Studio, vamos em "Ferramentas > Gerenciador de Pacotes do NuGet > Gerenciar Pacotes do NuGet para a Solução…". Na aba "Procurar", vamos pesquisar por "SQL Client". +instalar os pacotes: Microsoft.Data.SqlClient 5.1.2, Microsoft Entity Framework Core Design 7.013 , Microsoft Entity Framework Core Tools7.013 e Microsoft Entity Framework Core.SqlServer 7.0.13. -O primeiro exibido será o Microsoft.Data.SqlClient, o qual utilizaremos em nosso projeto para estabelecer o vínculo do banco de dados com o projeto em si. À direita, vamos marcar o projeto ScreenSound e clicar em "Instalar". Para concluir, devemos aceitar as licenças. +Exemplo com Microsoft.Data.SqlClient no Visual Studio, vamos em "Ferramentas > Gerenciador de Pacotes do NuGet > Gerenciar Pacotes do NuGet para a Solução…". Na aba "Procurar", vamos pesquisar por "SQL Client". O primeiro exibido será o Microsoft.Data.SqlClient, o qual utilizaremos em nosso projeto para estabelecer o vínculo do banco de dados com o projeto em si. À direita, vamos marcar o projeto ScreenSound e clicar em "Instalar". Para concluir, devemos aceitar as licenças. Para fazer a conexão, precisamos passar o caminho onde está o banco de dados e mais algumas outras informações de configuração. Para localizar essas informações, vamos ao Pesquisador de Objetos do SQL Server, clicamos com o botão direito sobre o banco de dados ScreenSound e vamos em "Propriedades". + Na lateral direita, aparecerão várias informações de propriedade. Precisamos da "Cadeia de conexão". Vamos copiar as informações desse campo para usá-las na classe Connection. Feito isso, precisamos trazer essas informações. Elas serão a nossa string de conexão. Portanto, podemos criar um private string que se chamará connectionString. Após o igual (=), passaremos todas as informações copiadas das propriedades do banco. Vamos apenas remover o Connect Timeout que vem por padrão 30, para que a execução seja um pouco mais rápida. From 03416dfdcbf13ab18ebd36a6418bef87f6b0f8e2 Mon Sep 17 00:00:00 2001 From: Wesley schuab Vieira <58818125+WesleySchuab@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:22:04 -0300 Subject: [PATCH 59/85] Detalhes para usar as migration --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index f5d2a16..3d431a7 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,15 @@ Para fazer a conexão, precisamos passar o caminho onde está o banco de dados e Na lateral direita, aparecerão várias informações de propriedade. Precisamos da "Cadeia de conexão". Vamos copiar as informações desse campo para usá-las na classe Connection. Feito isso, precisamos trazer essas informações. Elas serão a nossa string de conexão. Portanto, podemos criar um private string que se chamará connectionString. Após o igual (=), passaremos todas as informações copiadas das propriedades do banco. Vamos apenas remover o Connect Timeout que vem por padrão 30, para que a execução seja um pouco mais rápida. + +Adicionar migration +Com os pacotes instalados, precisamos adicionar a primeira migration ao nosso projeto. + +Para fazer isso, vamos em "Ferramentas > Gerenciador de pacotes do NuGet > Console do gerenciador de pacotes". É nesse console que vamos executar os comandos relacionados às migrations. Primeiramente, vamos adicionar essa migration inicial, que é referente ao status inicial do nosso banco. Vamos usar o comando Add. + +Quando escrevemos "Add", se pressionarmos "Tab", ele já começa a sugerir algumas opções. Podemos começar a escrever migration, e a sugestão de que queremos usar essa migration irá aparecer. + +Vamos usar "Tab" novamente para ele autocompletar e também precisamos informar qual será o nome inicial, o nome da nossa primeira migration. Podemos colocar projeto inicial. + +Add-Migration projetoInicial +As migrations são um recurso do Entity que nos permite gerenciar tanto a estrutura do nosso banco quanto as diferentes versões que ele terá durante o projeto, sem precisar mexer nos scripts SQL. From 0a87513da03c86a76a675615ab31ca8595a8f530 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 29 Mar 2024 18:08:03 -0300 Subject: [PATCH 60/85] Corrigindo as assinaturas --- ScreenSound/Banco/DAL.cs | 65 +++++++++++------------ ScreenSound/Menus/Menu.cs | 3 +- ScreenSound/Menus/MenuMostrarArtistas.cs | 2 +- ScreenSound/Menus/MenuMostrarMusicas.cs | 4 +- ScreenSound/Menus/MenuRegistrarArtista.cs | 2 +- ScreenSound/Menus/MenuRegistrarMusica.cs | 5 +- ScreenSound/Menus/MenuSair.cs | 2 +- 7 files changed, 38 insertions(+), 45 deletions(-) diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index be75a04..ac04579 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -1,46 +1,41 @@ -using ScreenSound.Modelos; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ScreenSound.Banco +namespace ScreenSound.Banco; +internal class DAL where T : class { - public class DAL where T : class - { - protected readonly ScreenSoundContext context; + protected readonly ScreenSoundContext context; - protected DAL(ScreenSoundContext context) - { - this.context = context; - } - - public IEnumerable Listar() - { - return context.Set().ToList(); - } - public void Adicionar(T objeto) - { - context.Set().Add(objeto); - context.SaveChanges(); - } - - public void Atualizar(T objeto) - { - context.Set().Update(objeto); - context.SaveChanges(); - } + public DAL(ScreenSoundContext context) + { + this.context = context; + } - public void Deletar(T objeto) - { - context.Set().Remove(objeto); - context.SaveChanges(); - } - public T? RecuperarPor(Func condicao) - { - return context.Set().FirstOrDefault(condicao); - } + public IEnumerable Listar() + { + return context.Set().ToList(); + } + public void Adicionar(T objeto) + { + context.Set().Add(objeto); + context.SaveChanges(); + } + public void Atualizar(T objeto) + { + context.Set().Update(objeto); + context.SaveChanges(); + } + public void Deletar(T objeto) + { + context.Set().Remove(objeto); + context.SaveChanges(); + } + public T? RecuperarPor(Func condicao) + { + return context.Set().FirstOrDefault(condicao); } } diff --git a/ScreenSound/Menus/Menu.cs b/ScreenSound/Menus/Menu.cs index 490202d..a336b1b 100644 --- a/ScreenSound/Menus/Menu.cs +++ b/ScreenSound/Menus/Menu.cs @@ -13,9 +13,8 @@ public void ExibirTituloDaOpcao(string titulo) Console.WriteLine(titulo); Console.WriteLine(asteriscos + "\n"); } - public virtual void Executar(ArtistaDAL artistaDAL) + public virtual void Executar(DAL artistaDAL) { Console.Clear(); } - } diff --git a/ScreenSound/Menus/MenuMostrarArtistas.cs b/ScreenSound/Menus/MenuMostrarArtistas.cs index 16d557f..4f00ece 100644 --- a/ScreenSound/Menus/MenuMostrarArtistas.cs +++ b/ScreenSound/Menus/MenuMostrarArtistas.cs @@ -5,7 +5,7 @@ namespace ScreenSound.Menus; internal class MenuMostrarArtistas : Menu { - public override void Executar(ArtistaDAL artistaDAL) + public override void Executar(DAL artistaDAL) { base.Executar(artistaDAL); ExibirTituloDaOpcao("Exibindo todos os artistas registradas na nossa aplicação"); diff --git a/ScreenSound/Menus/MenuMostrarMusicas.cs b/ScreenSound/Menus/MenuMostrarMusicas.cs index 7a2b31f..634cdce 100644 --- a/ScreenSound/Menus/MenuMostrarMusicas.cs +++ b/ScreenSound/Menus/MenuMostrarMusicas.cs @@ -5,13 +5,13 @@ namespace ScreenSound.Menus; internal class MenuMostrarMusicas : Menu { - public override void Executar(ArtistaDAL artistaDAL) + public override void Executar(DAL artistaDAL) { base.Executar(artistaDAL); ExibirTituloDaOpcao("Exibir detalhes do artista"); Console.Write("Digite o nome do artista que deseja conhecer melhor: "); string nomeDoArtista = Console.ReadLine()!; - var artistaRecuperado = artistaDAL.RecuperarPeloNome(nomeDoArtista); + var artistaRecuperado = artistaDAL.RecuperarPor(a => a.Nome.Equals(nomeDoArtista)); if (artistaRecuperado is not null) { Console.WriteLine("\nDiscografia:"); diff --git a/ScreenSound/Menus/MenuRegistrarArtista.cs b/ScreenSound/Menus/MenuRegistrarArtista.cs index cb83b81..10aae0d 100644 --- a/ScreenSound/Menus/MenuRegistrarArtista.cs +++ b/ScreenSound/Menus/MenuRegistrarArtista.cs @@ -5,7 +5,7 @@ namespace ScreenSound.Menus; internal class MenuRegistrarArtista : Menu { - public override void Executar(ArtistaDAL artistaDAL) + public override void Executar(DAL artistaDAL) { base.Executar(artistaDAL); ExibirTituloDaOpcao("Registro dos Artistas"); diff --git a/ScreenSound/Menus/MenuRegistrarMusica.cs b/ScreenSound/Menus/MenuRegistrarMusica.cs index 8e3bdc8..e94d1b6 100644 --- a/ScreenSound/Menus/MenuRegistrarMusica.cs +++ b/ScreenSound/Menus/MenuRegistrarMusica.cs @@ -5,18 +5,17 @@ namespace ScreenSound.Menus; internal class MenuRegistrarMusica : Menu { - public override void Executar(ArtistaDAL artistaDAL) + public override void Executar(DAL artistaDAL) { base.Executar(artistaDAL); ExibirTituloDaOpcao("Registro de músicas"); Console.Write("Digite o artista cuja música deseja registrar: "); string nomeDoArtista = Console.ReadLine()!; - var artistaRecuperado = artistaDAL.RecuperarPeloNome(nomeDoArtista); + var artistaRecuperado = artistaDAL.RecuperarPor(a => a.Nome.Equals(nomeDoArtista)); if (artistaRecuperado is not null) { Console.Write("Agora digite o título da música: "); string tituloDaMusica = Console.ReadLine()!; - artistaRecuperado.AdicionarMusica(new Musica(tituloDaMusica)); Console.WriteLine($"A música {tituloDaMusica} de {nomeDoArtista} foi registrada com sucesso!"); Thread.Sleep(4000); diff --git a/ScreenSound/Menus/MenuSair.cs b/ScreenSound/Menus/MenuSair.cs index 5d8c0a8..c4d4dca 100644 --- a/ScreenSound/Menus/MenuSair.cs +++ b/ScreenSound/Menus/MenuSair.cs @@ -5,7 +5,7 @@ namespace ScreenSound.Menus; internal class MenuSair : Menu { - public override void Executar(ArtistaDAL artistaDAL) + public override void Executar(DAL artistaDAL) { Console.WriteLine("Tchau tchau :)"); } From c4528b9e262bb482d367d3be4c51512571e4f4d5 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 29 Mar 2024 18:10:48 -0300 Subject: [PATCH 61/85] Corrigindo o programa principal --- ScreenSound/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index ad27376..21a359f 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -3,7 +3,7 @@ using ScreenSound.Modelos; var context = new ScreenSoundContext(); -var artistaDAL = new ArtistaDAL(context); +var artistaDAL = new DAL(context); Dictionary opcoes = new(); opcoes.Add(1, new MenuRegistrarArtista()); @@ -44,7 +44,7 @@ void ExibirOpcoesDoMenu() Menu menuASerExibido = opcoes[opcaoEscolhidaNumerica]; menuASerExibido.Executar(artistaDAL); if (opcaoEscolhidaNumerica > 0) ExibirOpcoesDoMenu(); - } + } else { Console.WriteLine("Opção inválida"); From d59ae0b6a68b0acc440c7e297eafdfc8b68f508e Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 29 Mar 2024 18:20:53 -0300 Subject: [PATCH 62/85] Adicionando a migration projeto inicial --- .../20240329212013_projetoInicial.Designer.cs | 71 +++++++++++++++++++ .../20240329212013_projetoInicial.cs | 52 ++++++++++++++ .../ScreenSoundContextModelSnapshot.cs | 68 ++++++++++++++++++ ScreenSound/ScreenSound.csproj | 8 +++ 4 files changed, 199 insertions(+) create mode 100644 ScreenSound/Migrations/20240329212013_projetoInicial.Designer.cs create mode 100644 ScreenSound/Migrations/20240329212013_projetoInicial.cs create mode 100644 ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs diff --git a/ScreenSound/Migrations/20240329212013_projetoInicial.Designer.cs b/ScreenSound/Migrations/20240329212013_projetoInicial.Designer.cs new file mode 100644 index 0000000..c6388e1 --- /dev/null +++ b/ScreenSound/Migrations/20240329212013_projetoInicial.Designer.cs @@ -0,0 +1,71 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ScreenSound.Banco; + +#nullable disable + +namespace ScreenSound.Migrations +{ + [DbContext(typeof(ScreenSoundContext))] + [Migration("20240329212013_projetoInicial")] + partial class projetoInicial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ScreenSound.Modelos.Artista", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Bio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FotoPerfil") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Artistas"); + }); + + modelBuilder.Entity("ScreenSound.Modelos.Musica", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Musica"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ScreenSound/Migrations/20240329212013_projetoInicial.cs b/ScreenSound/Migrations/20240329212013_projetoInicial.cs new file mode 100644 index 0000000..07dbede --- /dev/null +++ b/ScreenSound/Migrations/20240329212013_projetoInicial.cs @@ -0,0 +1,52 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ScreenSound.Migrations +{ + /// + public partial class projetoInicial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Artistas", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Nome = table.Column(type: "nvarchar(max)", nullable: false), + FotoPerfil = table.Column(type: "nvarchar(max)", nullable: false), + Bio = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Artistas", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Musica", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Nome = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Musica", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Artistas"); + + migrationBuilder.DropTable( + name: "Musica"); + } + } +} diff --git a/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs b/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs new file mode 100644 index 0000000..1492195 --- /dev/null +++ b/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs @@ -0,0 +1,68 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ScreenSound.Banco; + +#nullable disable + +namespace ScreenSound.Migrations +{ + [DbContext(typeof(ScreenSoundContext))] + partial class ScreenSoundContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ScreenSound.Modelos.Artista", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Bio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FotoPerfil") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Artistas"); + }); + + modelBuilder.Entity("ScreenSound.Modelos.Musica", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Musica"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ScreenSound/ScreenSound.csproj b/ScreenSound/ScreenSound.csproj index e4122e6..355a435 100644 --- a/ScreenSound/ScreenSound.csproj +++ b/ScreenSound/ScreenSound.csproj @@ -13,7 +13,15 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From da586b377488739b1b845e90f63e088143e4d25e Mon Sep 17 00:00:00 2001 From: Wesley schuab Vieira <58818125+WesleySchuab@users.noreply.github.com> Date: Fri, 29 Mar 2024 21:17:41 -0300 Subject: [PATCH 63/85] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Corrigindo as versões --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d431a7..e7d0f5e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ Nessa janela do Pesquisador de Objetos é onde vamos conseguir gerenciar o nosso Após pressionar "Enter" ou clicar em "OK", aparecerá na lista de bancos à esquerda todos os bancos disponíveis, inclusive o ScreenSound que acabamos de criar. Segundo Passo -instalar os pacotes: Microsoft.Data.SqlClient 5.1.2, Microsoft Entity Framework Core Design 7.013 , Microsoft Entity Framework Core Tools7.013 e Microsoft Entity Framework Core.SqlServer 7.0.13. +instalar os pacotes: +Microsoft.Data.SqlClient 5.1.2, Microsoft Entity Framework Core Design 7.014 , Microsoft Entity Framework Core Tools7.014 e Microsoft Entity Framework Core.SqlServer 7.0.14. Exemplo com Microsoft.Data.SqlClient no Visual Studio, vamos em "Ferramentas > Gerenciador de Pacotes do NuGet > Gerenciar Pacotes do NuGet para a Solução…". Na aba "Procurar", vamos pesquisar por "SQL Client". O primeiro exibido será o Microsoft.Data.SqlClient, o qual utilizaremos em nosso projeto para estabelecer o vínculo do banco de dados com o projeto em si. À direita, vamos marcar o projeto ScreenSound e clicar em "Instalar". Para concluir, devemos aceitar as licenças. Para fazer a conexão, precisamos passar o caminho onde está o banco de dados e mais algumas outras informações de configuração. Para localizar essas informações, vamos ao Pesquisador de Objetos do SQL Server, clicamos com o botão direito sobre o banco de dados ScreenSound e vamos em "Propriedades". From b57b13fc7aa52d45c52e880c736196855356739e Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 29 Mar 2024 18:26:24 -0300 Subject: [PATCH 64/85] =?UTF-8?q?Alterando=20banco=20para=20come=C3=A7ar?= =?UTF-8?q?=20do=20zero=20e=20n=C3=A3o=20dar=20conflito=20com=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/ScreenSoundContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScreenSound/Banco/ScreenSoundContext.cs b/ScreenSound/Banco/ScreenSoundContext.cs index c26ce53..a526995 100644 --- a/ScreenSound/Banco/ScreenSoundContext.cs +++ b/ScreenSound/Banco/ScreenSoundContext.cs @@ -14,7 +14,7 @@ internal class ScreenSoundContext: DbContext public DbSet Artistas { get; set; } public DbSet Musica { get; set; } - private string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ScreenSound;" + + private string connectionString = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ScreenSoundV0;" + "Integrated Security=True;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;" + "Multi Subnet Failover=False"; protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) From d52246163491b160a0d73d3a88d4bff1bafac87a Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 30 Mar 2024 16:47:18 -0300 Subject: [PATCH 65/85] usando o comando Add-Migration PopularTabela --- .../20240330194357_PopularTabela.Designer.cs | 71 +++++++++++++++++++ .../20240330194357_PopularTabela.cs | 22 ++++++ 2 files changed, 93 insertions(+) create mode 100644 ScreenSound/Migrations/20240330194357_PopularTabela.Designer.cs create mode 100644 ScreenSound/Migrations/20240330194357_PopularTabela.cs diff --git a/ScreenSound/Migrations/20240330194357_PopularTabela.Designer.cs b/ScreenSound/Migrations/20240330194357_PopularTabela.Designer.cs new file mode 100644 index 0000000..6b0de9d --- /dev/null +++ b/ScreenSound/Migrations/20240330194357_PopularTabela.Designer.cs @@ -0,0 +1,71 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ScreenSound.Banco; + +#nullable disable + +namespace ScreenSound.Migrations +{ + [DbContext(typeof(ScreenSoundContext))] + [Migration("20240330194357_PopularTabela")] + partial class PopularTabela + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ScreenSound.Modelos.Artista", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Bio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FotoPerfil") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Artistas"); + }); + + modelBuilder.Entity("ScreenSound.Modelos.Musica", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Musica"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ScreenSound/Migrations/20240330194357_PopularTabela.cs b/ScreenSound/Migrations/20240330194357_PopularTabela.cs new file mode 100644 index 0000000..9e9da99 --- /dev/null +++ b/ScreenSound/Migrations/20240330194357_PopularTabela.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ScreenSound.Migrations +{ + /// + public partial class PopularTabela : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} From a772630e8894418b17054b1e2eac0a3dddfe14e8 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 30 Mar 2024 16:52:59 -0300 Subject: [PATCH 66/85] =?UTF-8?q?Inserindo=20informa=C3=A7=C3=B5es=20no=20?= =?UTF-8?q?Banco?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Migrations/20240330194357_PopularTabela.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ScreenSound/Migrations/20240330194357_PopularTabela.cs b/ScreenSound/Migrations/20240330194357_PopularTabela.cs index 9e9da99..ee6556b 100644 --- a/ScreenSound/Migrations/20240330194357_PopularTabela.cs +++ b/ScreenSound/Migrations/20240330194357_PopularTabela.cs @@ -10,9 +10,22 @@ public partial class PopularTabela : Migration /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.InsertData("Artistas", new string[] { "Nome", "Bio", "FotoPerfil" }, new object[] { "Djavan", "Djavan Caetano Viana é um cantor, compositor, arranjador, produtor musical, empresário, violonista e ex-futebolista brasileiro.", "https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png" }); + migrationBuilder.InsertData("Artistas", new string[] { "Nome", "Bio", "FotoPerfil" }, new object[] { "Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995.", "https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png" }); + + migrationBuilder.InsertData("Artistas", new string[] { "Nome", "Bio", "FotoPerfil" }, new object[] { "Pitty", "Priscilla Novaes Leone, mais conhecida como Pitty, é uma cantora, compositora, produtora, escritora, empresária, apresentadora e multi-instrumentista brasileira.", "https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png" }); + + migrationBuilder.InsertData("Artistas", new string[] { "Nome", "Bio", "FotoPerfil" }, new object[] { "Gilberto Gil", "Gilberto Passos Gil Moreira é um cantor, compositor, multi-instrumentista, produtor musical, político e escritor brasileiro.", "https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png" }); + + migrationBuilder.InsertData("Artistas", new string[] { "Nome", "Bio", "FotoPerfil" }, new object[] { "Foo Fighters", "Foo Fighters é uma banda de rock alternativo americana formada por Dave Grohl em 1995.", "https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png" }); + + migrationBuilder.InsertData("Artistas", new string[] { "Nome", "Bio", "FotoPerfil" }, new object[] { "Pitty", "Priscilla Novaes Leone, mais conhecida como Pitty, é uma cantora, compositora, produtora, escritora, empresária, apresentadora e multi-instrumentista brasileira.", "https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png" }); + + migrationBuilder.InsertData("Artistas", new string[] { "Nome", "Bio", "FotoPerfil" }, new object[] { "Roque Abílio", "Recriando músicas famosas com uma reviravolta rockabilly, a Roque Abílio cativa o público com uma explosão autêntica do passado que ainda faz todo mundo dançar no presente.", "https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png" }); } + /// protected override void Down(MigrationBuilder migrationBuilder) { From 36a76e81957b3b00f9353c027a91718d1e43b1a0 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 30 Mar 2024 16:55:19 -0300 Subject: [PATCH 67/85] comando par ao downgrade --- ScreenSound/Migrations/20240330194357_PopularTabela.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScreenSound/Migrations/20240330194357_PopularTabela.cs b/ScreenSound/Migrations/20240330194357_PopularTabela.cs index ee6556b..583a181 100644 --- a/ScreenSound/Migrations/20240330194357_PopularTabela.cs +++ b/ScreenSound/Migrations/20240330194357_PopularTabela.cs @@ -29,7 +29,7 @@ protected override void Up(MigrationBuilder migrationBuilder) /// protected override void Down(MigrationBuilder migrationBuilder) { - + migrationBuilder.Sql("DELETE FROM Artistas"); } } } From effe5d66fd98a8d71f4be2fb60ff559e539afbe5 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 30 Mar 2024 17:16:34 -0300 Subject: [PATCH 68/85] =?UTF-8?q?Adicionando=20ano=20do=20lan=C3=A7amento?= =?UTF-8?q?=20da=20musica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Modelos/Musica.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ScreenSound/Modelos/Musica.cs b/ScreenSound/Modelos/Musica.cs index b6c8779..7999ec7 100644 --- a/ScreenSound/Modelos/Musica.cs +++ b/ScreenSound/Modelos/Musica.cs @@ -9,6 +9,7 @@ public Musica(string nome) public string Nome { get; set; } public int Id { get; set; } + public int? AnoLancamento { get; set; } public void ExibirFichaTecnica() { From fbd6d1958ca8b7fb5828b17fea4148a31ec37224 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 30 Mar 2024 19:22:40 -0300 Subject: [PATCH 69/85] Add-Migration PopularMusica para inserir muscas --- ...3_AdicionarColunaAnoLancamento.Designer.cs | 75 +++++++++++++++++++ ...0330201713_AdicionarColunaAnoLancamento.cs | 28 +++++++ .../20240330222129_PopularMusica.Designer.cs | 75 +++++++++++++++++++ .../20240330222129_PopularMusica.cs | 22 ++++++ .../ScreenSoundContextModelSnapshot.cs | 4 + 5 files changed, 204 insertions(+) create mode 100644 ScreenSound/Migrations/20240330201713_AdicionarColunaAnoLancamento.Designer.cs create mode 100644 ScreenSound/Migrations/20240330201713_AdicionarColunaAnoLancamento.cs create mode 100644 ScreenSound/Migrations/20240330222129_PopularMusica.Designer.cs create mode 100644 ScreenSound/Migrations/20240330222129_PopularMusica.cs diff --git a/ScreenSound/Migrations/20240330201713_AdicionarColunaAnoLancamento.Designer.cs b/ScreenSound/Migrations/20240330201713_AdicionarColunaAnoLancamento.Designer.cs new file mode 100644 index 0000000..ef576ad --- /dev/null +++ b/ScreenSound/Migrations/20240330201713_AdicionarColunaAnoLancamento.Designer.cs @@ -0,0 +1,75 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ScreenSound.Banco; + +#nullable disable + +namespace ScreenSound.Migrations +{ + [DbContext(typeof(ScreenSoundContext))] + [Migration("20240330201713_AdicionarColunaAnoLancamento")] + partial class AdicionarColunaAnoLancamento + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ScreenSound.Modelos.Artista", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Bio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FotoPerfil") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Artistas"); + }); + + modelBuilder.Entity("ScreenSound.Modelos.Musica", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnoLancamento") + .HasColumnType("int"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Musica"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ScreenSound/Migrations/20240330201713_AdicionarColunaAnoLancamento.cs b/ScreenSound/Migrations/20240330201713_AdicionarColunaAnoLancamento.cs new file mode 100644 index 0000000..5f13ddc --- /dev/null +++ b/ScreenSound/Migrations/20240330201713_AdicionarColunaAnoLancamento.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ScreenSound.Migrations +{ + /// + public partial class AdicionarColunaAnoLancamento : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "AnoLancamento", + table: "Musica", + type: "int", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "AnoLancamento", + table: "Musica"); + } + } +} diff --git a/ScreenSound/Migrations/20240330222129_PopularMusica.Designer.cs b/ScreenSound/Migrations/20240330222129_PopularMusica.Designer.cs new file mode 100644 index 0000000..2ad4ea2 --- /dev/null +++ b/ScreenSound/Migrations/20240330222129_PopularMusica.Designer.cs @@ -0,0 +1,75 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ScreenSound.Banco; + +#nullable disable + +namespace ScreenSound.Migrations +{ + [DbContext(typeof(ScreenSoundContext))] + [Migration("20240330222129_PopularMusica")] + partial class PopularMusica + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ScreenSound.Modelos.Artista", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Bio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FotoPerfil") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Artistas"); + }); + + modelBuilder.Entity("ScreenSound.Modelos.Musica", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnoLancamento") + .HasColumnType("int"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Musica"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ScreenSound/Migrations/20240330222129_PopularMusica.cs b/ScreenSound/Migrations/20240330222129_PopularMusica.cs new file mode 100644 index 0000000..cbc2cc5 --- /dev/null +++ b/ScreenSound/Migrations/20240330222129_PopularMusica.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ScreenSound.Migrations +{ + /// + public partial class PopularMusica : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs b/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs index 1492195..0098ed4 100644 --- a/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs +++ b/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs @@ -1,4 +1,5 @@ // +using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -54,6 +55,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("AnoLancamento") + .HasColumnType("int"); + b.Property("Nome") .IsRequired() .HasColumnType("nvarchar(max)"); From 898e163944ea072c8201fdd1f90bb84584d378ad Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Sat, 30 Mar 2024 19:30:00 -0300 Subject: [PATCH 70/85] Inserindo dados de musicas e downgrade --- ScreenSound/Migrations/20240330222129_PopularMusica.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Migrations/20240330222129_PopularMusica.cs b/ScreenSound/Migrations/20240330222129_PopularMusica.cs index cbc2cc5..44fc6b6 100644 --- a/ScreenSound/Migrations/20240330222129_PopularMusica.cs +++ b/ScreenSound/Migrations/20240330222129_PopularMusica.cs @@ -10,13 +10,19 @@ public partial class PopularMusica : Migration /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.InsertData("Musicas", new string[] { "Nome", "AnoLancamento" }, new object[] { "Oceano", 1989 }); + migrationBuilder.InsertData("Musicas", new string[] { "Nome", "AnoLancamento" }, new object[] { "Flor de Lis", 1976 }); + + migrationBuilder.InsertData("Musicas", new string[] { "Nome", "AnoLancamento" }, new object[] { "Samurai", 1982 }); + + migrationBuilder.InsertData("Musicas", new string[] { "Nome", "AnoLancamento" }, new object[] { "Se", 1992 }); } /// protected override void Down(MigrationBuilder migrationBuilder) { - + migrationBuilder.Sql("DELETE FROM Artistas"); } } } From fca815e732075db01c7cd32008d83de5cab77ae7 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Mon, 1 Apr 2024 21:44:42 -0300 Subject: [PATCH 71/85] Adicionando a propiedade Artista em musica para realizar o vinculo --- ScreenSound/Migrations/20240330222129_PopularMusica.cs | 8 ++++---- ScreenSound/Modelos/Musica.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ScreenSound/Migrations/20240330222129_PopularMusica.cs b/ScreenSound/Migrations/20240330222129_PopularMusica.cs index 44fc6b6..20ad58c 100644 --- a/ScreenSound/Migrations/20240330222129_PopularMusica.cs +++ b/ScreenSound/Migrations/20240330222129_PopularMusica.cs @@ -10,13 +10,13 @@ public partial class PopularMusica : Migration /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.InsertData("Musicas", new string[] { "Nome", "AnoLancamento" }, new object[] { "Oceano", 1989 }); + migrationBuilder.InsertData("Musica", new string[] { "Nome", "AnoLancamento" }, new object[] { "Oceano", 1989 }); - migrationBuilder.InsertData("Musicas", new string[] { "Nome", "AnoLancamento" }, new object[] { "Flor de Lis", 1976 }); + migrationBuilder.InsertData("Musica", new string[] { "Nome", "AnoLancamento" }, new object[] { "Flor de Lis", 1976 }); - migrationBuilder.InsertData("Musicas", new string[] { "Nome", "AnoLancamento" }, new object[] { "Samurai", 1982 }); + migrationBuilder.InsertData("Musica", new string[] { "Nome", "AnoLancamento" }, new object[] { "Samurai", 1982 }); - migrationBuilder.InsertData("Musicas", new string[] { "Nome", "AnoLancamento" }, new object[] { "Se", 1992 }); + migrationBuilder.InsertData("Musica", new string[] { "Nome", "AnoLancamento" }, new object[] { "Se", 1992 }); } /// diff --git a/ScreenSound/Modelos/Musica.cs b/ScreenSound/Modelos/Musica.cs index 7999ec7..c1aa826 100644 --- a/ScreenSound/Modelos/Musica.cs +++ b/ScreenSound/Modelos/Musica.cs @@ -10,7 +10,7 @@ public Musica(string nome) public string Nome { get; set; } public int Id { get; set; } public int? AnoLancamento { get; set; } - + public Artista? Artista { get; set; } public void ExibirFichaTecnica() { Console.WriteLine($"Nome: {Nome}"); From 6e8b410444abc140a5bb7e383f8caaf821019b04 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Mon, 1 Apr 2024 21:52:28 -0300 Subject: [PATCH 72/85] Transformando a lista de musica em uma propiedade do tipo Icollection --- ScreenSound/Modelos/Artista.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ScreenSound/Modelos/Artista.cs b/ScreenSound/Modelos/Artista.cs index 6fcb97b..cf309e8 100644 --- a/ScreenSound/Modelos/Artista.cs +++ b/ScreenSound/Modelos/Artista.cs @@ -2,7 +2,7 @@ internal class Artista { - private List musicas = new List(); + public ICollection Musicas { get; set; } = new List(); public Artista(string nome, string bio) { @@ -18,13 +18,13 @@ public Artista(string nome, string bio) public void AdicionarMusica(Musica musica) { - musicas.Add(musica); + Musicas.Add(musica); } public void ExibirDiscografia() { Console.WriteLine($"Discografia do artista {Nome}"); - foreach (var musica in musicas) + foreach (var musica in Musicas) { Console.WriteLine($"Música: {musica.Nome}"); } From a5256f0c97e6b4a70031d994b4bd5ab80657350f Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Mon, 1 Apr 2024 21:55:30 -0300 Subject: [PATCH 73/85] =?UTF-8?q?Adicionando=20altera=C3=A7=C3=A3o=20anter?= =?UTF-8?q?ior=20a=20o=20banco=20via=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...005459_RelacionarArtistaMusica.Designer.cs | 94 +++++++++++++++++++ .../20240402005459_RelacionarArtistaMusica.cs | 48 ++++++++++ .../ScreenSoundContextModelSnapshot.cs | 19 ++++ 3 files changed, 161 insertions(+) create mode 100644 ScreenSound/Migrations/20240402005459_RelacionarArtistaMusica.Designer.cs create mode 100644 ScreenSound/Migrations/20240402005459_RelacionarArtistaMusica.cs diff --git a/ScreenSound/Migrations/20240402005459_RelacionarArtistaMusica.Designer.cs b/ScreenSound/Migrations/20240402005459_RelacionarArtistaMusica.Designer.cs new file mode 100644 index 0000000..ae1b872 --- /dev/null +++ b/ScreenSound/Migrations/20240402005459_RelacionarArtistaMusica.Designer.cs @@ -0,0 +1,94 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ScreenSound.Banco; + +#nullable disable + +namespace ScreenSound.Migrations +{ + [DbContext(typeof(ScreenSoundContext))] + [Migration("20240402005459_RelacionarArtistaMusica")] + partial class RelacionarArtistaMusica + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ScreenSound.Modelos.Artista", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Bio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FotoPerfil") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Artistas"); + }); + + modelBuilder.Entity("ScreenSound.Modelos.Musica", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnoLancamento") + .HasColumnType("int"); + + b.Property("ArtistaId") + .HasColumnType("int"); + + b.Property("Nome") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ArtistaId"); + + b.ToTable("Musica"); + }); + + modelBuilder.Entity("ScreenSound.Modelos.Musica", b => + { + b.HasOne("ScreenSound.Modelos.Artista", "Artista") + .WithMany("Musicas") + .HasForeignKey("ArtistaId"); + + b.Navigation("Artista"); + }); + + modelBuilder.Entity("ScreenSound.Modelos.Artista", b => + { + b.Navigation("Musicas"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ScreenSound/Migrations/20240402005459_RelacionarArtistaMusica.cs b/ScreenSound/Migrations/20240402005459_RelacionarArtistaMusica.cs new file mode 100644 index 0000000..d4f4a84 --- /dev/null +++ b/ScreenSound/Migrations/20240402005459_RelacionarArtistaMusica.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ScreenSound.Migrations +{ + /// + public partial class RelacionarArtistaMusica : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ArtistaId", + table: "Musica", + type: "int", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Musica_ArtistaId", + table: "Musica", + column: "ArtistaId"); + + migrationBuilder.AddForeignKey( + name: "FK_Musica_Artistas_ArtistaId", + table: "Musica", + column: "ArtistaId", + principalTable: "Artistas", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Musica_Artistas_ArtistaId", + table: "Musica"); + + migrationBuilder.DropIndex( + name: "IX_Musica_ArtistaId", + table: "Musica"); + + migrationBuilder.DropColumn( + name: "ArtistaId", + table: "Musica"); + } + } +} diff --git a/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs b/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs index 0098ed4..e0b3905 100644 --- a/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs +++ b/ScreenSound/Migrations/ScreenSoundContextModelSnapshot.cs @@ -58,14 +58,33 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("AnoLancamento") .HasColumnType("int"); + b.Property("ArtistaId") + .HasColumnType("int"); + b.Property("Nome") .IsRequired() .HasColumnType("nvarchar(max)"); b.HasKey("Id"); + b.HasIndex("ArtistaId"); + b.ToTable("Musica"); }); + + modelBuilder.Entity("ScreenSound.Modelos.Musica", b => + { + b.HasOne("ScreenSound.Modelos.Artista", "Artista") + .WithMany("Musicas") + .HasForeignKey("ArtistaId"); + + b.Navigation("Artista"); + }); + + modelBuilder.Entity("ScreenSound.Modelos.Artista", b => + { + b.Navigation("Musicas"); + }); #pragma warning restore 612, 618 } } From 551e452e36d1e8a9217751e75c9da04bedaa6884 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 5 Apr 2024 10:29:39 -0300 Subject: [PATCH 74/85] Adicionando o pacote proxies --- ScreenSound/Banco/ScreenSoundContext.cs | 2 +- ScreenSound/ScreenSound.csproj | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Banco/ScreenSoundContext.cs b/ScreenSound/Banco/ScreenSoundContext.cs index a526995..c53fc92 100644 --- a/ScreenSound/Banco/ScreenSoundContext.cs +++ b/ScreenSound/Banco/ScreenSoundContext.cs @@ -19,7 +19,7 @@ internal class ScreenSoundContext: DbContext "Multi Subnet Failover=False"; protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(connectionString); + optionsBuilder.UseSqlServer(connectionString).UseLazyLoadingProxies(); } diff --git a/ScreenSound/ScreenSound.csproj b/ScreenSound/ScreenSound.csproj index 355a435..0cf3833 100644 --- a/ScreenSound/ScreenSound.csproj +++ b/ScreenSound/ScreenSound.csproj @@ -22,6 +22,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + From 2a2947d5e09196909b8ca61e3baa145fb52ccdcf Mon Sep 17 00:00:00 2001 From: Wesley schuab Vieira <58818125+WesleySchuab@users.noreply.github.com> Date: Fri, 5 Apr 2024 10:34:58 -0300 Subject: [PATCH 75/85] Adicionando o pacote proxies --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index e7d0f5e..56a37bc 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,22 @@ Vamos usar "Tab" novamente para ele autocompletar e também precisamos informar Add-Migration projetoInicial As migrations são um recurso do Entity que nos permite gerenciar tanto a estrutura do nosso banco quanto as diferentes versões que ele terá durante o projeto, sem precisar mexer nos scripts SQL. +Adicionando o Pacote Proxies +No nosso Gerenciador de Soluções, clicamos em ScreenSound com o botão direito e selecionamos a opção "Editar Arquivo do Projeto". Esse arquivo tem algumas configurações do nosso projeto, e é no que vamos adicionar a referência para o nosso pacote. +Após o fechamento da última referência de pacote adicionada, vamos colar a referência que + +Essa referência de pacote que adicionamos inclui o Microsoft Entity Framework Core Proxies na versão 7.0.14. Agora salvamos o arquivo, e pronto! O pacote já foi adicionado ao projeto. +Uso do pacote Proxies: UseLazyLoadingProxies() +O próximo passo para utilizar esse pacote no nosso projeto é ir ao Gerenciador de Soluções, na nossa pasta "Banco", para abrir o arquivo ScreenSoundContext.cs. + +Nesse arquivo, onde temos um OnConfiguring(), precisamos adicionar um novo Use. No momento, temos o UseSqlServer(), e logo depois dele vamos colocar um ponto e UseLazyLoadingProxies(). Através desse Use, vamos conseguir realmente utilizar o nosso pacote. +ScreenSoundContext.cs +protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) +{ + optionsBuilder + .UseSqlServer(connectionString) + .UseLazyLoadingProxies(); +} +Ao salvar o arquivo, já podemos utilizar o pacote em nosso projeto. + + From 2b5d55fdfafedce17e399b20c1f8867eb0b2dfbc Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 5 Apr 2024 10:47:19 -0300 Subject: [PATCH 76/85] refatorando a classe muscia para usar o proxie --- ScreenSound/Modelos/Musica.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ScreenSound/Modelos/Musica.cs b/ScreenSound/Modelos/Musica.cs index c1aa826..d8f8d4a 100644 --- a/ScreenSound/Modelos/Musica.cs +++ b/ScreenSound/Modelos/Musica.cs @@ -1,6 +1,6 @@ namespace ScreenSound.Modelos; -internal class Musica +public class Musica { public Musica(string nome) { @@ -10,7 +10,7 @@ public Musica(string nome) public string Nome { get; set; } public int Id { get; set; } public int? AnoLancamento { get; set; } - public Artista? Artista { get; set; } + public virtual Artista? Artista { get; set; } public void ExibirFichaTecnica() { Console.WriteLine($"Nome: {Nome}"); From 0907bf0491d3eab0d2b7ae9209c0489b58b90531 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 5 Apr 2024 10:48:33 -0300 Subject: [PATCH 77/85] Refatorando a classe artista para usar o proxie --- ScreenSound/Modelos/Artista.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ScreenSound/Modelos/Artista.cs b/ScreenSound/Modelos/Artista.cs index cf309e8..4704c6d 100644 --- a/ScreenSound/Modelos/Artista.cs +++ b/ScreenSound/Modelos/Artista.cs @@ -1,8 +1,8 @@ namespace ScreenSound.Modelos; -internal class Artista +public class Artista { - public ICollection Musicas { get; set; } = new List(); + public virtual ICollection Musicas { get; set; } = new List(); public Artista(string nome, string bio) { From a0f6d5a4cf725510208f94040c85c7e576c6d161 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 5 Apr 2024 10:59:30 -0300 Subject: [PATCH 78/85] =?UTF-8?q?Adicionando=20ano=20de=20lan=C3=A7amento?= =?UTF-8?q?=20na=20classe=20registrar=20musica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Menus/MenuRegistrarMusica.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Menus/MenuRegistrarMusica.cs b/ScreenSound/Menus/MenuRegistrarMusica.cs index e94d1b6..9090a27 100644 --- a/ScreenSound/Menus/MenuRegistrarMusica.cs +++ b/ScreenSound/Menus/MenuRegistrarMusica.cs @@ -16,8 +16,11 @@ public override void Executar(DAL artistaDAL) { Console.Write("Agora digite o título da música: "); string tituloDaMusica = Console.ReadLine()!; - artistaRecuperado.AdicionarMusica(new Musica(tituloDaMusica)); + Console.Write("Agora digite o ano de lançamento da música: "); + string anoLancamento = Console.ReadLine()!; + artistaRecuperado.AdicionarMusica(new Musica(tituloDaMusica) { AnoLancamento = Convert.ToInt32(anoLancamento)}); Console.WriteLine($"A música {tituloDaMusica} de {nomeDoArtista} foi registrada com sucesso!"); + artistaDAL.Atualizar(artistaRecuperado); Thread.Sleep(4000); Console.Clear(); } From ded573335a25428a63b1ebd528b9b01b67ac9cd8 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 5 Apr 2024 11:00:47 -0300 Subject: [PATCH 79/85] Adcionando exibir ano na discografia --- ScreenSound/Modelos/Artista.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ScreenSound/Modelos/Artista.cs b/ScreenSound/Modelos/Artista.cs index 4704c6d..3cd495b 100644 --- a/ScreenSound/Modelos/Artista.cs +++ b/ScreenSound/Modelos/Artista.cs @@ -26,7 +26,8 @@ public void ExibirDiscografia() Console.WriteLine($"Discografia do artista {Nome}"); foreach (var musica in Musicas) { - Console.WriteLine($"Música: {musica.Nome}"); + Console.WriteLine($"Música: {musica.Nome} - Ano de Lançamento: {musica.AnoLancamento}"); + } } From 057fcefea28b9d5ad99e96f1ec1e636a491851e4 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 5 Apr 2024 15:33:15 -0300 Subject: [PATCH 80/85] =?UTF-8?q?metodo=20que=20retorna=20uma=20lista=20co?= =?UTF-8?q?m=20base=20em=20uma=20condi=C3=A7=C3=A3o=20especifica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Banco/DAL.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ScreenSound/Banco/DAL.cs b/ScreenSound/Banco/DAL.cs index ac04579..bb4e1b2 100644 --- a/ScreenSound/Banco/DAL.cs +++ b/ScreenSound/Banco/DAL.cs @@ -18,6 +18,11 @@ public IEnumerable Listar() { return context.Set().ToList(); } + public IEnumerable ListarPor(Func condicao) + { + return context.Set().Where(condicao); + } + public void Adicionar(T objeto) { context.Set().Add(objeto); From b413ff7c140c3d89d84b5d00e05d29c84c59a035 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 5 Apr 2024 15:36:37 -0300 Subject: [PATCH 81/85] criando a classe mostrar musica por ano --- ScreenSound/Menus/MenuMostrarMusicasPorAno.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ScreenSound/Menus/MenuMostrarMusicasPorAno.cs diff --git a/ScreenSound/Menus/MenuMostrarMusicasPorAno.cs b/ScreenSound/Menus/MenuMostrarMusicasPorAno.cs new file mode 100644 index 0000000..a8c0707 --- /dev/null +++ b/ScreenSound/Menus/MenuMostrarMusicasPorAno.cs @@ -0,0 +1,42 @@ +using ScreenSound.Banco; +using ScreenSound.Modelos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ScreenSound.Menus +{ + internal class MenuMostrarMusicasPorAno : Menu + { + public override void Executar(DAL artistaDAL) + { + base.Executar(artistaDAL); + ExibirTituloDaOpcao("Mostrar musicas por ano de lançamento"); + Console.Write("Digite o ano para consultar músicas:"); + string anoLancamento = Console.ReadLine()!; + var musicaDal = new DAL(new ScreenSoundContext()); + var listaAnoLancamento = musicaDal.ListarPor(a => a.AnoLancamento == Convert.ToInt32(anoLancamento)); + if (listaAnoLancamento.Any()) + { + Console.WriteLine($"\nMusicas do Ano {anoLancamento}:"); + foreach (var musica in listaAnoLancamento) + { + musica.ExibirFichaTecnica(); + } + Console.WriteLine("\nDigite uma tecla para voltar ao menu principal"); + Console.ReadKey(); + Console.Clear(); + } + else + { + Console.WriteLine($"\nO ano {anoLancamento} não foi encontrada!"); + Console.WriteLine("Digite uma tecla para voltar ao menu principal"); + Console.ReadKey(); + Console.Clear(); + } + } + } + +} From 1388ad191a162a11b36d3eff36d448850ca6dcb7 Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 5 Apr 2024 15:37:11 -0300 Subject: [PATCH 82/85] =?UTF-8?q?adicionando=20a=20op=C3=A7=C3=A3o=20mostr?= =?UTF-8?q?ar=20musica=20por=20ano=20no=20meu=20principal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index 21a359f..a204f44 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -10,6 +10,7 @@ opcoes.Add(2, new MenuRegistrarMusica()); opcoes.Add(3, new MenuMostrarArtistas()); opcoes.Add(4, new MenuMostrarMusicas()); +opcoes.Add(5, new MenuMostrarMusicasPorAno()); opcoes.Add(-1, new MenuSair()); void ExibirLogo() From 4e1eebc94e4b8291562c0c076343d2555962ac1f Mon Sep 17 00:00:00 2001 From: Wesley Schuab Date: Fri, 5 Apr 2024 15:48:31 -0300 Subject: [PATCH 83/85] =?UTF-8?q?atualisando=20as=20op=C3=A7=C3=B5es=20do?= =?UTF-8?q?=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenSound/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ScreenSound/Program.cs b/ScreenSound/Program.cs index a204f44..6b8343d 100644 --- a/ScreenSound/Program.cs +++ b/ScreenSound/Program.cs @@ -34,6 +34,7 @@ void ExibirOpcoesDoMenu() Console.WriteLine("Digite 2 para registrar a música de um artista"); Console.WriteLine("Digite 3 para mostrar todos os artistas"); Console.WriteLine("Digite 4 para exibir todas as músicas de um artista"); + Console.WriteLine("Digite 5 para exibir as músicas por ano de lançamento"); Console.WriteLine("Digite -1 para sair"); Console.Write("\nDigite a sua opção: "); From 9d798b8183b1f22d056c25bf59e610a68edac468 Mon Sep 17 00:00:00 2001 From: Wesley schuab Vieira <58818125+WesleySchuab@users.noreply.github.com> Date: Sat, 13 Apr 2024 19:18:17 -0300 Subject: [PATCH 84/85] =?UTF-8?q?Instala=C3=A7=C3=A3o=20de=20pacotes=20nes?= =?UTF-8?q?cess=C3=A1rios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 56a37bc..301937f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ Primeiro passo é criar o banco de dados +Para utilizarmos o SQL Server no projeto, é preciso que você tenha instalado o seu componente. Geralmente, este componente já é instalado junto com o Visual Studio quando você faz o processo padrão de instalação, mas você pode seguir o passo a passo abaixo para conferir se tudo está instalado corretamente: + +Abra o Visual Studio Installer; +Em Visual Studio Community 2022, na aba instalados, clique em Modificar; +Na aba Componentes individuais, pesquise por “sql” na caixa de pesquisa e verifique se o componente SQL Server Express 2019 LocalDB está assinalado. Criando o banco de dados ScreenSound : Para criarmos um banco para utilizar na nossa aplicação, vamos em "Exibir > Pesquisador de Objetos do SQL Server". Ao clicar nele, abrirá uma janela na lateral esquerda do Visual Studio. Nessa janela do Pesquisador de Objetos é onde vamos conseguir gerenciar o nosso banco. Teremos a pasta "Banco de Dados", e clicando com o botão direito sobre ela, temos a opção "Adicionar Novo Banco de Dados". Vamos selecionar essa opção e criar um banco de dados com o nome do nosso projeto. Portanto, vamos chamá-lo de ScreenSound. From 312c7104c122150786cc441544fc0072c4dcc32d Mon Sep 17 00:00:00 2001 From: Wesley schuab Vieira <58818125+WesleySchuab@users.noreply.github.com> Date: Sun, 28 Jul 2024 02:24:25 -0300 Subject: [PATCH 85/85] Update README.md --- README.md | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/README.md b/README.md index 301937f..0fa3136 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,94 @@ +# Projeto ScreenSound + +Este repositório contém o código fonte do projeto **ScreenSound**. É um aplicativo desktop desenvolvido em C# que permite o cadastro e gerenciamento de informações sobre músicos, suas músicas, álbuns e outros detalhes relevantes. O projeto utiliza o Entity Framework Core para interagir com um banco de dados SQL Server, garantindo a persistência dos dados de forma organizada e eficiente. + +## Pré-requisitos + +- Visual Studio 2022 ou superior +- .NET 7 SDK +- SQL Server Express LocalDB (geralmente instalado junto com o Visual Studio) + +## Primeiro Passo: Criar o Banco de Dados + +Para utilizarmos o SQL Server no projeto, é necessário ter o componente SQL Server Express LocalDB instalado. Normalmente, este componente é instalado com o Visual Studio durante o processo padrão de instalação. No entanto, siga os passos abaixo para verificar se está tudo instalado corretamente: + +1. Abra o **Visual Studio Installer**. +2. Em **Visual Studio Community 2022**, na aba **Instalados**, clique em **Modificar**. +3. Na aba **Componentes Individuais**, pesquise por “sql” na caixa de pesquisa e verifique se o componente **SQL Server Express 2019 LocalDB** está assinalado. + +### Criando o Banco de Dados ScreenSound + +1. No Visual Studio, vá em **Exibir > Pesquisador de Objetos do SQL Server**. Uma janela será aberta na lateral esquerda do Visual Studio. +2. Nessa janela, localize a pasta **Banco de Dados**. Clique com o botão direito sobre ela e selecione **Adicionar Novo Banco de Dados**. +3. Nomeie o banco de dados como **ScreenSound** e clique em **OK**. O banco de dados aparecerá na lista de bancos à esquerda. + +## Segundo Passo: Instalar os Pacotes + +Instale os seguintes pacotes: + +- `Microsoft.Data.SqlClient` versão 5.1.2 +- `Microsoft.EntityFrameworkCore.Design` versão 7.0.14 +- `Microsoft.EntityFrameworkCore.Tools` versão 7.0.14 +- `Microsoft.EntityFrameworkCore.SqlServer` versão 7.0.14 + +### Exemplo com Microsoft.Data.SqlClient no Visual Studio + +1. Vá em **Ferramentas > Gerenciador de Pacotes do NuGet > Gerenciar Pacotes do NuGet para a Solução…**. +2. Na aba **Procurar**, busque por "SQL Client". O primeiro resultado será o `Microsoft.Data.SqlClient`. Marque o projeto **ScreenSound** e clique em **Instalar**. Aceite as licenças para concluir a instalação. + +### Configurando a Conexão + +Para fazer a conexão com o banco de dados: + +1. No Pesquisador de Objetos do SQL Server, clique com o botão direito sobre o banco de dados **ScreenSound** e selecione **Propriedades**. +2. Copie a **Cadeia de Conexão** exibida. + +No seu projeto, crie uma variável privada chamada `connectionString` e atribua a ela as informações copiadas. Remova o valor padrão de `Connect Timeout` (30) para otimizar a execução. + +## Adicionar Migration + +Com os pacotes instalados, adicione a primeira migration ao projeto: + +1. Vá em **Ferramentas > Gerenciador de Pacotes do NuGet > Console do Gerenciador de Pacotes**. +2. Execute o seguinte comando para adicionar a migration inicial: + + ```bash + Add-Migration projetoInicial + ``` + +As migrations são um recurso do Entity Framework que permite gerenciar a estrutura e as versões do banco de dados sem a necessidade de editar scripts SQL manualmente. + +## Adicionar o Pacote Proxies + +1. No Gerenciador de Soluções, clique com o botão direito em **ScreenSound** e selecione **Editar Arquivo do Projeto**. +2. Adicione a seguinte referência no ``: + + ```xml + + ``` + +Salve o arquivo para adicionar o pacote ao projeto. + +### Uso do Pacote Proxies: `UseLazyLoadingProxies()` + +Para usar o pacote Proxies: + +1. No Gerenciador de Soluções, abra a pasta **Banco** e edite o arquivo `ScreenSoundContext.cs`. +2. No método `OnConfiguring()`, adicione `UseLazyLoadingProxies()` após `UseSqlServer()`: + + ```csharp + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder + .UseSqlServer(connectionString) + .UseLazyLoadingProxies(); + } + ``` + +Salve o arquivo para habilitar o uso do pacote no projeto. + +Abaixo está uma descrição informal narrando os passos que executei. + Primeiro passo é criar o banco de dados Para utilizarmos o SQL Server no projeto, é preciso que você tenha instalado o seu componente. Geralmente, este componente já é instalado junto com o Visual Studio quando você faz o processo padrão de instalação, mas você pode seguir o passo a passo abaixo para conferir se tudo está instalado corretamente: