public List <FavoritosViewModel> Listar(int id) { using (SqlConnection connection = new SqlConnection(StringConexao)) { string Query = "SELECT * FROM Favoritos where IdUsuario = @IdUsuario"; connection.Open(); SqlDataReader sdr; using (SqlCommand command = new SqlCommand(Query, connection)) { command.Parameters.AddWithValue("@IdUsuario", id); sdr = command.ExecuteReader(); while (sdr.Read()) { FavoritosViewModel favorito = new FavoritosViewModel { UsuarioId = Convert.ToInt32(sdr["IdUsuario"]), TituloId = Convert.ToInt32(sdr["IdTitulo"]) }; favoritos.Add(favorito); } } return(favoritos); } }
public FavoritosList() { this.InitializeComponent(); _navigationHelper = new NavigationHelper(this); FavoritosModel = new FavoritosViewModel(); SizeChanged += OnSizeChanged; }
public FavoritosDetail() { this.InitializeComponent(); _navigationHelper = new NavigationHelper(this); FavoritosModel = new FavoritosViewModel(); ApplicationView.GetForCurrentView(). SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible); }
public void Favoritar(FavoritosViewModel favorito) { using (SqlConnection con = new SqlConnection(StringConexao)) { string Query = "insert into Favoritos (IdTitulo, IdUsuario) values(@IdTitulo,@IdUsuario);"; SqlCommand cmd = new SqlCommand(Query, con); cmd.Parameters.AddWithValue("@IdTitulo", favorito.TituloId); cmd.Parameters.AddWithValue("@IdUsuario", favorito.UsuarioId); con.Open(); cmd.ExecuteNonQuery(); } }
public IActionResult Favoritar(int tituloId) { FavoritosViewModel favorito = new FavoritosViewModel(); try { favorito.UsuarioId = Convert.ToInt32(User.Claims.FirstOrDefault(claim => claim.Type == JwtRegisteredClaimNames.Jti).Value); favorito.TituloId = tituloId; FavoritoRepository.Favoritar(favorito); return(Ok()); } catch (Exception) { throw; } }
public FavoritosPage() { InitializeComponent(); BindingContext = viewModel = new FavoritosViewModel(); }