public List<Maticsoft.Model.Shop.Products.ProductCategories> DataTableToList(DataTable dt) { List<Maticsoft.Model.Shop.Products.ProductCategories> list = new List<Maticsoft.Model.Shop.Products.ProductCategories>(); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { Maticsoft.Model.Shop.Products.ProductCategories item = new Maticsoft.Model.Shop.Products.ProductCategories(); if ((dt.Rows[i]["CategoryId"] != null) && (dt.Rows[i]["CategoryId"].ToString() != "")) { item.CategoryId = int.Parse(dt.Rows[i]["CategoryId"].ToString()); } if ((dt.Rows[i]["ProductId"] != null) && (dt.Rows[i]["ProductId"].ToString() != "")) { item.ProductId = long.Parse(dt.Rows[i]["ProductId"].ToString()); } if ((dt.Rows[i]["CategoryPath"] != null) && (dt.Rows[i]["CategoryPath"].ToString() != "")) { item.CategoryPath = dt.Rows[i]["CategoryPath"].ToString(); } list.Add(item); } } return list; }
public Maticsoft.Model.Shop.Products.ProductCategories GetModel(long produtId) { StringBuilder builder = new StringBuilder(); builder.Append("SELECT TOP 1 CategoryId,ProductId,CategoryPath FROM Shop_ProductCategories "); builder.Append(" WHERE ProductId=@ProductId"); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@ProductId", SqlDbType.BigInt) }; cmdParms[0].Value = produtId; Maticsoft.Model.Shop.Products.ProductCategories categories = new Maticsoft.Model.Shop.Products.ProductCategories(); DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms); if (set.Tables[0].Rows.Count <= 0) { return null; } if ((set.Tables[0].Rows[0]["CategoryId"] != null) && (set.Tables[0].Rows[0]["CategoryId"].ToString() != "")) { categories.CategoryId = int.Parse(set.Tables[0].Rows[0]["CategoryId"].ToString()); } if ((set.Tables[0].Rows[0]["ProductId"] != null) && (set.Tables[0].Rows[0]["ProductId"].ToString() != "")) { categories.ProductId = long.Parse(set.Tables[0].Rows[0]["ProductId"].ToString()); } if ((set.Tables[0].Rows[0]["CategoryPath"] != null) && (set.Tables[0].Rows[0]["CategoryPath"].ToString() != "")) { categories.CategoryPath = set.Tables[0].Rows[0]["CategoryPath"].ToString(); } return categories; }