public string AddNewProduct(string data) { string result = ""; try { Products product = new Products(); product.ProductName = data.Split(';')[0].ToString(); product.SupplierID = Convert.ToInt32(data.Split(';')[1].ToString()); product.CategoryID = Convert.ToInt32(data.Split(';')[2].ToString()); product.QuantityPerUnit = data.Split(';')[3].ToString(); product.UnitPrice = Convert.ToDecimal(data.Split(';')[4].ToString()); product.UnitsInStock = Convert.ToInt16(data.Split(';')[5].ToString()); product.UnitsOnOrder = Convert.ToInt16(data.Split(';')[6].ToString()); product.ReorderLevel = Convert.ToInt16(data.Split(';')[7].ToString()); if (data.Split(';')[8].ToString() == "1") { product.Discontinued = true; } else if (data.Split(';')[8].ToString() == "0") { product.Discontinued = false; } ProductOperation productOperation = new ProductOperation(); result = productOperation.InsertProduct(product); } catch (Exception) { result = "An error occurred during this operation."; } return result; }
public string GetProductFromId(string id) { ProductOperation productOperation = new ProductOperation(); List<ProductObject> productList = productOperation.GetProductDetailFromID(Convert.ToInt32(id)); string json = Newtonsoft.Json.JsonConvert.SerializeObject(productList); return json; }
public string GetAllProduct() { ProductOperation productOperation = new ProductOperation(); List<ProductObject> productList = productOperation.GetProduct(); string json = Newtonsoft.Json.JsonConvert.SerializeObject(productList); return json; }
public string DeleteProduct(string id) { ProductOperation productOperation = new ProductOperation(); string result = productOperation.DeleteProduct(Convert.ToInt32(id)); return result; }