public void InsertProductDb(Producto producto) { string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "carrito.db3"); var db = new SQLiteConnection(dbPath); var table = db.Table <SQProduct>(); var query = table.Where(p => p.ProductID == producto.ProductID).Count(); SQProduct prod = new SQProduct(); if (query == 0) { prod.Name = producto.Name; prod.ProductID = producto.ProductID; prod.StandardCost = producto.StandardCost; prod.Color = producto.Color; prod.ProductNumber = producto.ProductNumber; prod.Cantidad = 1; db.Insert(prod); } else { prod = table.Where(p => p.ProductID == producto.ProductID).FirstOrDefault(); prod.Cantidad = prod.Cantidad + 1; db.Update(prod); } }
private void deleteProductDb(Producto producto) { string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "carrito.db3"); SQProduct productosq = new SQProduct(); var db = new SQLiteConnection(dbPath); db.Delete <SQProduct>(producto.ProductID); listProductos.Remove(producto); }