0

I have such classes:

public abstract class BookingShoppingCart : SerializableEntity, IShoppingCart
{
    protected BookingShoppingCart()
    {
        Accommodations = new ObservableCollection<RQBooking>();
        Packages = new ObservableCollection<RQBooking>();
        Splits = new ObservableCollection<RQBookingContainer>();
    }

    public ObservableCollection<RQBooking> Accommodations { get; set; }

    public ObservableCollection<RQBooking> Packages { get; set; }

    public ObservableCollection<RQBookingContainer> Splits { get; set; }

    public List<RQBooking> AllAccommodationsAndParts
    {
        get { return Accommodations.Union(Splits.SelectMany(s => s.Bookings)).ToList(); }
    }

    public List<RQBooking> AllBookedItemsAndParts
    {
        get { return Accommodations.Union(Packages).Union(Splits.SelectMany(s => s.Bookings)).ToList(); }
    }

    public decimal AccommodationFeesTotal
    {
        get { return AllBookedItemsAndParts.Sum(x => (x.RQReservation.FeeRules.Any(r => r.AppliedOn == FeeAppliedOn.Booking)) ? x.RQReservation.FeeRules.Where(r => r.AppliedOn == FeeAppliedOn.Booking).Sum(r => r.Total) : 0); }
    }

    public decimal AddonsFeesTotal
    {
        get { return AllAccommodationsAndParts.Sum(x => (x.DefaultRQAddonsOrder.Items.SelectMany(oi => oi.FeeRules).Sum(r => r.Total))); }
    }

    public decimal AccommodationTotalWithoutFees
    {
        get { return AllAccommodationsAndParts.Sum(x => x.RQReservation.TotalBooking) + Packages.Sum(x => x.Total); }
    }

    public decimal AddonsTotalWithoutFees
    {
        get { return AllAccommodationsAndParts.Sum(x => OrderItemGrouping.ItemsExceptFree(x.DefaultRQAddonsOrder).Sum(o => o.Total)); }
    }


    public decimal AddonsTotal
    {
        get { return AddonsTotalWithoutFees + AddonsFeesTotal; }
    }


    public UserInfoRequest UserInfoRequest { get; set; }

    public string Currency { get; set; }
    public string BookingDates { get; set; }
    public string BookingStartDate { get; set; }
    public string BookingStartDateFormat { get; set; }
    public string BookingEndDate { get; set; }        
    public string BookingEndDateFormat { get; set; }
    public string BookingNights { get; set; }

    public decimal CurrencyExcRate { get; set; }

    public abstract decimal Total { get; }

    public abstract void Init();
}




 public class BookingShoppingCartCreate : BookingShoppingCart
        {
            public override decimal Total
            {
                get { return AccommodationTotal + AddonsTotal; }
            }

            public override void Init()
            {

            }
        }


public class QuoteBookingShoppingCart : BookingShoppingCartCreate
    {
    }

And I need to cast BookingShoppingCart to QuoteShoppingCart:

    public BookingConfirmation ConfirmQuoteWithSession(BookingShoppingCart bookingShoppingCart)
            {

                var bookingShoppingCartCreate = _mappingEngine.Map<BookingShoppingCartCreate>(bookingShoppingCart);

                var quoteShoppingCart = _mappingEngine.Map<QuoteBookingShoppingCart>(bookingShoppingCartCreate);
                var confirmResult = _bookingServiceFacade.CreateOrUpdateReservation(quoteShoppingCart, targetPersonID);

          }

I created mapper for this:

public class ExampleAutomapperConfiguration
    {
        public static void Configure()
        {
            Mapper.Initialize(
                configuration =>
                {
                    configuration.AddProfile<QuoteProfile>();
                });

            Mapper.AssertConfigurationIsValid();
        }


public class QuoteProfile : BaseProfile
    {
        protected override void Configure()
        {
            CreateMap<BookingShoppingCart, BookingShoppingCartCreate>()
                    .IgnoreAllNonExisting();
            CreateMap<BookingShoppingCartCreate, QuoteBookingShoppingCart>()
                .IgnoreAllNonExisting();
        }
    }

But everytime I get an error:

Missing type map configuration or unsupported mapping.

Mapping types:
BookingShoppingCartCreate -> QuoteBookingShoppingCart
ShoppingCarts.BookingShoppingCarts.BookingShoppingCartCreate -> ShoppingCarts.BookingShoppingCarts.QuoteBookingShoppingCart

Destination path:
QuoteBookingShoppingCart

What's wrong? Mapping from BookingShoppingCart to BookingShoppingCartCreate works, but from BookingShoppingCartCreate to QuoteShoppingCart - no:( I also tried to specify all members with

.ForMember(dest => dest.AccommodationFeesTotal, exp => exp.MapFrom(scc => scc.AccommodationFeesTotal))

and etc, but no result.

6
  • It complains about property QuoteBookingShopingCart. But that's not in your code. How is that supposed to be mapped? What's its type and the corresponding source property's type. AM says those types cannot be mapped and perhaps you need a map between them. Commented Dec 6, 2019 at 6:24
  • @LucianBargaoanu sorry, don't understand - what property QuoteBookingShoppingCart? It's a class Commented Dec 6, 2019 at 9:51
  • Perhaps you're using an older version that has some weird messages. Then you should upgrade. But the message says Destination path: QuoteBookingShoppingCart. Commented Dec 6, 2019 at 9:54
  • But that's normal, no? I thought that destination path = class in which maps. Also I can see this in stackoverflow.com/questions/14677889/… Commented Dec 6, 2019 at 9:56
  • No, it should be the property. Upgrade. Commented Dec 6, 2019 at 10:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.