public BookingAllocationResortTeamRequest GetCustomerResortTeamRequest(BookingAllocationResponse bookingResponse)
 {
     return(new BookingAllocationResortTeamRequest()
     {
         CustomerResortTeamRequest = PrepareCustomerResortTeamRequest(bookingResponse)
     });
 }
        public bool ValidForProcessing(BookingAllocationResponse bookingResponse, List <Guid> processedCustomers, string responseLog)
        {
            if (bookingResponse == null)
            {
                throw new ArgumentNullException("bookingResponse");
            }
            ;
            if (bookingResponse.ChildHotelTeam == null)
            {
                logger.LogWarning(responseLog + "Not processing this record as no child hotel team exists for this combination of booking's sourcemarket businessunit and hotel owner");
                return(false);
            }

            //customer already allocated
            if (bookingResponse.Customer != null && processedCustomers.Contains(bookingResponse.Customer.Id))
            {
                logger.LogWarning(responseLog + "Not processing this record as customer: " + bookingResponse.Customer.Name + " was already got processed.");
                return(false);
            }
            //accommodation start date is not provided
            if (bookingResponse.AccommodationStartDate == null)
            {
                logger.LogWarning(responseLog + "Not processing this record as accommodation startdate is null");
                return(false);
            }
            return(true);
        }
        public string WriteAllocationResponseLog(BookingAllocationResponse bookingAllocationResponse)
        {
            var information = new StringBuilder();

            if (bookingAllocationResponse != null)
            {
                information.AppendLine();
                information.AppendLine();
                if (bookingAllocationResponse.BookingNumber != null)
                {
                    information.AppendLine($"Processing Booking: '{ bookingAllocationResponse.BookingNumber}'");
                }
            }
            return(information.ToString());
        }
 public bool IsCustomerAllocated(BookingAllocationResponse bookingResponse)
 {
     if (bookingResponse.Customer == null || bookingResponse.Customer.Owner == null || bookingResponse.ChildHotelTeam == null)
     {
         return(false);
     }
     if (bookingResponse.Customer.Owner.OwnerType == OwnerType.Team)
     {
         if (Guid.Equals(bookingResponse.Customer.Owner.Id, bookingResponse.ChildHotelTeam.Id))
         {
             return(true);
         }
     }
     return(false);
 }
        public CustomerResortTeamRequest PrepareCustomerResortTeamRequest(BookingAllocationResponse bookingResponse)
        {
            if (bookingResponse == null)
            {
                throw new ArgumentNullException("bookingResponse");
            }
            if (bookingResponse.Customer == null || bookingResponse.ChildHotelTeam == null)
            {
                return(null);
            }
            var customerResortTeamRequest = new CustomerResortTeamRequest
            {
                Customer = bookingResponse.Customer,
                Owner    = bookingResponse.ChildHotelTeam
            };


            return(customerResortTeamRequest);
        }
        public BookingResortTeamRequest PrepareBookingResortTeamRequest(BookingAllocationResponse bookingResponse)
        {
            if (bookingResponse == null)
            {
                throw new ArgumentNullException("bookingResponse");
            }
            if (bookingResponse.BookingId == null || bookingResponse.ChildHotelTeam == null)
            {
                return(null);
            }
            var bookingResortTeamRequest = new BookingResortTeamRequest
            {
                Id    = bookingResponse.BookingId,
                Name  = bookingResponse.BookingNumber,
                Owner = bookingResponse.ChildHotelTeam
            };


            return(bookingResortTeamRequest);
        }
        public void AddResortTeamRequest(BookingAllocationResponse bookingResponse, IList <BookingAllocationResortTeamRequest> bookingAllocationResortTeamRequests, ResortTeamRequestType resortTeamRequestType)
        {
            if (bookingAllocationResortTeamRequests == null)
            {
                throw new ArgumentNullException("bookingAllocationResortTeamRequests");
            }
            if (bookingResponse == null)
            {
                throw new ArgumentNullException("bookingResponse");
            }

            if (resortTeamRequestType == ResortTeamRequestType.Both)
            {
                bookingAllocationResortTeamRequests.Add(GetResortTeamRequest(bookingResponse));
            }
            else if (resortTeamRequestType == ResortTeamRequestType.BookingRequest)
            {
                bookingAllocationResortTeamRequests.Add(GetBookingResortTeamRequest(bookingResponse));
            }
            else if (resortTeamRequestType == ResortTeamRequestType.CustomerRequest)
            {
                bookingAllocationResortTeamRequests.Add(GetCustomerResortTeamRequest(bookingResponse));
            }
        }
        public string AllocateToChildHotelTeam(BookingAllocationResponse bookingResponse, IList <BookingAllocationResortTeamRequest> bookingAllocationResortTeamRequest, bool differentBooking, bool sameBookingDifferentCustomer, bool bookingAllocated, bool customerAllocated)
        {
            var log = string.Empty;

            if (sameBookingDifferentCustomer)
            {
                if (!customerAllocated)
                {
                    AddResortTeamRequest(bookingResponse, bookingAllocationResortTeamRequest, ResortTeamRequestType.CustomerRequest);
                    log = "<<Processing only customer record as the booking was already processed>>";
                }
                else
                {
                    log = "Booking was already processed and not even processing customer as it was already allocated to child hotel team";
                }
            }
            else if (differentBooking)
            {
                if (!bookingAllocated && !customerAllocated)
                {
                    AddResortTeamRequest(bookingResponse, bookingAllocationResortTeamRequest, ResortTeamRequestType.Both);
                    log = "<<Processing both booking and customer records>>";
                }
                else if (!bookingAllocated)
                {
                    AddResortTeamRequest(bookingResponse, bookingAllocationResortTeamRequest, ResortTeamRequestType.BookingRequest);
                    log = "<<Processing only booking record as the customer was already allocated to child hotel team>>";
                }
                else if (!customerAllocated)
                {
                    AddResortTeamRequest(bookingResponse, bookingAllocationResortTeamRequest, ResortTeamRequestType.CustomerRequest);
                    log = "<<Processing only customer record as the booking was already allocated to child hotel team>>";
                }
            }
            return(log);
        }
