Esempio n. 1
0
        public Task <CreateOfferResponseDto> Handle(CreateOfferRequestDto request, CancellationToken cancellationToken)
        {
            //TODO: add request validtion

            var calculatePriceRequest = new CalculatePriceRequestDto()
            {
                PolicyHolderAge = AgeUtils.CalculateAgeFromPesel(request.PolicyHolder.Pesel),
                PolicyStartDate = request.PolicyFrom,
                ProductCode     = request.ProductCode,
                SelectedCovers  = request.SelectedCovers
            };

            var calculatePriceResponse = pricingApiFacade.CalculatePrice(calculatePriceRequest);

            var offer = new Offer(request, calculatePriceResponse);

            dbContext.Offer.Add(offer);

            dbContext.SaveChanges();

            var response = new CreateOfferResponseDto()
            {
                OfferNumber      = offer.OfferNumber,
                OfferValidityEnd = offer.ValidTo,
                TotalPrice       = offer.TotalPrice
            };

            return(Task.FromResult(response));
        }