public object MyWorkplace(int levelId, int page, int pageSize) { var obj = _dbContext.KPILevels.Where(x => x.LevelID == levelId && x.Checked == true).ToList(); var kpiName = _dbContext.KPIs; var datas = _dbContext.Datas; var list = new List <KPIUpLoadVM>(); if (obj != null) { foreach (var item in obj) { var data = new KPIUpLoadVM() { KPIName = kpiName.FirstOrDefault(x => x.ID == item.KPIID).Name, StateW = item.WeeklyChecked == true && datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Week > 0) != null ? true : false, StateM = item.MonthlyChecked == true && datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Month > 0) != null ? true : false, StateQ = item.QuarterlyChecked == true && datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Quarter > 0) != null ? true : false, StateY = item.YearlyChecked == true && datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Year > 0) != null ? true : false }; list.Add(data); } var total = list.Count(); list = list.OrderBy(x => x.KPIName).Skip((page - 1) * pageSize).Take(pageSize).ToList(); return(new { model = list, total, status = true }); } return(new { status = false }); }
public object UpLoadKPILevelTrack(int userid, int page, int pageSize) { var model1 = new LevelDAO().GetListTreeForWorkplace(userid); var relative = ConvertHierarchicalToFlattenObject(model1); var itemuser = _dbContext.Users.FirstOrDefault(x => x.ID == userid).LevelID; var level = _dbContext.Levels.Select( x => new LevelVM { ID = x.ID, Name = x.Name, Code = x.Code, ParentID = x.ParentID, ParentCode = x.ParentCode, LevelNumber = x.LevelNumber, State = x.State, CreateTime = x.CreateTime }).ToList(); // here you get your list var itemlevel = _dbContext.Levels.FirstOrDefault(x => x.ID == itemuser); var tree = GetTree(level, itemuser).FirstOrDefault(); var relative2 = ConvertHierarchicalToFlattenObject2(tree); //var KPILevels = _dbContext.KPILevels.Where(x => x.Checked == true).ToList(); var list = new List <KPIUpLoadVM>(); var userKPIlevel = _dbContext.KPILevels.Where(x => x.Checked == true && x.LevelID == itemuser).ToList(); foreach (var item in userKPIlevel) { var data = new KPIUpLoadVM() { KPIName = _dbContext.KPIs.FirstOrDefault(x => x.ID == item.KPIID).Name, Area = _dbContext.Levels.FirstOrDefault(x => x.ID == item.LevelID).Name, StateW = item.WeeklyChecked == true && _dbContext.Datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Week > 0) != null ? true : false, StateM = item.MonthlyChecked == true && _dbContext.Datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Month > 0) != null ? true : false, StateQ = item.QuarterlyChecked == true && _dbContext.Datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Quarter > 0) != null ? true : false, StateY = item.YearlyChecked == true && _dbContext.Datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Year > 0) != null ? true : false, StateDataW = (bool?)item.WeeklyChecked ?? false, StateDataM = (bool?)item.MonthlyChecked ?? false, StateDataQ = (bool?)item.QuarterlyChecked ?? false, StateDataY = (bool?)item.YearlyChecked ?? false, }; list.Add(data); } var total = 0; if (relative2 != null) { var KPILevels = new List <KPILevel>(); foreach (var aa in relative2) { if (aa != null) { KPILevels = _dbContext.KPILevels.Where(x => x.Checked == true && x.LevelID == aa.ID) .Select(a => new { a.KPIID, a.LevelID, a.WeeklyChecked, a.MonthlyChecked, a.QuarterlyChecked, a.YearlyChecked, a.KPILevelCode }).ToList() .Select(x => new KPILevel { KPIID = x.KPIID, LevelID = x.LevelID, WeeklyChecked = x.WeeklyChecked, MonthlyChecked = x.MonthlyChecked, QuarterlyChecked = x.QuarterlyChecked, YearlyChecked = x.YearlyChecked, KPILevelCode = x.KPILevelCode }).ToList(); } if (KPILevels != null) { foreach (var item in KPILevels) { var data = new KPIUpLoadVM() { KPIName = _dbContext.KPIs.FirstOrDefault(x => x.ID == item.KPIID).Name, Area = _dbContext.Levels.FirstOrDefault(x => x.ID == item.LevelID).Name, StateW = item.WeeklyChecked == true && _dbContext.Datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Week > 0) != null ? true : false, StateM = item.MonthlyChecked == true && _dbContext.Datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Month > 0) != null ? true : false, StateQ = item.QuarterlyChecked == true && _dbContext.Datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Quarter > 0) != null ? true : false, StateY = item.YearlyChecked == true && _dbContext.Datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode && x.Year > 0) != null ? true : false }; list.Add(data); } } } total = list.Count(); list = list.OrderBy(x => x.KPIName).Skip((page - 1) * pageSize).Take(pageSize).ToList(); } return(new { model = list, total, page, pageSize }); }