Esempio n. 9
0
        public IList <BookingAllocationResponse> PrepareBookingAllocation(EntityCollection bookingCollection, List <ChildHotelTeam> childTeam)
        {
            if (bookingCollection == null || bookingCollection.Entities.Count == 0)
            {
                logger.LogWarning("No booking records found to process in CRM for the schedule.");
                return(null);
            }

            if (childTeam == null || childTeam.Count == 0)
            {
                logger.LogWarning("No child Teams found to process in CRM for the schedule.");
                return(null);
            }

            var bookingAllocationResponse = new List <BookingAllocationResponse>();

            for (int i = 0; i < bookingCollection.Entities.Count; i++)
            {
                var booking = bookingCollection.Entities[i];
                if (booking == null)
                {
                    continue;
                }

                var response = new BookingAllocationResponse();
                if (booking.Contains(Attributes.Booking.BookingId) && booking[Attributes.Booking.BookingId] != null)
                {
                    response.BookingId = Guid.Parse(booking.Attributes[Attributes.Booking.BookingId].ToString());
                }
                if (booking.Contains(Attributes.Booking.Name) && booking.Attributes[Attributes.Booking.Name] != null)
                {
                    response.BookingNumber = booking.Attributes[Attributes.Booking.Name].ToString();
                }

                response.BookingOwner = GetOwner(booking, Attributes.Booking.Owner, false);

                var fieldStartDate    = AliasName.AccommodationAliasName + Attributes.BookingAccommodation.StartDateandTime;
                var fieldEndDate      = AliasName.AccommodationAliasName + Attributes.BookingAccommodation.EndDateandTime;
                var fieldHotelOwner   = AliasName.HotelAliasName + Attributes.Hotel.Owner;
                var fieldHotelName    = AliasName.HotelAliasName + Attributes.Hotel.Name;
                var fieldCustomer     = AliasName.RoleAliasName + Attributes.CustomerBookingRole.Customer;
                var fieldAccountOwner = AliasName.AccountAliasName + Attributes.Customer.Owner;
                var fieldContactOwner = AliasName.ContactAliasName + Attributes.Customer.Owner;

                if (booking.Contains(fieldStartDate) && booking[fieldStartDate] != null)
                {
                    response.AccommodationStartDate = DateTime.Parse(((AliasedValue)booking[fieldStartDate]).Value.ToString());
                }
                if (booking.Contains(fieldEndDate) && booking[fieldEndDate] != null)
                {
                    response.AccommodationEndDate = DateTime.Parse(((AliasedValue)booking[fieldEndDate]).Value.ToString());
                }
                if (booking.Contains(fieldHotelName) && booking[fieldHotelName] != null)
                {
                    response.HotelName = ((AliasedValue)booking[fieldHotelName]).Value.ToString();
                }

                var fieldBusinessUnit = GetBusinessUnitField(booking);
                if (!string.IsNullOrWhiteSpace(fieldBusinessUnit) && booking.Contains(fieldBusinessUnit) && booking[fieldBusinessUnit] != null)
                {
                    var hotelOwner = GetOwner(booking, fieldHotelOwner, true);
                    if (hotelOwner != null)
                    {
                        response.HotelOwner = hotelOwner;
                        var businessUnit = (EntityReference)((AliasedValue)booking[fieldBusinessUnit]).Value;
                        response.SourceMarketBusinessUnit = businessUnit.Name;
                        var team = childTeam.Find(t => t.ParentTeamId == hotelOwner.Id && t.BusinessUnitId == businessUnit.Id);
                        if (team != null && team.ChildTeamId != Guid.Empty)
                        {
                            response.ChildHotelTeam = new Owner {
                                Id = team.ChildTeamId, Name = team.ChildTeamName, OwnerType = OwnerType.Team
                            };
                        }
                    }
                }


                if (booking.Contains(fieldCustomer) && booking[fieldCustomer] != null)
                {
                    var          customer = (EntityReference)((AliasedValue)booking[fieldCustomer]).Value;
                    CustomerType customerType;
                    Owner        owner;

                    if (customer.LogicalName == EntityName.Contact)
                    {
                        customerType = CustomerType.Contact;
                    }
                    else
                    {
                        customerType = CustomerType.Account;
                    }

                    if (booking.Contains(fieldContactOwner) && booking[fieldContactOwner] != null)
                    {
                        owner = GetOwner(booking, fieldContactOwner, true);
                    }
                    else
                    {
                        owner = GetOwner(booking, fieldAccountOwner, true);
                    }


                    response.Customer = new Common.Models.Customer()
                    {
                        Id = customer.Id, Name = customer.Name, CustomerType = customerType, Owner = owner
                    };
                }


                bookingAllocationResponse.Add(response);
            }

            return(bookingAllocationResponse);
        }