Exemplo n.º 1
0
        ///// <summary>
        ///// Implementation of method.
        ///// </summary>
        ///// <returns>value.</returns>
        // public List<ProductsListModel> GetProducts()
        // {
        //    var parameter = new List<SqlParameter>();
        //    List<ProductsListModel> list = new List<ProductsListModel>();
        //    ProductsListModel product = null;
        //    var productList = this.basedal.GetData("SP_GetProducts", CommandType.StoredProcedure);
        //    foreach (DataRow data in productList.Tables[0].Rows)
        //    {
        //        product = new ProductsListModel();
        //        product.ProductId = data[0].ToString();
        //        product.CategoryId = data[1].ToString();
        //        list.Add(product);
        //    }

        // return list;
        // }

        /// <summary>
        /// Implementation of Method.
        /// </summary>
        /// <param name="productList">list.</param>
        /// <returns>value.</returns>
        public int InsertProducts(ProductsListModel productList)
        {
            var parameter = new List <SqlParameter>();

            parameter.Add(this.basedal.CreateParameter("@ProductName", 50, productList.ProductName, DbType.String));
            parameter.Add(this.basedal.CreateParameter("@CategoryId", 50, productList.CategoryId, DbType.Int16));
            parameter.Add(this.basedal.CreateParameter("@Description", 50, productList.Description, DbType.String));
            parameter.Add(this.basedal.CreateParameter("@Price", 50, productList.Price, DbType.VarNumeric));
            parameter.Add(this.basedal.CreateParameter("@Quantity", 50, productList.Quantity, DbType.Int16));
            parameter.Add(this.basedal.CreateParameter("@Image", 50, productList.Image, DbType.String));

            this.basedal.Insert("SP_InsertProduct", CommandType.StoredProcedure, parameter.ToArray(), out int lastId);

            return(lastId);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Implementation of method.
        /// </summary>
        /// <param name="keyword">list.</param>
        /// <returns>value.</returns>
        public List <ProductsListModel> SearchProduct(string keyword)
        {
            var parameter = new List <SqlParameter>();
            List <ProductsListModel> list    = new List <ProductsListModel>();
            ProductsListModel        product = null;

            parameter.Add(this.basedal.CreateParameter("@keyword", 50, keyword, DbType.String));
            var productList = this.basedal.GetData("SP_SearchProductByKeyword", CommandType.StoredProcedure);

            foreach (DataRow data in productList.Tables[0].Rows)
            {
                product            = new ProductsListModel();
                product.ProductId  = data[0].ToString();
                product.CategoryId = data[1].ToString();

                list.Add(product);
            }

            return(list);
        }