/// <summary>
        ///     Splits an <see cref="IEnumerable{T}" /> into evenly sized chunks.
        /// </summary>
        /// <param name="enumerable">The source enumerable.</param>
        /// <param name="chunkSize">The size of the chunks to return.</param>
        /// <returns>An <see cref="IEnumerable{T}" /> containing other enumerables representing the chunks.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="enumerable" /> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="chunkSize" /> is less than 1.</exception>
        public static IEnumerable <IEnumerable <T> > InChunksOf <T>(this IEnumerable <T> enumerable, int chunkSize)
        {
            if (enumerable == null)
            {
                throw new ArgumentNullException(nameof(enumerable));
            }

            if (chunkSize < 1)
            {
                throw new ArgumentException("Chunk size must be a positive integer greater than zero",
                                            nameof(chunkSize));
            }

            return(chunkSize == 1
                ? enumerable.Select(item => new[] { item })
                : IEnumerableExtensions.ChunksImpl(enumerable, chunkSize));
        }
Esempio n. 2
0
        private void MapSpecs()
        {
            CreateMap <CreateSpecificationViewModel, SpecificationSummary>()
            .ForMember(m => m.Id, opt => opt.Ignore())
            .ForMember(m => m.FundingPeriod, opt => opt.Ignore())
            .ForMember(m => m.FundingStreams, opt => opt.Ignore())
            .ForMember(m => m.IsSelectedForFunding, opt => opt.Ignore())
            .ForMember(m => m.ApprovalStatus, opt => opt.Ignore())
            .ForMember(m => m.TemplateIds, opt => opt.Ignore())
            .ForMember(m => m.DataDefinitionRelationshipIds, opt => opt.Ignore())
            .ForMember(m => m.LastEditedDate, opt => opt.Ignore())
            .ForMember(m => m.ProviderSource, opt => opt.Ignore())
            .ForMember(m => m.CoreProviderVersionUpdates, opt => opt.Ignore());

            CreateMap <CreateSpecificationModel, CreateSpecificationViewModel>()
            .ForMember(m => m.FundingStreamId, opt => opt.Ignore())
            .AfterMap((CreateSpecificationModel source, CreateSpecificationViewModel destination) => { destination.FundingStreamId = source.FundingStreamIds.FirstOrDefault(); });

            CreateMap <CreateSpecificationViewModel, CreateSpecificationModel>()
            .ForMember(m => m.FundingStreamIds, opt => opt.Ignore())
            .AfterMap((CreateSpecificationViewModel source, CreateSpecificationModel destination) => { destination.FundingStreamIds = new List <string> {
                                                                                                           source.FundingStreamId
                                                                                                       }; });

            CreateMap <EditSpecificationViewModel, EditSpecificationModel>()
            .ForMember(m => m.AssignedTemplateIds, opt => opt.Ignore());

            CreateMap <EditSpecificationModel, EditSpecificationViewModel>()
            .ForMember(m => m.Id, opt => opt.Ignore())
            .ForMember(m => m.FundingStreamId, opt => opt.Ignore())
            .ForMember(m => m.OriginalFundingPeriodId, opt => opt.Ignore())
            .ForMember(m => m.OriginalFundingStreamId, opt => opt.Ignore())
            .ForMember(m => m.OriginalSpecificationName, opt => opt.Ignore())
            .ForMember(m => m.IsSelectedForFunding, opt => opt.Ignore());

            CreateMap <CreateAdditionalCalculationViewModel, CalculationCreateModel>()
            .ForMember(m => m.Name, opt => opt.Ignore())
            .ForMember(m => m.Description, opt => opt.Ignore())
            .ForMember(m => m.SpecificationId, opt => opt.Ignore())
            .ForMember(m => m.ValueType, opt => opt.Ignore())
            .ForMember(m => m.Id, opt => opt.Ignore());

            CreateMap <EditAdditionalCalculationViewModel, CalculationEditModel>()
            .ForMember(m => m.Name, opt => opt.Ignore())
            .ForMember(m => m.Description, opt => opt.Ignore())
            .ForMember(m => m.SpecificationId, opt => opt.Ignore())
            .ForMember(m => m.CalculationId, opt => opt.Ignore())
            .ForMember(m => m.ValueType, opt => opt.Ignore());


            CreateMap <SpecificationSummary, SpecificationSummaryViewModel>();

            CreateMap <SpecificationSummary, SpecificationSummary>();

            CreateMap <SpecificationSummary, SpecificationViewModel>()
            .ForMember(m => m.PublishStatus, opt => opt.MapFrom(c => c.ApprovalStatus));

            CreateMap <CalculationVersion, CalculationViewModel>()
            .ForMember(d => d.LastModified, opt => opt.MapFrom(s => s.LastUpdated))
            .ForMember(d => d.LastModifiedByName, opt => opt.MapFrom(s => s.Author != null ? s.Author.Name : "Unknown"))
            .ForMember(d => d.PublishStatus, opt => opt.MapFrom(s => s.PublishStatus.AsMatchingEnum <PublishStatusViewModel>()))
            .ForMember(d => d.Id, opt => opt.MapFrom(s => s.CalculationId))
            .ForMember(d => d.ValueType, opt => opt.Ignore())
            .ForMember(d => d.SpecificationId, opt => opt.Ignore())
            .ForMember(d => d.LastModified, opt => opt.Ignore())
            .ForMember(d => d.Description, opt => opt.Ignore());

            CreateMap <SpecificationSummary, EditSpecificationViewModel>()
            .ForMember(m => m.OriginalSpecificationName, opt => opt.Ignore())
            .ForMember(m => m.OriginalFundingStreamId, opt => opt.Ignore())
            .ForMember(m => m.OriginalFundingPeriodId, opt => opt.Ignore())
            .ForMember(m => m.FundingStreamId, opt => opt.Ignore())
            .AfterMap((SpecificationSummary source, EditSpecificationViewModel destination) =>
            {
                destination.FundingPeriodId = source.FundingPeriod?.Id;
                if (IEnumerableExtensions.AnyWithNullCheck(source.FundingStreams))
                {
                    destination.FundingStreamId = source.FundingStreams.FirstOrDefault()?.Id;
                }
            });

            CreateMap <SpecificationSearchResultItem, SpecificationSearchResultItemViewModel>();
        }