public List<Maticsoft.Model.Shop.Products.ProductConsultsType> DataTableToList(DataTable dt) { List<Maticsoft.Model.Shop.Products.ProductConsultsType> list = new List<Maticsoft.Model.Shop.Products.ProductConsultsType>(); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { Maticsoft.Model.Shop.Products.ProductConsultsType item = new Maticsoft.Model.Shop.Products.ProductConsultsType(); if ((dt.Rows[i]["TypeId"] != null) && (dt.Rows[i]["TypeId"].ToString() != "")) { item.TypeId = int.Parse(dt.Rows[i]["TypeId"].ToString()); } if ((dt.Rows[i]["TypeName"] != null) && (dt.Rows[i]["TypeName"].ToString() != "")) { item.TypeName = dt.Rows[i]["TypeName"].ToString(); } if ((dt.Rows[i]["CreatedDate"] != null) && (dt.Rows[i]["CreatedDate"].ToString() != "")) { item.CreatedDate = new DateTime?(DateTime.Parse(dt.Rows[i]["CreatedDate"].ToString())); } if ((dt.Rows[i]["IsActive"] != null) && (dt.Rows[i]["IsActive"].ToString() != "")) { if ((dt.Rows[i]["IsActive"].ToString() == "1") || (dt.Rows[i]["IsActive"].ToString().ToLower() == "true")) { item.IsActive = true; } else { item.IsActive = false; } } list.Add(item); } } return list; }
public Maticsoft.Model.Shop.Products.ProductConsultsType GetModel(int TypeId) { StringBuilder builder = new StringBuilder(); builder.Append("SELECT TOP 1 TypeId,TypeName,CreatedDate,IsActive FROM Shop_ProductConsultationsType "); builder.Append(" WHERE TypeId=@TypeId"); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@TypeId", SqlDbType.Int, 4) }; cmdParms[0].Value = TypeId; Maticsoft.Model.Shop.Products.ProductConsultsType type = new Maticsoft.Model.Shop.Products.ProductConsultsType(); DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms); if (set.Tables[0].Rows.Count <= 0) { return null; } if ((set.Tables[0].Rows[0]["TypeId"] != null) && (set.Tables[0].Rows[0]["TypeId"].ToString() != "")) { type.TypeId = int.Parse(set.Tables[0].Rows[0]["TypeId"].ToString()); } if ((set.Tables[0].Rows[0]["TypeName"] != null) && (set.Tables[0].Rows[0]["TypeName"].ToString() != "")) { type.TypeName = set.Tables[0].Rows[0]["TypeName"].ToString(); } if ((set.Tables[0].Rows[0]["CreatedDate"] != null) && (set.Tables[0].Rows[0]["CreatedDate"].ToString() != "")) { type.CreatedDate = new DateTime?(DateTime.Parse(set.Tables[0].Rows[0]["CreatedDate"].ToString())); } if ((set.Tables[0].Rows[0]["IsActive"] != null) && (set.Tables[0].Rows[0]["IsActive"].ToString() != "")) { if ((set.Tables[0].Rows[0]["IsActive"].ToString() == "1") || (set.Tables[0].Rows[0]["IsActive"].ToString().ToLower() == "true")) { type.IsActive = true; return type; } type.IsActive = false; } return type; }