/// <summary>
 /// Creates the event.
 /// </summary>
 /// <param name="person">The person.</param>
 /// <param name="gangwayEventType">Type of the gangway event.</param>
 /// <param name="personEvent">The person event.</param>
 /// <param name="boardingDetail">The boarding detail.</param>
 /// <param name="clearAlertMessage">The clear alert message.</param>
 public static async void CreateEvent(PersonBase person, GangwayEventType gangwayEventType, PersonEvent personEvent, BoardingDetail boardingDetail, ClearAlertMessage clearAlertMessage)
 {
     if (personEvent != null)
     {
         await GangwayRepositoryFactory.Retrieve().CreateEventAsync(personEvent, boardingDetail, clearAlertMessage);
     }
     else
     {
         var eventDetail = new EventDetail();
         eventDetail.GangwayEventProcessType = person.GangwayEventProcessType.HasValue ? person.GangwayEventProcessType.Value : GangwayEventProcessType.Manual;
         await GangwayRepositoryFactory.Retrieve().CreateEventAsync(MapPersonEvent(person, gangwayEventType, null, null, null, null, eventDetail), null, null);
     }
 }
 /// <summary>
 /// Maps the person status.
 /// </summary>
 /// <param name="personId">The person identifier.</param>
 /// <param name="personTypeId">Type of the person.</param>
 /// <param name="boardingDetail">The boarding detail.</param>
 /// <returns>
 /// Person Status.
 /// </returns>
 internal static PersonStatus Map(string personId, string personTypeId, BoardingDetail boardingDetail)
 {
     return new PersonStatus
     {
         PersonId = personId,
         PersonTypeId = personTypeId,
         StatusChangedDate = boardingDetail.StatusChangedDate,
         StatusChangedDateGMT = boardingDetail.StatusChangedDateGMT,
         StatusChangedBy = !string.IsNullOrEmpty(boardingDetail.StatusChangedBy) ? boardingDetail.StatusChangedBy : boardingDetail.UserId,
         ShipId = boardingDetail.ShipId,
         Status = boardingDetail.Status,
         StatusTypeId = !string.IsNullOrWhiteSpace(boardingDetail.StatusTypeId) ? boardingDetail.StatusTypeId : string.Empty,
         MachineName = boardingDetail.MachineName,
         Port = boardingDetail.PortName,
         GangwayLocation = boardingDetail.GangwayLocation,
         VoyageId = boardingDetail.VoyageId,
         PersonEvent = boardingDetail.PersonEvent
     };
 }
        /// <summary>
        /// Creates the event.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="alertId">The alert identifier.</param>
        /// <param name="gangwayEventType">Type of the gangway event.</param>
        /// <param name="boardingDetail">The boarding detail.</param>
        /// <param name="clearAlertMessage">The clear alert message.</param>
        /// <param name="photoAddress">The photo address.</param>
        /// <param name="mediaItemId">The media item identifier.</param>
        /// <returns>Return instance of Person Event.</returns>
        public static PersonEvent MapPersonEvent(PersonBase person, string alertId, GangwayEventType gangwayEventType, BoardingDetail boardingDetail, ClearAlertMessage clearAlertMessage, string photoAddress, string mediaItemId)
        {
            // Fills event detail.
            var eventDetail = new EventDetail();

            if (person != null)
            {
                eventDetail.GangwayEventProcessType = person.GangwayEventProcessType.HasValue ? person.GangwayEventProcessType.Value : GangwayEventProcessType.Manual;
                eventDetail.AlertCode = alertId;

                var alertData = person.Alerts.FirstOrDefault(alert => alert.IsParentalAuthorizationAlert || alert.IsFolioAlert || alert.IsNotCheckedIn || alert.IsPortManningAlert);

                if (string.IsNullOrEmpty(alertId) && alertData != null)
                {
                    if (alertData != null && alertData.Message != null)
                    {
                        eventDetail.AlertDescription = alertData.Message.Description;
                    }
                }
                else if (gangwayEventType == GangwayEventType.AlertRemoved && !string.IsNullOrEmpty(alertId))
                {
                    eventDetail.AlertDescription = person.Alerts.Where(alert => alert.AlertId.Equals(alertId)).Select(a => a.Message.Description).FirstOrDefault();
                }
                else if (gangwayEventType == GangwayEventType.MessageRemoved && !string.IsNullOrEmpty(alertId))
                {
                    eventDetail.AlertDescription = person.Messages.Where(alert => alert.AlertId.Equals(alertId)).Select(a => a.Message.Description).FirstOrDefault();
                }

                if (person.CruiseDetail != null)
                {
                    eventDetail.ReservationNumber = person.CruiseDetail.ReservationNumber;
                }

                return MapPersonEvent(person, gangwayEventType, boardingDetail, clearAlertMessage, photoAddress, mediaItemId, eventDetail);
            }

            return null;
        }
        /// <summary>
        /// Setups the data.
        /// </summary>
        private void SetupData()
        {
            // Repository registration
            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.User.UserFullName = "DC-Dev60";
            ws.ConnectionMode = ConnectionMode.Online;
            this.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.workStation = ws;

            this.repository = new Mock<GangwayEventRepository>();
            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>();

            DIContainer.Instance.RegisterType<IPersonsClient, PersonsClientTest>();
            DIContainer.Instance.RegisterType<IGuestClient, GuestClientTest>();

            DIContainer.Instance.RegisterInstance<GangwayEventRepository>(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);
            var boardingDetail = new BoardingDetail
            {
                GangwayLocation = "location",
                MachineName = "GWY terminal",
                PortName = "port",
                ShipId = "1",
                Status = "onboard",
                StatusTypeId = "1",
                UserId = "1"
            };
            var personEvent = new PersonEvent { PersonId = "123", ApplicationId = "1" };
            this.repository.Setup(a => a.CreateEventAsync(personEvent)).Returns(Task.FromResult("Successful"));
        }
        /// <summary>
        /// insert person status
        /// </summary>
        /// <param name="personId">The person Id.</param>
        /// <param name="personTypeId">Type of the person.</param>
        /// <param name="boardingDetail">boarding details for person status change</param>
        /// <returns> result message</returns>
        public async Task<string> UpdatePersonStatusAsync(string personId, string personTypeId, BoardingDetail boardingDetail)
        {
            string status;
            var task = await this.personsClient.UpdateBoardingDetailAsync(personId, personTypeId, JsonConvert.SerializeObject(boardingDetail), isOnlineMode: true);
            status = task != string.Empty ? JsonConvert.DeserializeObject<string>(task) : default(string);

            return await Task.FromResult(status);
        }
        /// <summary>
        /// Creates the event.
        /// </summary>
        /// <param name="personEvent">The person event.</param>
        /// <param name="boardingDetail">The boarding detail.</param>
        /// <param name="clearAlertMessage">The clear alert message.</param>
        /// <returns>
        /// Task Containing string.
        /// </returns>
        public async Task<string> CreateEventAsync(PersonEvent personEvent, BoardingDetail boardingDetail, ClearAlertMessage clearAlertMessage)
        {
            var command = this.Database.GetStoredProcCommand(InsertPersonEventDetailStoredProcedure)
                .AddParameter(MediaItemIdField, DbType.Int32, Convert.ToInt32(personEvent.MediaItemId))
                .AddParameter(MediaItemTypeIdField, DbType.Int32, Convert.ToInt32(personEvent.MediaTypeId))
                .AddParameter(PhotoURLField, DbType.String, personEvent.PhotoAddress)
                .AddParameter(() => boardingDetail != null, PersonStatusJSONField, DbType.String, JsonConvert.SerializeObject(boardingDetail))
                .AddParameter(PersonEventJSONField, DbType.String, JsonConvert.SerializeObject(personEvent))
                .AddParameter(() => clearAlertMessage != null, PersonNotificationJSONField, DbType.String, JsonConvert.SerializeObject(clearAlertMessage))
                .AddParameter(PersonEventDetailField, DbType.Xml, personEvent.RetrieveXml())
                .AddParameter(EventDetailsField, DbType.Xml, personEvent.EventDetails)
                .AddParameter(LinkIdField, DbType.String, string.IsNullOrEmpty(personEvent.LinkId) ? Guid.NewGuid().ToString() : personEvent.LinkId)
                .AddParameter(AlternateIdField, DbType.String, personEvent.AlternateId);

            return await this.ExecuteReaderAsync(command, GangwayEventDataMapper.MapGangwayEventStatusAsync);
        }
 /// <summary>
 /// Creates the event.
 /// </summary>
 /// <param name="personEvent">The person event.</param>
 /// <param name="boardingDetail">The boarding detail.</param>
 /// <param name="clearAlertMessage">The clear alert message.</param>
 /// <returns>
 /// Task Containing string.
 /// </returns>
 public async Task<string> CreateEventAsync(PersonEvent personEvent, BoardingDetail boardingDetail, ClearAlertMessage clearAlertMessage)
 {
     return await this.gangwayEventRepository.CreateEventAsync(personEvent);
 }
 /// <summary>
 /// insert person status
 /// </summary>
 /// <param name="personId">The person Id.</param>
 /// <param name="personTypeId">Type of the person.</param>
 /// <param name="boardingDetail">boarding details for person status changes</param>
 /// <param name="personEvent">The person event.</param>
 /// <returns>
 /// result message
 /// </returns>
 public async Task<string> UpdatePersonStatusAsync(string personId, string personTypeId, BoardingDetail boardingDetail, PersonEvent personEvent)
 {
     return await this.personServiceRepository.UpdatePersonStatusAsync(personId, personTypeId, boardingDetail);
 }
 /// <summary>
 /// Creates the person event.
 /// </summary>
 /// <param name="person">The person.</param>
 /// <param name="gangwayEventType">Type of the gangway event.</param>
 /// <param name="boardingDetail">The boarding detail.</param>
 /// <param name="clearAlertMessage">The clear alert message.</param>
 /// <param name="photoAddress">The photo address.</param>
 /// <param name="mediaItemId">The media item identifier.</param>
 /// <param name="eventDetail">The event detail.</param>
 /// <returns>Return instance of Person Event.</returns>
 private static PersonEvent MapPersonEvent(PersonBase person, GangwayEventType gangwayEventType, BoardingDetail boardingDetail, ClearAlertMessage clearAlertMessage, string photoAddress, string mediaItemId, EventDetail eventDetail)
 {
     var workstation = DIContainer.Instance.Resolve<Workstation>();
     string eventTypeId = gangwayEventType.RetrieveEventTypeId();
     return new PersonEvent()
     {
         EventTypeId = eventTypeId,
         AlternateId = Guid.NewGuid().ToString(),
         PersonId = person.PersonId,
         PersonTypeId = person.PersonTypeId,
         ShipId = workstation.Ship != null ? workstation.Ship.ShipId : null,
         MachineName = workstation.MachineName,
         Location = workstation.GangwayLocation != null ? workstation.GangwayLocation.Name : null,
         Port = workstation.Port != null ? workstation.Port.Name : null,
         AddedBy = workstation.User != null ? workstation.User.UserFullName : null,
         EventDetails = eventDetail != null ? eventDetail.RetrieveXml() : null,
         EventDate = workstation.CurrentDateTime,
         EventDateGMT = DateTime.UtcNow,
         ApplicationId = CommonConstants.ApplicationId,
         VoyageId = person.CruiseDetail != null ? person.CruiseDetail.VoyageId : null,
         LinkId = person.LinkId,
         PersonStatusDetail = workstation.ConnectionMode == ConnectionMode.Offline ? boardingDetail : null,
         PersonNotificationDetail = workstation.ConnectionMode == ConnectionMode.Offline ? clearAlertMessage : null,
         PhotoAddress = photoAddress,
         MediaItemId = mediaItemId,
         MediaTypeId = CommonConstants.MediaItemTypeId
     };
 }
 public async Task UpdateVisitorBoardingDetail()
 {
     try
     {
         CommonDependencies();
         var boardingDetail = new BoardingDetail { ShipId = "2", GangwayLocation = "Gangway Location", VoyageId = "1", MachineName = Environment.MachineName, PortName = "PortName", Status = "true", StatusChangedDate = DateTime.Now, StatusTypeId = "1", UserId = "1", EventDetail = new EventDetail { AlertCode = "1", AuthorizedAdultPersonId = "1", AuthorizedAdultPersonTypeId = "1", GangwayEventProcessType = "MSIR", ReservationNumber = "121wer" } };
         await this.manager.UpdatePersonStatusAsync("1", "3", false, boardingDetail);
     }
     finally
     {
         this.Dispose();
     }
 }
 /// <summary>
 /// Updates the person status asynchronous.
 /// </summary>
 /// <param name="personId">The person identifier.</param>
 /// <param name="personTypeId">Type of the person.</param>
 /// <param name="isOnlineMode">if set to <c>true</c> [is on line mode].</param>
 /// <param name="boardingDetail">The boarding detail.</param>
 /// <returns>
 /// Task containing string
 /// </returns>
 public async Task<string> UpdatePersonStatusAsync(string personId, string personTypeId, bool isOnlineMode, BoardingDetail boardingDetail)
 {
     var personStatus = PersonStatusMapper.Map(personId, personTypeId, boardingDetail);
     return await this.personRepository.UpdatePersonStatusAsync(personStatus, isOnlineMode);
 }
        /// <summary>
        /// Update person status
        /// </summary>
        /// <param name="personId">The person Id.</param>
        /// <param name="personTypeId">Type of the person.</param>
        /// <param name="boardingDetail">boarding details for person status change</param>
        /// <returns> result message</returns>
        public async Task<string> UpdatePersonStatusAsync(string personId, string personTypeId, BoardingDetail boardingDetail)
        {
            var command = this.Database.GetStoredProcCommand(UpdatePersonStatusStoredProcedure)
                .AddParameter(LinkId, DbType.String, boardingDetail.LinkId)
                .AddParameter(PersonStatusDetail, DbType.Xml, boardingDetail.RetrieveXml());
            string status = await this.ExecuteReaderAsync(command, PersonDataMapper.MapPersonStatusAsync);

            return await Task.FromResult(status);
        }
        private void SetUpData()
        {
            Domain.Dependencies.Register();

            //Repository registration
            DIContainer.Instance.RegisterType<IRepository, OnlineRepository>(OnlineRepository.InstanceName);
            DIContainer.Instance.RegisterType<ReferenceDataRepository>(new ContainerControlledLifetimeManager());
            DIContainer.Instance.RegisterType<IPersonsClient, PersonsClientTest>();
            DIContainer.Instance.RegisterType<IGuestClient, GuestClientTest>();
            DIContainer.Instance.RegisterType<ICrewmemberClient, CrewmemberClientTest>();

            var workStation = DIContainer.Instance.Resolve<Workstation>();
            workStation.GangwayServiceBaseAddress = "http://Localhost/";
            var voyages = new List<Voyage>();
            voyages.Add(new Voyage { IsActive = true, VoyageId = "31", Number = "dd0", ShipId = "1" });
            workStation.AssignVoyageList(voyages);
            this.targetRepository = new PersonServiceRepository();

            workStation.MaxRecentPersonCount = 1;
            workStation.Ship = new Ship { ShipId = "1", BrandId = "3", Code = "3" };

            this.personTypes = new List<PersonType>();
            personTypes.Add(PersonType.Guest);

            this.boardingDetail = new BoardingDetail
            {
                GangwayLocation = "location",
                MachineName = "GWY terminal",
                PortName = "port",
                ShipId = "1",
                Status = "onboard",
                StatusTypeId = "1",
                UserId = "1"
            };
            var port = new Port { State = "state", PortId = "1", StateId = "1", Name = "port", City = "city", IsAtSea = true, Code = "code", CountryId = "1", MediaItem = new MediaItem { MediaItemAddress = "", MediaTypeId = "1" }, Description = "Description test" };
        }
 public async Task UpdateVisitorBoardingDetail()
 {
     try
     {
         SetupController(this.controller, HttpMethod.Post);
         var boardingDetail = new BoardingDetail { ShipId = "2", EventDetail = new EventDetail() };
         var actionResult = await this.controller.UpdateBoardingDetail("1", "3", boardingDetail, false);
         Assert.IsNotNull(actionResult);
     }
     finally
     {
         this.Dispose();
     }
 }
 /// <summary>
 /// Function to update person boarding status.
 /// </summary>
 /// <param name="person">Instance of PersonBase</param>
 /// <param name="personStatus">Instance of BoardingDetail</param>
 /// <param name="personEvent">The person event.</param>
 private static void UpdatePersonBoardingStatus(PersonBase person, BoardingDetail personStatus, PersonEvent personEvent)
 {
     var task = Task.Run(() => GangwayRepositoryFactory.Retrieve().UpdatePersonStatusAsync(person.PersonId, person.PersonTypeId, personStatus, personEvent));
     task.Wait();
 }
        /// <summary>
        /// Function to fill BoardingDetail.
        /// </summary>
        /// <param name="person">Instance of PersonBase</param>
        /// <param name="personEvent">The person event.</param>
        /// <param name="isOnboard">Whether guest status will be onboard or ashore</param>
        /// <returns>
        /// Instance of BoardingDetail
        /// </returns>
        private BoardingDetail FillBoardingDetail(PersonBase person, PersonEvent personEvent, bool isOnboard)
        {
            BoardingDetail boardingDetail = new BoardingDetail();
            boardingDetail.PersonId = person.PersonId;
            boardingDetail.PersonTypeId = person.PersonTypeId;
            boardingDetail.StatusTypeId = CommonConstants.BoardingStatusTypeId;
            boardingDetail.ShipId = this.workstation.Ship.ShipId;
            boardingDetail.Status = isOnboard ? CommonConstants.OnboardStatusParameter : CommonConstants.AshoreStatusParameter;
            boardingDetail.StatusChangedDate = this.workstation.CurrentDateTime;
            boardingDetail.StatusChangedDateGMT = DateTime.UtcNow;
            boardingDetail.UserId = this.workstation.User.UserId;
            boardingDetail.PortName = this.workstation.Port.Name;
            boardingDetail.GangwayLocation = this.workstation.GangwayLocation.Name;
            boardingDetail.MachineName = Environment.MachineName;
            boardingDetail.VoyageId = person.CruiseDetail.VoyageId;
            boardingDetail.LinkId = person.LinkId;
            boardingDetail.StatusChangedBy = this.workstation.User.UserId;
            boardingDetail.PersonEvent = personEvent;

            return boardingDetail;
        }