//Agregar public bool Agregar(Entities.Libro libro) { SqlConnection c; SqlCommand comandAgregar; String sql = "INSERT INTO libros (libCodigo, libNombre, libNumPag, libAutor, libEditorial, libArea) VALUES (@codigo, @nombre ,@paginas, @autor, @editorial, @area)"; try { c = con.getConexion(); comandAgregar = new SqlCommand(sql, c); comandAgregar.Parameters.AddWithValue("@codigo", libro.Codigo); comandAgregar.Parameters.AddWithValue("@nombre", libro.Nombre); comandAgregar.Parameters.AddWithValue("@paginas", libro.NumeroPaginas); comandAgregar.Parameters.AddWithValue("@autor", libro.Autor); comandAgregar.Parameters.AddWithValue("@editorial", libro.Editorial); comandAgregar.Parameters.AddWithValue("@area", libro.Area); comandAgregar.ExecuteNonQuery(); return(true); }catch (Exception ex) { ex.ToString(); return(false); } }
//ACTUALIZAR public bool Actualizar(Entities.Libro libro, String cod) { SqlConnection c = null; SqlCommand comandActualizar = null; String sql = "UPDATE libros SET libCodigo = @codigo, libNombre = @nombre, libNumPag = @paginas, libAutor = @autor, libEditorial = @editorial, libArea = @area WHERE libCodigo = @codigoUP"; try { c = con.getConexion(); comandActualizar = new SqlCommand(sql, c); comandActualizar.Parameters.AddWithValue("@codigo", libro.Codigo); comandActualizar.Parameters.AddWithValue("@nombre", libro.Nombre); comandActualizar.Parameters.AddWithValue("@paginas", libro.NumeroPaginas); comandActualizar.Parameters.AddWithValue("@autor", libro.Autor); comandActualizar.Parameters.AddWithValue("@editorial", libro.Editorial); comandActualizar.Parameters.AddWithValue("@area", libro.Area); comandActualizar.Parameters.AddWithValue("@codigoUp", cod); comandActualizar.ExecuteNonQuery(); return(true); }catch (Exception ex) { ex.ToString(); return(false); } finally { c.Close(); comandActualizar = null; } }
public void InicialViewModel() { Libros = new List <Entities.Libro>(); BuscarLibroCommand = new CommandDelegate ((o) => { return(true); }, (o) => { var Proxy = new ProxyService.Proxy(); Libros = Proxy.FiltrarLibroPorIDGenero(IDGeneroL); int CountProduct = 0; foreach (var item in Libros) { CountProduct += 1; } Application.Current.MainPage.DisplayAlert("Mensaje", $"Se encontraron {CountProduct} resultados", "Ok"); }); BuscarLibroPorIDCommand = new CommandDelegate ((o) => { return(true); }, (o) => { if (LibroSelected.IDL != 0) { var Proxy = new ProxyService.Proxy(); var p = Proxy.ObtenerLibroPorID(LibroSelected.IDL); IDL = p.IDL; NombreL = p.NombreL; AutorL = p.AutorL; Editorial = p.Editorial; ISBN = p.ISBN; PrecioL = p.PrecioL; RutaImgL = p.RutaImgL; IDGeneroL = p.IDGeneroL; //Application.Current.MainPage.Navigation.PushAsync(); } }); CrearLibroCommand = new CommandDelegate ((o) => { return(true); }, (o) => { var nuevoLibro = new Entities.Libro { IDL = IDL, NombreL = NombreL, AutorL = AutorL, Editorial = Editorial, ISBN = ISBN, PrecioL = PrecioL, RutaImgL = RutaImgL, IDGeneroL = IDGeneroL }; var Proxy = new ProxyService.Proxy(); nuevoLibro = Proxy.CrearLibro(nuevoLibro); IDL = nuevoLibro.IDL; if (IDL != 0) { Application.Current.MainPage.DisplayAlert("Mensaje", "Creado Correctamente", "Ok"); } } ); ActualizarLibroCommand = new CommandDelegate ((o) => { return(true); }, (o) => { var nuevoLibro = new Entities.Libro { NombreL = NombreL, AutorL = AutorL, Editorial = Editorial, ISBN = ISBN, PrecioL = PrecioL, RutaImgL = RutaImgL, IDGeneroL = IDGeneroL }; var Proxy = new ProxyService.Proxy(); var Respuesta = Proxy.ActualizarLibro(IDL, nuevoLibro); if (Respuesta) { Application.Current.MainPage.DisplayAlert("Mensaje", "Actualizado Correctamente", "Ok"); } }); EliminarLibroCommand = new CommandDelegate ((o) => { return(true); }, (o) => { var Proxy = new ProxyService.Proxy(); var Respuesta = Proxy.EliminarLibro(IDL); if (Respuesta) { IDL = 0; NombreL = ""; AutorL = ""; Editorial = ""; ISBN = ""; PrecioL = 0; RutaImgL = ""; IDGeneroL = 0; Application.Current.MainPage.DisplayAlert("Mensaje", "Eliminado Correctamente", "Ok"); } }); }
public void InicialViewModel() { Libros = new List <Entities.Libro>(); BuscarLibroCommand = new CommandDelegate ((o) => { return(true); }, (o) => { var Proxy = new ProxyService.Proxy(); Libros = Proxy.FiltrarLibroPorIDGenero(IDGeneroL); }); BuscarLibroPorIDCommand = new CommandDelegate ((o) => { return(true); }, (o) => { if (LibroSelected.IDL != 0) { var Proxy = new ProxyService.Proxy(); var p = Proxy.ObtenerLibroPorID(LibroSelected.IDL); IDL = p.IDL; NombreL = p.NombreL; AutorL = p.AutorL; Editorial = p.Editorial; ISBN = p.ISBN; IDGeneroL = p.IDGeneroL; } }); CrearLibroCommand = new CommandDelegate ((o) => { return(true); }, (o) => { var nuevoLibro = new Entities.Libro { IDL = IDL, NombreL = NombreL, AutorL = AutorL, Editorial = Editorial, ISBN = ISBN, IDGeneroL = IDGeneroL }; var Proxy = new ProxyService.Proxy(); nuevoLibro = Proxy.CrearLibro(nuevoLibro); IDL = nuevoLibro.IDL; if (IDL != 0) { //Application.Current.MainPage.DisplayAlert("Mensaje", "Creado Correctamente", "Ok"); } } ); ActualizarLibroCommand = new CommandDelegate ((o) => { return(true); }, (o) => { var nuevoLibro = new Entities.Libro { NombreL = NombreL, AutorL = AutorL, Editorial = Editorial, ISBN = ISBN, IDGeneroL = IDGeneroL }; var Proxy = new ProxyService.Proxy(); var Respuesta = Proxy.ActualizarLibro(IDL, nuevoLibro); if (Respuesta) { //Application.Current.MainPage.DisplayAlert("Mensaje", "Actualizado Correctamente", "Ok"); } }); EliminarLibroCommand = new CommandDelegate ((o) => { return(true); }, (o) => { var Proxy = new ProxyService.Proxy(); var Respuesta = Proxy.EliminarLibro(IDL); if (Respuesta) { IDL = 0; NombreL = ""; AutorL = ""; Editorial = ""; ISBN = ""; IDGeneroL = 0; //Application.Current.MainPage.DisplayAlert("Mensaje", "Eliminado Correctamente", "Ok"); } }); }