コード例 #1
0
ファイル: RegistController.cs プロジェクト: sun198986/Station
        public async Task <IActionResult> GetRegistCollection(
            [FromQuery] RegistDtoParameter registDtoP
            )
        {
            Expression <Func <Regist, bool> > expression = null;

            if (registDtoP.Search != null)
            {
                var entity = _mapper.Map <Regist>(registDtoP.Search);
                expression = entity.AsExpression();
            }

            Dictionary <string, PropertyMappingValue> mappingDictionary = null;

            if (registDtoP.OrderBy != null)
            {
                if (!_propertyMappingService.ValidMappingExistsFor <RegistDto, Regist>(registDtoP.OrderBy))
                {
                    return(BadRequest("无法找到对应的属性"));
                }
                mappingDictionary = _propertyMappingService.GetPropertyMapping <RegistDto, Regist>();
            }

            var entities = await _registRepository.GetAsync(registDtoP.Ids, expression, registDtoP.OrderBy, mappingDictionary);

            if (registDtoP.Ids != null && registDtoP.Ids.Count() != entities.Count())
            {
                List <string> idNotFounds = registDtoP.Ids.Where(x => !entities.Select(p => p.RegistId).ToList().Contains(x)).ToList();
                return(NotFound(JsonSerializer.Serialize(idNotFounds)));
            }

            var listDto = _mapper.Map <IEnumerable <RegistDto> >(entities);

            return(Ok(listDto.ShapeData(registDtoP.Fields)));
        }
コード例 #2
0
        public async Task <IActionResult> GetRegistCollection(
            [FromQuery] RegistDtoParameter registDtoP
            )
        {
            Expression <Func <Regist, bool> > expression = null;

            if (registDtoP.Search != null)
            {
                var entity = _mapper.Map <Regist>(registDtoP.Search);
                expression = entity.AsExpression();
            }

            Dictionary <string, PropertyMappingValue> mappingDictionary = null;

            if (registDtoP.OrderBy != null)
            {
                if (!_propertyMappingService.ValidMappingExistsFor <RegistDto, Regist>(registDtoP.OrderBy))
                {
                    return(BadRequest("无法找到对应的属性"));
                }

                //PropertyMapping <RegistDto, Regist> registMapping= new PropertyMapping<RegistDto, Regist>(
                //    new Dictionary<string, PropertyMappingValue>(StringComparer.OrdinalIgnoreCase)
                //    {
                //        {"RegistId", new PropertyMappingValue(new List<string> {"RegistId"})},
                //        {"RegistDate", new PropertyMappingValue(new List<string> {"RegistDate"})},
                //        {"MaintainNumber", new PropertyMappingValue(new List<string> {"MaintainNumber"})},
                //        {"CustomName", new PropertyMappingValue(new List<string> {"CustomName"})},
                //        {"Address", new PropertyMappingValue(new List<string> {"Address"})},
                //        {"Linkman", new PropertyMappingValue(new List<string> {"Linkman"})},
                //        {"TelPhone", new PropertyMappingValue(new List<string> {"Phone"})},
                //        {"Fax", new PropertyMappingValue(new List<string> {"Fax"})}
                //    });
                //mappingDictionary = registMapping.MappingDictionary;
                mappingDictionary = _propertyMappingService.GetPropertyMapping <RegistDto, Regist>();
            }

            var entities = await _registRepository.GetAsync(registDtoP.Ids, expression, registDtoP.OrderBy, mappingDictionary);

            if (registDtoP.Ids != null && registDtoP.Ids.Count() != entities.Count())
            {
                List <string> idNotFounds = registDtoP.Ids.Where(x => !entities.Select(p => p.RegistId).ToList().Contains(x)).ToList();
                return(NotFound(JsonSerializer.Serialize(idNotFounds)));
            }

            var listDto = _mapper.Map <IEnumerable <RegistDto> >(entities);

            return(Ok(listDto.ShapeData(registDtoP.Fields)));
        }