public ActionResult List() { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.Year.List(); var tb = from p in db.Table <Basis.Entity.tbYear>() select p; if (string.IsNullOrEmpty(vm.SearchText) == false) { tb = tb.Where(d => d.YearName.Contains(vm.SearchText)); } var result = (from p in tb orderby p.No select new Dto.Year.List { Id = p.Id, No = p.No, YearName = p.YearName, IsDisable = p.IsDisable, IsDefault = p.IsDefault, FromDate = p.FromDate, ToDate = p.ToDate, YearType = p.YearType, ParentId = p.tbYearParent != null ? p.tbYearParent.Id : 0 }).ToList(); vm.YearList = (from p in result where p.YearType == Code.EnumHelper.YearType.Year select p).ToList(); vm.YearList.ForEach(p => { p.ChildList = (from t in result where t.ParentId == p.Id select t).ToList(); }); vm.YearList.ForEach(p => { p.ChildList.ForEach(t => { t.ChildList = (from s in result where s.ParentId == t.Id select s).ToList(); }); }); return(View(vm)); } }
public ActionResult List(Models.Year.List vm) { return(Code.MvcHelper.Post(null, Url.Action("List", new { searchText = vm.SearchText }))); }