//---------------METODOS DE BUSQUEDA DE VARIOS PRODUCTOS------------------ public static List <ShowProductModel> SelectMultipleProducts(string text) { try { string code = text; string brand = text; string category = text; string subcategory = text; string description = text; string[] product = new string[] { code, brand, category, subcategory, description }; ShowProductModel showProduct = new ShowProductModel() { Code = code, Brand = brand, Category = category, Subcategory = subcategory, Description = description }; return(ProductConnection.SelectMultipleProducts(showProduct)); } catch (Exception ex) { //Log4Net return(null); } }
public void TestAddingToConnectionUnitialized() { string responseString2 = @"{ ""edges"": [ { ""node"": { ""title"": ""product1"" }, ""cursor"": ""0"" } ], ""pageInfo"": { ""hasNextPage"": true } }"; Dictionary <string, object> response2 = (Dictionary <string, object>)Json.Deserialize(responseString2); Dictionary <string, object> response1 = new Dictionary <string, object>(); ProductConnection queryResponse1 = new ProductConnection(response1); ProductConnection queryResponse2 = new ProductConnection(response2); queryResponse1.AddFromConnection(queryResponse2); Assert.AreEqual(1, queryResponse1.edges().Count); Assert.AreEqual("product1", queryResponse1.edges()[0].node().title()); Assert.AreEqual(true, queryResponse1.pageInfo().hasNextPage()); }
public void TestCastConnectionToList() { string stringJSON = @"{ ""edges"": [ { ""node"": { ""title"": ""Product 1"" } }, { ""node"": { ""title"": ""Product 2"" } } ] }"; ProductConnection connection = new ProductConnection((Dictionary <string, object>)Json.Deserialize(stringJSON)); List <Product> products = (List <Product>)connection; bool couldIterateOverConnection = false; foreach (Product product in products) { couldIterateOverConnection = true; } Assert.IsNotNull(products, "products is not null"); Assert.AreEqual(2, products.Count, "products list has two products"); Assert.AreEqual("Product 2", products[1].title(), "List had data"); Assert.IsTrue(couldIterateOverConnection, "could iterate over connection"); }
//---------------METODOS DE BUSQUEDA DE PRODUCTOS------------------ public static List <ShowProductModel> SelectAllProducts() { try { return(ProductConnection.SelectAllProducts()); } catch (Exception ex) { //Log4Net return(null); } }
public static ProductModel SelectProductByID(string id) { try { ProductModel productModel = new ProductModel() { Id_Product = int.Parse(id) }; return(ProductConnection.SelectProductByID(productModel)); } catch (Exception ex) { throw; } }
public static ProductModel SelectProductByCode(string code) { try { ProductModel productModel = new ProductModel() { Code = code }; return(ProductConnection.SelectProductByCode(productModel)); } catch (Exception ex) { return(null); } }
public void TestAddingToConnection() { string responseString1 = @"{ ""edges"": [ { ""node"": { ""title"": ""product1"" }, ""cursor"": ""0"" } ], ""pageInfo"": { ""hasNextPage"": true } }"; string responseString2 = @"{ ""edges"": [ { ""node"": { ""title"": ""product2"" }, ""cursor"": ""1"" } ], ""pageInfo"": { ""hasNextPage"": false } }"; Dictionary <string, object> response1 = (Dictionary <string, object>)Json.Deserialize(responseString1); Dictionary <string, object> response2 = (Dictionary <string, object>)Json.Deserialize(responseString2); ProductConnection queryResponse1 = new ProductConnection(response1); ProductConnection queryResponse2 = new ProductConnection(response2); queryResponse1.AddFromConnection(queryResponse2); Assert.AreEqual(2, queryResponse1.edges().Count); Assert.AreEqual("product1", queryResponse1.edges()[0].node().title()); Assert.AreEqual("product2", queryResponse1.edges()[1].node().title()); Assert.AreEqual(false, queryResponse1.pageInfo().hasNextPage()); // the following are to test whether original response was not mutated Assert.AreEqual(1, ((List <object>)response1["edges"]).Count); Assert.AreEqual("product1", ((Dictionary <string, object>)((Dictionary <string, object>)((List <object>)response1["edges"])[0])["node"])["title"]); }
// ACTUALIZAR PRODUCTO public static bool UpdateProductById( string idProduct, string code, string idBrand, string idSubCategory, string stock, string Description, string Price, string lowerPrice, byte[] image, bool ivi ) { try { string[] product = new string[] { idProduct, code, idBrand, idSubCategory, stock, Description, Price, lowerPrice }; ProductModel productModel = new ProductModel() { Id_Product = int.Parse(idProduct), Code = code, Id_Brand = int.Parse(idBrand), Id_Subcategory = int.Parse(idSubCategory), Quantity_Stock = int.Parse(stock), Description = Description, Price = decimal.Parse(Price), Lower_Price = decimal.Parse(lowerPrice), Ivi = ivi, Image = image }; return(ProductConnection.UpdateProductById(productModel)); } catch (Exception ex) { //Log4Net return(false); } }
/// <summary> /// Metodo para eliminar un producto /// </summary> /// <param name="idProduct"></param> /// <returns></returns> public static bool DeleteProductById(string idProduct) { try { string[] product = new string[] { idProduct }; ProductModel productModel = new ProductModel() { Id_Product = int.Parse(idProduct), }; return(ProductConnection.DeleteProductById(productModel)); } catch (Exception ex) { //Log4Net return(false); } }
//-----------------METODOS ACME DEL PRODUCTO --------------------------- // AGREGAR PRODUCTO public static bool InsertProduct( string code, string idBrand, string idSubcategory, string Description, string Stock, string Price, string lowerPrice, byte[] image, bool ivi ) { try { string[] Product = new string[] { code, idBrand, idSubcategory, Description, Stock, Price, lowerPrice }; ProductModel productModel = new ProductModel() { Code = code, Id_Brand = int.Parse(idBrand), Id_Subcategory = int.Parse(idSubcategory), Description = Description, Quantity_Stock = int.Parse(Stock), Price = decimal.Parse(Price), Lower_Price = decimal.Parse(lowerPrice), Ivi = ivi, Image = image }; return(ProductConnection.InsertProduct(productModel)); } catch (Exception ex) { //Log4Net return(false); } }
/// <summary> /// Medoto para actualizar la cantidad de productos en la base de datos (stock) /// </summary> /// <param name="id"></param> /// <param name="stock"></param> /// <returns></returns> public static bool UpdateProductById2(string id, string stock) { try { string[] product = new string[] { id, stock }; ProductModel productModel = new ProductModel() { Id_Product = Convert.ToInt32(id), Quantity_Stock = int.Parse(stock) }; return(ProductConnection.UpdateProductById2(productModel)); } catch (Exception ex) { //Log4Net return(false); } }