Ejemplo n.º 1
0
        public ApiCollection GetDtoCollection(ApiCollection entityCollection, BaseSearchParams searchParams)
        {
            if (searchParams.Fields == null)
            {
                var items = _mapper.Map <IEnumerable <ValueReadDto> >(entityCollection.Items);

                return(new ApiCollection(items)
                {
                    TotalCount = entityCollection.TotalCount
                });
            }
            else
            {
                var newItems = new List <object>();

                foreach (var item in entityCollection.Items)
                {
                    newItems.Add(_mapper.DynamicMap(item, searchParams.Fields));
                }

                var result = new ApiCollection(newItems);
                result.TotalCount = entityCollection.TotalCount;

                return(result);
            }
        }
Ejemplo n.º 2
0
        public async Task <AmfModel> Load(SpecificationType type, string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentException("filePath");
            }

            filePath = FixPath(filePath);

            var rawresult = await GetDynamicStructureAsync(type, filePath).ConfigureAwait(false);

            var ret   = rawresult as IDictionary <string, object>;
            var error = ret["error"];

            if (error != null)
            {
                var errObj = error as IDictionary <string, object>;
                var msg    = errObj["message"] + Environment.NewLine + errObj["stack"];
                throw new FormatException(msg);
            }
            var model  = ret["model"] as IDictionary <string, object>;
            var webApi = WebApiMapper.Map(model);
            var shapes = ShapeMapper.Map(ret["shapes"] as object[]);

            return(new AmfModel(webApi, shapes));
        }