public ActionResult GetWorkerListByFilter(string id) { var query = from d in _context.V_PARTNERS where SqlMethods.Like(d.CATALOG_NAME, @"%" + id + "%") select d; if (!query.Any()) { return(Ok(new Result { Status = 404, Message = "Data not exists.", Data = null })); } List <V_PARTNER> workerList = query.ToList(); var distinctList = workerList.Aggregate(new Dictionary <decimal, V_PARTNER>(), (d, e) => { d[e.USER_ID] = e; return(d); }, d => d.Values); //var distinctList = Utility.DistinctBy(workerList, p => p.USER_ID); List <V_WorkerEntity> entityList = new List <V_WorkerEntity>(); foreach (V_PARTNER worker in distinctList) { V_WorkerEntity entity = new V_WorkerEntity(); entity.UserId = worker.USER_ID; entity.Name = worker.NAME; entity.Avatar = worker.AVATAR; entity.Introduce = worker.INTRODUCE; entity.ModeUser = worker.MODE_USER; entity.CatalogCd = worker.CATALOG_CD; entity.CatalogName = worker.CATALOG_NAME; entity.Cost = worker.COST; entity.UnitCd = worker.UNIT_CD; entity.UnitName = worker.UNIT_NAME; entity.Score = worker.SCORE; entityList.Add(entity); } return(Ok(new Result { Status = 200, Message = string.Empty, Data = entityList })); }
public ActionResult GetWorkerListByCatalog(decimal id) { var query = from d in _context.V_PARTNERS where d.CATALOG_CD == id select d; if (!query.Any()) { return(Ok(new Result { Status = 404, Message = "Data not exists.", Data = null })); } List <V_PARTNER> workerList = query.ToList(); List <V_WorkerEntity> entityList = new List <V_WorkerEntity>(); foreach (V_PARTNER worker in workerList) { V_WorkerEntity entity = new V_WorkerEntity(); entity.UserId = worker.USER_ID; entity.Name = worker.NAME; entity.Avatar = worker.AVATAR; entity.Introduce = worker.INTRODUCE; //entity.Token = worker.TOKEN; entity.CatalogCd = worker.CATALOG_CD; entity.CatalogName = worker.CATALOG_NAME; entity.Cost = worker.COST; entity.UnitCd = worker.UNIT_CD; entity.UnitName = worker.UNIT_NAME; entity.Score = worker.SCORE.Value; entityList.Add(entity); } return(Ok(new Result { Status = 200, Message = string.Empty, Data = entityList })); }