/// <summary>
 /// Maps the asynchronous.
 /// </summary>
 /// <param name="gangwayHistory">The gangway history.</param>
 /// <returns>
 /// Return instance of Person Event History.
 /// </returns>
 private static PersonEventHistory MapAsync(GangwayHistory gangwayHistory)
 {
     return new PersonEventHistory
     {
         EventDateTime = gangwayHistory.EventDateTime,
         GangwayEventProcessType = gangwayHistory.EventDetails.GangwayEventProcessType,
         GangwayEventType = gangwayHistory.GangwayEventTypeId,
         GangwayLocation = gangwayHistory.GangwayLocation,
         Port = gangwayHistory.PortCode,
         UserName = gangwayHistory.UserName,
         AlertDescription = gangwayHistory.EventDetails.AlertDescription
     };
 }
 /// <summary>
 /// Maps the specified gangway history.
 /// </summary>
 /// <param name="gangwayHistory">The gangway history.</param>
 /// <returns>
 /// Return instance of Person Event History.
 /// </returns>
 private static PersonEventHistory Map(GangwayHistory gangwayHistory)
 {
     return new PersonEventHistory
     {
         EventDateTime = gangwayHistory.EventDateTime,
         GangwayEventProcessType = gangwayHistory.EventDetails != null ? gangwayHistory.EventDetails.GangwayEventProcessType.ToString() : Manual,
         GangwayEventType = gangwayHistory.GangwayEventTypeId,
         GangwayLocation = gangwayHistory.GangwayLocation,
         Port = gangwayHistory.PortCode,
         UserName = gangwayHistory.UserName,
         GangwayEventDescription = gangwayHistory.EventDetails != null ? gangwayHistory.EventDetails.AlertDescription : null
     };
 }
 /// <summary>
 /// Events the description.
 /// </summary>
 /// <param name="gangwayHistory">The gangway history.</param>
 private void EventDescription(GangwayHistory gangwayHistory)
 {
     if (gangwayHistory != null)
     {
         if (gangwayHistory.EventDetails != null && !string.IsNullOrEmpty(gangwayHistory.EventDetails.AlertDescription) && (gangwayHistory.GangwayEventTypeId.Equals(GangwayEventType.AlertRemoved.RetrieveEventTypeId()) || gangwayHistory.GangwayEventTypeId.Equals(GangwayEventType.MessageRemoved.RetrieveEventTypeId())))
         {
             Messenger.Instance.Notify(MessengerMessage.OpenMessagePopup, gangwayHistory.EventDetails.AlertDescription);
         }
     }
 }
        /// <summary>
        /// Fills the details for popup.
        /// </summary>
        /// <param name="selectedItem">The selected item.</param>
        private void RetrievePersonDetail(GangwayHistory selectedItem)
        {
            var task = Task.Run(async () => await PersonsService.RetrievePersonsBySearchText(Workstation.Ship.ShipId, null, new List<PersonType>() { selectedItem.PersonType }, SearchType.PersonId, personId: selectedItem.PersonId, folioNumber: null));
            task.Wait();
            if (!task.IsCanceled && !task.IsFaulted)
            {
                this.personDetail = task.Result;
                this.personTypeForPopup = selectedItem.PersonType;
            }

            this.RetrieveCountries();
            this.RetrieveLoyaltyLevelTypes();
        }
 /// <summary>
 /// Shows the personal detail view.
 /// </summary>
 /// <param name="selectedItem">The selected item.</param>
 private void ShowPersonalDetailView(GangwayHistory selectedItem)
 {
     if (selectedItem != null)
     {
         Messenger.Instance.Notify(MessengerMessage.ShowSpinWheel, true);
         ObservableManager.RunObservable(() => this.RetrievePersonDetail(selectedItem), this.OnPersonDetailRetrieval);
     }
 }
        /// <summary>
        /// Setups the manager.
        /// </summary>
        private void SetupData()
        {
            var gangwayHistory = new GangwayHistory
            {
                EventDateTime = DateTime.Now,
                FirstName = "Bob",
                GangwayEventTypeId = "1",
                LastName = "Taylor",
                GangwayLocation = "New Jersey",
                PersonId = "600001",
                PersonTypeId = "1",
                PortCode = "445",
                UserName = "******",
                AuthorizedAdultFirstName = "McIntyre",
                AuthorizedAdultLastName = "McBiath",
                EventDetails = new EventDetail
                {
                    AuthorizedAdultPersonId = "54000",
                    AuthorizedAdultPersonTypeId = "1",
                    GangwayEventProcessType = "MSR",
                    ReservationNumber = "5400"
                }
            };

            var items = new Collection<GangwayHistory>();

            for (int i = 0; i < 20; i++)
            {
                items.Add(gangwayHistory);
            }
            this.gangwayHistoryList.AssignItems(items);

            this.gangwayHistoryList.TotalResults = this.gangwayHistoryList.Items.Count;
            this.manager.Setup(data => data.ListAsync(It.IsAny<GangwayHistorySearchParameters>())).Returns(Task.FromResult(this.gangwayHistoryList));
        }
        /// <summary>
        /// Sets the recent person data.
        /// </summary>
        private void SetRecentPersonData()
        {
            var list = new ListResult<GangwayHistory>();
            var gangwayHistory = new GangwayHistory
            {
                AuthorizedAdultFirstName = "TesT",
                AuthorizedAdultLastName = "Test",
                EventDateTime = DateTime.Now,
                EventDetails = new EventDetail { AlertCode = "1", AuthorizedAdultPersonId = "1", AuthorizedAdultPersonTypeId = "1", GangwayEventProcessType = "MSIR", ReservationNumber = "1000" },
                FirstName = "Test",
                GangwayEventTypeId = "0",
                GangwayLocation = "Gangway Location",
                Gender = Gender.Male,
                LastName = "Last Name",
                PersonId = "600001",
                PersonTypeId = "2",
                PortCode = "Port Code",
                UserName = Environment.MachineName
            };
            var gangwayHistory1 = new GangwayHistory
            {
                AuthorizedAdultFirstName = "TesT",
                AuthorizedAdultLastName = "Test",
                EventDateTime = DateTime.Now,
                EventDetails = new EventDetail { AlertCode = "1", AuthorizedAdultPersonId = "1", AuthorizedAdultPersonTypeId = "1", GangwayEventProcessType = "MSIR", ReservationNumber = "1000" },
                FirstName = "Test",
                GangwayEventTypeId = "0",
                GangwayLocation = "Gangway Location",
                Gender = Gender.Male,
                LastName = "Last Name",
                PersonId = "212",
                PersonTypeId = "1",
                PortCode = "Port Code",
                UserName = Environment.MachineName
            };
            var gangwayHistory2 = new GangwayHistory
            {
                AuthorizedAdultFirstName = "TesT",
                AuthorizedAdultLastName = "Test",
                EventDateTime = DateTime.Now,
                EventDetails = new EventDetail { AlertCode = "1", AuthorizedAdultPersonId = "1", AuthorizedAdultPersonTypeId = "1", GangwayEventProcessType = "MSIR", ReservationNumber = "1000" },
                FirstName = "Test",
                GangwayEventTypeId = "0",
                GangwayLocation = "Gangway Location",
                Gender = Gender.Male,
                LastName = "Last Name",
                PersonId = "22",
                PersonTypeId = "3",
                PortCode = "Port Code",
                UserName = Environment.MachineName
            };

            list.Items.Add(gangwayHistory);
            list.Items.Add(gangwayHistory1);
            list.Items.Add(gangwayHistory2);
            this.personRepository.Setup(a => a.RetrievePersonEventsListAsync(It.IsNotNull<PersonHistorySearchParameters>())).Returns(Task.FromResult(list));
        }
 /// <summary>
 /// Maps the guest information.
 /// </summary>
 /// <param name="guests">The guests.</param>
 /// <param name="item">The item.</param>
 private static void MapGuestInformation(ListResult<Guest> guests, GangwayHistory item)
 {
     var value = guests.Items.FirstOrDefault(a => a.GuestId.Equals(item.PersonId));
     if (value != null)
     {
         item.FirstName = value.PersonalDetail.FirstName;
         item.LastName = value.PersonalDetail.LastName;
         item.Gender = value.PersonalDetail.Gender == "1" ? Gender.Male : value.PersonalDetail.Gender == "2" ? Gender.Female : Gender.NotSpecified;
     }
 }
        /// <summary>
        /// Maps the person information.
        /// </summary>
        /// <param name="personTypeList">The person type list.</param>
        /// <param name="guests">The guests.</param>
        /// <param name="crews">The crews.</param>
        /// <param name="visitors">The visitors.</param>
        /// <param name="item">The item.</param>
        private static void MapPersonInformation(ListResult<PersonTypeEntity> personTypeList, ListResult<Guest> guests, ListResult<Crewmember> crews, ListResult<Entities.Visitor> visitors, GangwayHistory item)
        {
            var guestTypePerson = personTypeList.Items.FirstOrDefault(personType => personType.Name.Equals(GuestType, StringComparison.OrdinalIgnoreCase));
            var crewTypePerson = personTypeList.Items.FirstOrDefault(personType => personType.Name.Equals(CrewType, StringComparison.OrdinalIgnoreCase));
            var visitorTypePerson = personTypeList.Items.FirstOrDefault(personType => personType.Name.Equals(VisitorType, StringComparison.OrdinalIgnoreCase));

            if (guestTypePerson != null && guests != null && item.PersonTypeId.Equals(guestTypePerson.PersonTypeId))
            {
                MapGuestInformation(guests, item);
            }

            if (crewTypePerson != null && crews != null && item.PersonTypeId.Equals(crewTypePerson.PersonTypeId))
            {
                MapCrewInformation(crews, item);
            }

            if (visitorTypePerson != null && visitors != null && item.PersonTypeId.Equals(visitorTypePerson.PersonTypeId))
            {
                MapVisitorInformation(visitors, item);
            }
        }
        /// <summary>
        /// Setups the data.
        /// </summary>
        private void SetupData()
        {
            Domain.Dependencies.Register();
            DataAccess.Dependencies.Register();

            Workstation ws = DIContainer.Instance.Resolve<Workstation>();

            ws.Port = new Port { PortId = "1" };
            ws.Ship = new Ship { ShipId = "1" };
            ws.GangwayLocation = new GangwayLocation { LocationId = "1" };
            ws.GangwayServiceBaseAddress = "http://Localhost/";
            ws.ConfigurationServiceBaseAddress = "http://Localhost/";
            ws.AuthenticationServiceBaseAddress = "http://Localhost/";
            ws.AuthorizationServiceBaseAddress = "http://Localhost/";
            ws.ConnectionMode = ConnectionMode.Online;
            var intCollection = new Collection<int>();
            intCollection.Add(0);
            var brand = new Brand { BrandId = "3", Name = "Carnival Breeze", MediaItemAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23" };
            brand.AssignPortIds(intCollection);
            ws.Brand = brand;

            ////this.repository = new Mock<IRepository>();
            ////this.embarkationStatisticsRepositoryMock = new Mock<EmbarkationStatisticsRepository>();
            ////this.personServiceRepositoryMock = new Mock<PersonServiceRepository>();
            ////this.photoCaptureRepositoryMock = new Mock<PhotoCaptureRepository>();
            ////this.shipTimeRepositoryMock = new Mock<ShipTimeRepository>();
            ////this.referenceDataRepositoryMock = new Mock<ReferenceDataRepository>();
            this.gangwayEventRepositoryMock = new Mock<GangwayEventRepository>();

            ////this.gangwayHistoryClient = new Mock<IGangwayHistoryClient>();
            ////this.personsClient = new Mock<IPersonsClient>();
            ////this.guestClient = new Mock<IGuestClient>();

            ////DIContainer.Instance.RegisterInstance<IGuestClient>(this.guestClient.Object);

            ////DIContainer.Instance.RegisterInstance<IPersonsClient>(this.personsClient.Object);

            ////DIContainer.Instance.RegisterInstance<IGangwayHistoryClient>(this.gangwayHistoryClient.Object);

            ////DIContainer.Instance.RegisterInstance<IRepository>(this.repository.Object);
            ////DIContainer.Instance.RegisterInstance<ReferenceDataRepository>(this.referenceDataRepositoryMock.Object);
            ////DIContainer.Instance.RegisterInstance<EmbarkationStatisticsRepository>(this.embarkationStatisticsRepositoryMock.Object);
            DIContainer.Instance.RegisterInstance<GangwayEventRepository>(this.gangwayEventRepositoryMock.Object);
            ////DIContainer.Instance.RegisterInstance<PhotoCaptureRepository>(this.photoCaptureRepositoryMock.Object);
            ////DIContainer.Instance.RegisterInstance<PersonServiceRepository>(this.personServiceRepositoryMock.Object);
            ////DIContainer.Instance.RegisterInstance<ShipTimeRepository>(this.shipTimeRepositoryMock.Object);
            ////this.service = new GangwayEventService();
            var gangwayHistoryData = new ListResult<GangwayHistory>();
            var gangwayHistory = new GangwayHistory { AlertCode = "1", AuthorizedAdultPersonId = "123", AuthorizedFirstName = "Demo", AuthorizedLastName = "demo", AuthorizedAdultPersonType = "1", ChargeId = "1", MachineName = "DC-Dev", PersonId = "123" };
            gangwayHistoryData.Items.Add(gangwayHistory);
            gangwayHistoryData.TotalResults = 1;

            this.gangwayEventRepositoryMock.Setup(a => a.RetrieveGangwayHistoryListAsync(It.IsNotNull<string>(), It.IsNotNull<string>(), 0, 0)).Returns(Task.FromResult(gangwayHistoryData));
            ////var gangwayHistoryData = @"{""ShipId"":""1"",""GangwayLocations"":[{""LocationId"":""1"",""LocationTypeId"":""1"",""Name"":""DK1""},""Voyages"":[{""VoyageId"":""8"",""ShipId"":""1"",""Number"":""SH201503200008"",""Name"":""8 Night Eastern"",""EmbarkDate"":""2015 - 03 - 20T00: 00:00"",""DebarkDate"":""2015 - 03 - 28T00: 00:00"",""EmbarkPortId"":""1"",""DebarkPortId"":""1"",""Nights"":8,""DestinationId"":""9"",""IsActive"":true,""MediaItemAddress"":""http://devweb03.decurtis.com/ImagingMediaService/MediaItems/2"",""Itineraries"":[{""VoyageItineraryId"":""29"",""Day"":2,""IsSeaDay"":true,""PortId"":"""",""ArrivalTime"":null,""DepartureTime"":null,""GangwayOpeningTime"":null,""GangwayClosingTime"":null}]}],""StateroomCategories"":[]}";
            ////this.gangwayHistoryClient.Setup(data => data.RetrieveGangwayHistoryListAsync(It.IsNotNull<string>(), It.IsAny<string>(), It.IsAny<string>(), null, null, 0, 0)).Returns(Task.FromResult(gangwayHistoryData));
        }
 /// <summary>
 /// Maps the crew information.
 /// </summary>
 /// <param name="crews">The crews.</param>
 /// <param name="item">The item.</param>
 private static void MapCrewInformation(ListResult<Crewmember> crews, GangwayHistory item)
 {
     var value = crews.Items.FirstOrDefault(a => a.CrewmemberId.Equals(item.PersonId));
     if (value != null)
     {
         item.FirstName = value.PersonalDetail.FirstName;
         item.LastName = value.PersonalDetail.LastName;
         item.Gender = value.PersonalDetail.Gender;
     }
 }
 /// <summary>
 /// Maps the visitor information.
 /// </summary>
 /// <param name="visitors">The visitors.</param>
 /// <param name="item">The item.</param>
 private static void MapVisitorInformation(ListResult<Visitor> visitors, GangwayHistory item)
 {
     var value = visitors.Items.FirstOrDefault(a => a.VisitorId.Equals(item.PersonId));
     if (value != null)
     {
         item.FirstName = value.PersonalDetail.FirstName;
         item.LastName = value.PersonalDetail.LastName;
         item.Gender = value.PersonalDetail.Gender;
     }
 }
        /// <summary>
        /// Function to assign the gangway history data.
        /// </summary>
        /// <param name="worksheet">Instance of worksheet</param>
        /// <param name="gangwayHistory">Instance of troll gangway event.</param>
        /// <param name="rowNumber">The row number.</param>
        private static void AssignGangwayHistoryData(Worksheet worksheet, GangwayHistory gangwayHistory, int rowNumber)
        {
            string personType;
            worksheet.Cells[rowNumber, PassengerColumnIndex] = string.Format(CultureInfo.CurrentCulture, "{0}, {1}", gangwayHistory.LastName, gangwayHistory.FirstName);
            ////worksheet.Cells[rowNumber, PersonTypeColumnIndex] = trollGangwayEvent.PersonType == PersonType.Guest ? Properties.Resources.Guest : (trollGangwayEvent.PersonType == PersonType.Crew ? Properties.Resources.Crew : Properties.Resources.Visitor);
            worksheet.Cells[rowNumber, LastEventColumnIndex] = gangwayHistory.EventTypeDescription;
            worksheet.Cells[rowNumber, DateTimeColumnIndex] = gangwayHistory.EventDateTime.Value.AddMilliseconds(-gangwayHistory.EventDateTime.Value.Millisecond);

            worksheet.Cells[rowNumber, LocationColumnIndex] = gangwayHistory.GangwayLocation;
            worksheet.Cells[rowNumber, PortColumnIndex] = gangwayHistory.PortCode;
            worksheet.Cells[rowNumber, ProcessTypeColumnIndex] = gangwayHistory.GangwayEventProcessType.ToString();
            worksheet.Cells[rowNumber, UserColumnIndex] = gangwayHistory.UserName;

            if (gangwayHistory.PersonTypeId.Equals(Common.CommonConstants.CrewmemberTypeId))
            {
                personType = PersonType.Crewmember.ToString();
            }
            else if (gangwayHistory.PersonTypeId.Equals(Common.CommonConstants.VisitorTypeId))
            {
                personType = PersonType.Visitor.ToString();
            }
            else
            {
                personType = gangwayHistory.PersonType.ToString();
            }

            worksheet.Cells[rowNumber, DetailsColumnIndex] = personType;
        }
 /// <summary>
 /// Write the data into the Excel sheet
 /// </summary>
 /// <param name="worksheet">Excel WorkSheet</param>
 /// <param name="trollGangwayEvent">Instance of TrollGangwayEvent</param>
 /// <param name="rowNumber">Row Number Value </param>
 private static void WriteDataIntoExcelSheet(Worksheet worksheet, GangwayHistory trollGangwayEvent, int rowNumber)
 {
     AssignGangwayHistoryData(worksheet, trollGangwayEvent, rowNumber);
 }