}/// <summary> /// 获取用户列表 /// </summary> /// <param name="userName"></param> /// <param name="PageSize"></param> /// <param name="page"></param> /// <returns></returns> public ActionResult GetUerList(string userName, int limit, int page) { Sql sql = new Sql(); int totalAmount; try { using (var db = new LayUIDemo.Models.DBMall()) { if (!string.IsNullOrEmpty(userName)) { //sql.Append("where UserName=@0", userName); var query = from p in db.Userinfo where p.UserName == userName orderby p.CreateTime select p; totalAmount = query.Count(); return(Json(ResultTemp <UserInfo> .OK(query.Skip((page - 1) * limit).Take(limit).ToList(), totalAmount), JsonRequestBehavior.AllowGet)); } // var result = db.Page<UserInfo>(page, limit, sql); var result = from p in db.Userinfo orderby p.CreateTime select p; totalAmount = result.Count(); return(Json(ResultTemp <UserInfo> .OK(result.Skip((page - 1) * limit).Take(limit).ToList(), totalAmount), JsonRequestBehavior.AllowGet)); } } catch (Exception) { throw; } }
/// <summary> /// Converts a DataTable to a List<TSource> /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="dataTable"></param> /// <returns></returns> public static List <TSource> ToList <TSource>(this DataTable dataTable, bool replaceResourceKeys) { EnumerableRowCollection <DataRow> EnumerableRowCollectionDataRowObj = dataTable.AsEnumerable(); List <TSource> ListResult = new List <TSource>(); if (EnumerableRowCollectionDataRowObj != null) { string dtValueOriginal; TSource ResultTemp; foreach (DataRow dr in EnumerableRowCollectionDataRowObj) { ResultTemp = Activator.CreateInstance <TSource>(); foreach (var prop in ResultTemp.GetType().GetProperties()) { if (dr.Table.Columns.Contains(prop.Name)) { var dtValue = dr[prop.Name] is DBNull ? (prop.PropertyType == typeof(string) ? string.Empty : null) : dr[prop.Name]; if (dtValue.IsNotNull() && dtValue.GetType() == typeof(string)) { dtValue = (dtValue as string).Trim(); } //To support the multilingual records it is necessary to use {#itemvalue} in the DB records if (dtValue.IsNotNull() && replaceResourceKeys && dtValue.AsString().StartsWith("{#") && dtValue.AsString().EndsWith("}")) { dtValueOriginal = dtValue.AsString(); //dtValue = Strings.ResourceManager.GetString(dtValue.AsString().Substring(2, dtValue.AsString().Length - 3)); dtValue = dtValue.AsString().Substring(2, dtValue.AsString().Length - 3).GetStringFromResource(); //If the Resource file lookup returns empty then display the original key value if (dtValue.AsString().IsEmptyOrWhiteSpace()) { dtValue = dtValueOriginal; } } ResultTemp.SetPropertyValue(prop.Name, dtValue); } } ListResult.Add(ResultTemp); } } return(ListResult); }