/// <summary> /// /// </summary> /// <param name="index"></param> /// <param name="name"></param> /// <param name="totalPage"></param> /// <param name="type"></param> /// <param name="pageSize"></param> /// <param name="IsShow">是否显示在网站前台</param> /// <returns></returns> public IEnumerable <CommerceViewModel> GetItemModel(int index, string name, out int totalPage, int type, int pageSize = 10, bool IsShow = false) { List <Commerce> itemList = null; Expression <Func <Commerce, bool> > where; Expression <Func <Commerce, int> > sort = c => c.id; if (string.IsNullOrWhiteSpace(name)) { where = (c => c.IsDelete == 0 && c.Type == type); if (IsShow) { where = (c => c.IsDelete == 0 && c.Type == type && c.Look == 0); sort = c => (int)c.Sort; } } else { where = (c => c.IsDelete == 0 && c.Type == type && c.Name.Contains(name)); if (IsShow) { where = (c => c.IsDelete == 0 && c.Type == type && c.Look == 0 && c.Name.Contains(name)); sort = c => (int)c.Sort; } } if (IsShow) { itemList = dal.QueryByPageASC(index, pageSize, out totalPage, where, sort).ToList <Commerce>(); } else { itemList = dal.QueryByPage(index, pageSize, out totalPage, where, sort).ToList <Commerce>(); } int newid = 1; if (index > 1) { newid = (index - 1) * 10 + newid; } return(itemList.Select(d => new CommerceViewModel { Nid = newid++, IsDelete = d.IsDelete, LookBool = d.Look == 0 ? true : false, id = d.id, Contents = d.Contents.Length > 10 && IsShow == false ? d.Contents.Substring(0, 8) : d.Contents, Creater = d.Creater, CreateTime = d.CreateTime, Look = d.Look, Name = d.Name, Remark = d.Remark, ImageUrl = d.ImageUrl, UpdateTime = d.UpdateTime, UpdateTimeStr = d.UpdateTime.ToShortDateString(), typeName = d.Type, Sort = string.IsNullOrWhiteSpace(d.Sort.ToString())?0:(int)d.Sort })); }