Ejemplo n.º 1
0
        public IEnumerable <SortCriteria> Resolve(TSource source, TDestination destination, IEnumerable <SortCriteria> destMember, ResolutionContext context)
        {
            List <SortCriteria> sortCriterias = new List <SortCriteria>();

            foreach (var s in source.SortBy)
            {
                PropertyMappingValue tp = null;
                try
                {
                    tp = _propertyMappingService.GetMapping <TResource, TEntity>(s.SortByCriteria);
                }
                catch (InvalidPropertyMappingException)
                {
                    // Skip erroneous mapping and move on to next sort criteria.
                    continue;
                }
                sortCriterias.AddRange(
                    tp.TargetPropertyNames.Select(tpn =>
                                                  new SortCriteria
                {
                    SortByCriteria = tpn,
                    SortDirection  = tp.Revert
                                ? s.SortDirection == SortDirection.Desc
                                    ? SortDirection.Asc
                                    : SortDirection.Desc
                                : s.SortDirection == SortDirection.Asc
                                    ? SortDirection.Asc
                                    : SortDirection.Desc
                }));
            }
            return(sortCriterias);
        }
Ejemplo n.º 2
0
        public IEnumerable <PropertyMappingValue> GetMappings(params string[] sourcePropertyNames)
        {
            PropertyMappingValue        propertyMappingValue  = null;
            List <PropertyMappingValue> propertyMappingValues = new List <PropertyMappingValue>();

            Array.ForEach(sourcePropertyNames, sourcePropertyName =>
            {
                _propertyMappingValues.TryGetValue(sourcePropertyName, out propertyMappingValue);
                if (propertyMappingValue == null)
                {
                    throw new InvalidPropertyMappingException($"Source property name '{sourcePropertyName}' for source type {typeof(TSource)} not mapped to target type {typeof(TTarget)}.");
                }
                propertyMappingValues.Add(propertyMappingValue);
            });
            return(propertyMappingValues);
        }