Esempio n. 1
0
        protected void InitializeMapper()
        {
            lock (MapperInitLock)
            {
                AutoMapper.Mapper.Reset();
                AutoMapper.Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <String, DateTime>().ConvertUsing(new DateTimeTypeConverter());

                    cfg.CreateMap <InstitutionDoc, InstitutionDto>();

                    cfg.CreateMap <BankAccount, BankAccountCreatingDto>();
                    cfg.CreateMap <BankAccount, BankAccountDto>();

                    cfg.CreateMap <CreditCard, _CreditCardCreatingDto>();
                    cfg.CreateMap <_CreditCardCreatingDto, CreditCardDoc>()
                    .ForMember(dest => dest.Id, opt => opt.MapFrom(o => Guid.NewGuid()));

                    cfg.CreateMap <CreditCard, CreditCardDto>();
                    cfg.CreateMap <CreditCard, CreditCardDoc>();
                    cfg.CreateMap <CreditCardDoc, CreditCardDto>();
                    cfg.CreateMap <CreditCardDoc, CreditCard>();
                    cfg.CreateMap <CreditCardDoc, CreditCardDescriptor>()
                    .ForMember(dest => dest.CardId, opt => opt.MapFrom(o => o.Id));

                    cfg.CreateMap <BankAccountCreatingDto, BankAccountDoc>()
                    .ForMember(dest => dest.Id, opt => opt.MapFrom(o => Guid.NewGuid()));
                    cfg.CreateMap <BankAccountDoc, BankAccountDto>()
                    .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id.ToString()));

                    cfg.CreateMap <BankTransaction, TransactionDto>();
                    cfg.CreateMap <BankTransaction, TransactionDoc>()
                    .ForMember(dest => dest.Id, opt => opt.MapFrom(o => Guid.NewGuid()));

                    cfg.CreateMap <Mortgage, MortgageDto>();
                    cfg.CreateMap <Mortgage, MortgageDoc>()
                    .ForMember(dest => dest.InterestAmount, opt => opt.MapFrom(src => CalculateHelper.CalculateInterest(src)));

                    cfg.CreateMap <Loan, LoanDto>();
                    cfg.CreateMap <Loan, LoanDoc>();

                    cfg.CreateMap <TransactionDoc, TransactionDto>();

                    cfg.CreateMap <ProviderCreatingDto, ProviderDoc>();
                    cfg.CreateMap <ProviderDoc, ProviderDto>();

                    cfg.CreateMap <LeumiMortgageResponse, Mortgage>();
                    cfg.CreateMap <LeumiLoanResponse, Loan>();

                    cfg.CreateMap <CalAccountResponse, CreditCardBankAccount>()
                    .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.AccountId));

                    cfg.CreateMap <CalBankDebit, CreditCardDebitPeriod>()
                    .ForMember(dest => dest.Amount, opt => opt.MapFrom(src => src.Amount.Value))
                    .ForMember(dest => dest.CardLastDigits, opt => opt.MapFrom(src => src.CardLast4Digits));

                    cfg.CreateMap <CalTransactionResponse, CreditCardTransaction>()
                    .ForMember(dest => dest.DealAmount, opt => opt.MapFrom(src => src.Amount.Value))
                    .ForMember(dest => dest.PaymentAmount, opt => opt.MapFrom(src => src.DebitAmount.Value));

                    cfg.CreateMap <HapoalimAccountResponse, BankAccount>()
                    .ForMember(dest => dest.Label, opt => opt.MapFrom(src => src.ProductLabel));
                });
            }
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseCors("DevPolicy");
            }
            else
            {
                app.UseExceptionHandler(options =>
                {
                    options.Run(async context =>
                    {
                        context.Response.StatusCode = 500;
                        await context.Response.WriteAsync("Ooops... something went wrong");
                    });
                });
                app.UseCors("ProdPolicy");
            }

            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <String, DateTime>().ConvertUsing(new DateTimeTypeConverter());

                cfg.CreateMap <InstitutionDoc, InstitutionDto>();

                cfg.CreateMap <BankAccount, BankAccountCreatingDto>();
                cfg.CreateMap <BankAccount, BankAccountDto>();

                cfg.CreateMap <CreditCard, _CreditCardCreatingDto>();
                cfg.CreateMap <_CreditCardCreatingDto, CreditCardDoc>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(o => Guid.NewGuid()));

                cfg.CreateMap <CreditCard, CreditCardDto>();
                cfg.CreateMap <CreditCard, CreditCardDoc>();
                cfg.CreateMap <CreditCardDoc, CreditCardDto>();
                cfg.CreateMap <CreditCardDoc, CreditCard>();
                cfg.CreateMap <CreditCardDoc, CreditCardDescriptor>()
                .ForMember(dest => dest.CardId, opt => opt.MapFrom(o => o.Id));

                cfg.CreateMap <BankAccountCreatingDto, BankAccountDoc>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(o => Guid.NewGuid()));
                cfg.CreateMap <BankAccountDoc, BankAccountDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id.ToString()));

                cfg.CreateMap <BankTransaction, TransactionDto>();
                cfg.CreateMap <BankTransaction, TransactionDoc>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(o => Guid.NewGuid()));

                cfg.CreateMap <Mortgage, MortgageDto>();
                cfg.CreateMap <Mortgage, MortgageDoc>()
                .ForMember(dest => dest.InterestAmount, opt => opt.MapFrom(src => CalculateHelper.CalculateInterest(src)));

                cfg.CreateMap <Loan, LoanDto>();
                cfg.CreateMap <Loan, LoanDoc>();

                cfg.CreateMap <TransactionDoc, TransactionDto>();

                cfg.CreateMap <ProviderCreatingDto, ProviderDoc>();
                cfg.CreateMap <ProviderDoc, ProviderDto>();

                cfg.CreateMap <LeumiMortgageResponse, Mortgage>();
                cfg.CreateMap <LeumiLoanResponse, Loan>();

                CalMapping(cfg);
                HapoalimMapping(cfg);
            });
            app.UseMvc();
        }