public ActionResult List() { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.MoralPower.List(); var tb = (from p in db.Table <Moral.Entity.tbMoralPower>() where p.tbMoralItem.Id == vm.MoralItemId select p); if (!string.IsNullOrWhiteSpace(vm.SearchText)) { tb = tb.Where(p => p.tbTeacher.TeacherName.Contains(vm.SearchText) || p.tbTeacher.TeacherCode.Contains(vm.SearchText)); } vm.MoralPowerList = (from p in tb select new Dto.MoralPower.List() { Id = p.Id, No = p.No, MoralDate = p.MoralDate, MoralItemName = p.tbMoralItem.MoralItemName, TeacherName = p.tbTeacher.TeacherName }).ToList(); var powerIds = vm.MoralPowerList.Select(p => p.Id); var morarlPowerClass = (from p in db.Table <Entity.tbMoralPowerClass>() where powerIds.Contains(p.tbMoralPower.Id) select new { p.tbMoralPower.Id, p.tbClass.ClassName }); vm.MoralPowerList.ForEach(p => { p.MoralPowerClassNames = string.Join(",", morarlPowerClass.Where(c => c.Id == p.Id).Select(c => c.ClassName)); }); return(View(vm)); } }
public ActionResult List(Models.MoralPower.List vm) { return(Code.MvcHelper.Post(returnUrl: Url.Action("List", new { searchText = vm.SearchText, moralItemId = vm.MoralItemId }))); }