/// <summary>
        /// Sets the paged records for alert.
        /// </summary>
        /// <param name="presenter">The presenter.</param>
        /// <param name="alerts">The alerts.</param>
        private void SetPagedRecordsForAlert(PassengerPresenter presenter, ListResult<Alert> alerts)
        {
            var visitorAlerts = alerts.Items.Where(alert => !alert.IsMessage).ToList();
            var visitorAlertsResult = new ListResult<Alert>();
            visitorAlertsResult.AssignItems(visitorAlerts);
            SessionData.Instance.AssignAlertSearchResult(visitorAlertsResult);
            this.ExtractAlertPagedRecords(presenter);

            var visitorMessages = alerts.Items.Where(alert => alert.IsMessage).ToList();
            var visitorMessagesResult = new ListResult<Alert>();
            visitorMessagesResult.AssignItems(visitorMessages);
            SessionData.Instance.AssignMessageSearchResult(visitorMessagesResult);
            this.ExtractMessagePagedRecords(presenter);
        }
        /// <summary>
        /// Maps the alert data from database.
        /// </summary>
        /// <param name="alertData">The alert data.</param>
        /// <returns>
        /// Alert type list
        /// </returns>
        private static ListResult<Entities.AlertType> MapAlertDataListFromService(ListResult<Entities.PersonNotification.Alert> alertData)
        {
            var result = new ListResult<Entities.AlertType>();
            var alerts = new AlertTypeCollection();

            foreach (var alert in alertData.Items)
            {
                Entities.AlertType alertTypeData = new Entities.AlertType();

                alertTypeData.AlertTypeId = alert.AlertId;
                alertTypeData.AddedBy = alert.AddedBy;
                alertTypeData.AddedDate = alert.AddedDate;
                alertTypeData.Description = alert.Description;
                alertTypeData.DueDate = alert.DueDate;
                alertTypeData.ExpiryDate = alert.ExpiryDate;
                alertTypeData.IsOverride = alert.IsOverride;
                alertTypeData.IsSoundEnable = alert.IsSoundEnable;
                alertTypeData.ModifiedBy = alert.LastModifiedBy;
                alertTypeData.IsMessage = false;
                alertTypeData.IsTemplate = false;
                alertTypeData.DepartmentId = alert.DepartmentId;

                foreach (var applicationIds in alert.AlertTargetApplications)
                {
                    alertTypeData.ApplicationId = applicationIds.ApplicationId;
                }

                alertTypeData.TypeId = alert.AlertTypeId;

                foreach (var personAlerts in alert.PersonAlerts)
                {
                    Entities.Alert personAlert = new Entities.Alert();

                    personAlert.PersonId = personAlerts.PersonId;
                    personAlert.PersonTypeId = personAlerts.PersonTypeId;
                    personAlert.ShipId = personAlerts.ShipId;
                    personAlert.VoyageId = personAlerts.VoyageId;
                    personAlert.StatusId = personAlerts.StatusId;
                    personAlert.AlertTypeId = personAlerts.AlertId;
                    personAlert.PersonAlertId = personAlerts.PersonAlertId;

                    alertTypeData.Alerts.Add(personAlert);
                }

                alerts.Add(alertTypeData);
            }

            result.AssignItems(alerts);

            return result;
        }
        /// <summary>
        /// Maps the alert template data from service.
        /// </summary>
        /// <param name="messageTemplateResults">The message template results.</param>
        /// <returns>
        /// Message template data
        /// </returns>
        private static ListResult<Entities.AlertType> MapMessageTemplateDataListFromService(ListResult<MessageTemplate> messageTemplateResults)
        {
            var result = new ListResult<Entities.AlertType>();
            var messageTemplate = new AlertTypeCollection();

            foreach (var message in messageTemplateResults.Items)
            {
                var messageTempalteData = new Entities.AlertType();

                messageTempalteData.Description = message.Description;
                messageTempalteData.ModifiedBy = message.LastModifiedBy;
                messageTempalteData.AlertTypeId = message.MessageTemplateId;
                messageTempalteData.IsTemplate = true;
                messageTempalteData.IsMessage = true;

                messageTemplate.Add(messageTempalteData);
            }

            result.AssignItems(messageTemplate);

            return result;
        }
        /// <summary>
        /// Maps the person.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <returns>Person list</returns>
        internal static async Task<ListResult<Person>> MapPerson(SqlDataReader dataReader)
        {
            var persons = new ListResult<Person>();
            var person = new Person();
            var personCollection = new Collection<Person>();

            if (dataReader != null)
            {
                ////Map Crew
                person.AssignCrewmembers(await MapCrew(dataReader));

                ////Map Crew Personal Detail
                await dataReader.NextResultAsync();
                var crewPersonDetailList = await RetrieveCrewmemberPersonalDetail(dataReader);

                ////map access card
                await dataReader.NextResultAsync();
                var crewAccessCards = await AccessCardMapper.MapCrewAccessCards(dataReader);

                ////Map Crew Alerts
                await dataReader.NextResultAsync();
                var alerts = await AlertsAndMessageMapper.MapCrewAlerts(dataReader);

                await dataReader.NextResultAsync();
                var alertMessages = await AlertsAndMessageMapper.MapMessagesDescription(dataReader);

                await dataReader.NextResultAsync();
                var messages = await AlertsAndMessageMapper.MapCrewMessages(dataReader);

                await dataReader.NextResultAsync();
                var messageDescription = await AlertsAndMessageMapper.MapMessagesDescription(dataReader);

                MapCrewDetail(person, crewPersonDetailList, alerts, alertMessages, messages, messageDescription, crewAccessCards);

                ////Map Visitor
                await dataReader.NextResultAsync();
                person.AssignVisitors(await MapVisitors(dataReader));

                ////Map Visitor Personal Detail
                await dataReader.NextResultAsync();
                var visitorPersonalDetailList = await RetrieveVisitorPersonalDetail(dataReader);

                ////Map Visitor access card
                await dataReader.NextResultAsync();
                var visitorAccessCards = await AccessCardMapper.MapVisitorAccessCards(dataReader);

                ////Map Visitor Alerts
                await dataReader.NextResultAsync();
                var visitorAlerts = await AlertsAndMessageMapper.MapVisitorAlerts(dataReader);

                await dataReader.NextResultAsync();
                var visitorAlertMessages = await AlertsAndMessageMapper.MapMessagesDescription(dataReader);

                await dataReader.NextResultAsync();
                var visitorMessages = await AlertsAndMessageMapper.MapVisitorMessages(dataReader);

                await dataReader.NextResultAsync();
                var visitorMessagesDescription = await AlertsAndMessageMapper.MapMessagesDescription(dataReader);

                MapVisitorDetail(person, visitorPersonalDetailList, visitorAlerts, visitorAlertMessages, visitorMessages, visitorMessagesDescription, visitorAccessCards);

                ////Map Guest
                await dataReader.NextResultAsync();
                person.AssignGuests(await MapGuests(dataReader));

                ////Map Guest Personal Detail
                await dataReader.NextResultAsync();
                var guestPersonDetailList = await RetrieveGuestPersonalDetail(dataReader);

                ////Map Guest Cruise Detail
                await dataReader.NextResultAsync();
                var guestReservationDetailList = await RetrieveGuestReservationDetail(dataReader);

                ////Map Guest Alerts
                await dataReader.NextResultAsync();
                var guestAlerts = await AlertsAndMessageMapper.MapGuestAlerts(dataReader);

                await dataReader.NextResultAsync();
                var guestAlertMessages = await AlertsAndMessageMapper.MapMessagesDescription(dataReader);

                await dataReader.NextResultAsync();
                var guestMessages = await AlertsAndMessageMapper.MapGuestMessages(dataReader);

                await dataReader.NextResultAsync();
                var guestMessagesDescription = await AlertsAndMessageMapper.MapMessagesDescription(dataReader);

                // Map folio data.
                await dataReader.NextResultAsync();
                var folioList = await RetrieveFolios(dataReader);

                MapGuestDetail(person, guestPersonDetailList, guestReservationDetailList, guestAlerts, guestAlertMessages, guestMessages, guestMessagesDescription, folioList);

                ////map total results
                await dataReader.NextResultAsync();
                await MapTotalResults(dataReader, person);

                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }
            }

            personCollection.Add(person);
            persons.AssignItems(personCollection);
            return await Task.FromResult(persons);
        }
        /// <summary>
        /// Adds the passenger.
        /// </summary>
        /// <param name="presenter">The alert presenter.</param>
        /// <param name="personId">The person ids.</param>
        /// <returns>
        /// The JSON Result
        /// </returns>
        public ActionResult AddPassenger(AlertPresenter presenter, string personId)
        {
            var alertPresenter = new AlertPresenter();
            if (presenter != null)
            {
                alertPresenter = presenter;
            }

            if (!string.IsNullOrEmpty(personId))
            {
                var filteredPersonList = new List<Person>();
                var personSearchResult = new ListResult<Person>();
                if (!SessionData.Instance.SelectedPersonIds.Contains(personId))
                {
                    SessionData.Instance.SelectedPersonIds.Add(personId);
                }

                if (SessionData.Instance.PassengerAutoSearchItems != null && SessionData.Instance.PassengerAutoSearchItems.Items.Count > 0)
                {
                    filteredPersonList.Add(SessionData.Instance.PassengerAutoSearchItems.Items.FirstOrDefault(person => person.PersonId.Equals(personId)));
                }

                if (filteredPersonList.Count > 0)
                {
                    if (SessionData.Instance.FilterPersonList != null && SessionData.Instance.FilterPersonList.Count > 0)
                    {
                        foreach (var person in SessionData.Instance.FilterPersonList.Where(person => !person.PersonId.Equals(personId)))
                        {
                            filteredPersonList.Add(person);
                        }
                    }

                    personSearchResult.AssignItems(filteredPersonList);
                    alertPresenter.AssignPersonSearchResult(personSearchResult);
                    SessionData.Instance.AssignFilterPersonResult(filteredPersonList);
                }

                return this.PartialView(AlertPassengerListPartialView, alertPresenter);
            }

            return this.View();
        }
        /// <summary>
        /// Retrieves the crew lists.
        /// </summary>
        /// <param name="personSearchParameter">The person search parameter.</param>
        /// <param name="isAlertCount">if set to <c>true</c> [is alert count].</param>
        /// <param name="crewIds">The crew ids.</param>
        /// <returns>The Crew list.</returns>
        private async Task<ListResult<Person>> RetrieveCrewLists(PersonSearchParameter personSearchParameter, bool isAlertCount, List<string> crewIds)
        {
            ListResult<Person> personList = new ListResult<Person>();
            if (crewIds.Count == 0 || !string.IsNullOrWhiteSpace(personSearchParameter.Birthdate) || !string.IsNullOrWhiteSpace(personSearchParameter.ReservationNo))
            {
                return personList;
            }

            ListResult<Stateroom> staterooms = new ListResult<Stateroom>();
            var crews = await this.crewClientRepository.RetrieveCrewmembersList(crewIds.RetrieveIds(id => id), personSearchParameter.LastNameContains, null, personSearchParameter.Citizenship, personSearchParameter.PassportNo, 1, int.MaxValue, CrewDepths.Crew);
            if (string.IsNullOrWhiteSpace(personSearchParameter.Stateroom))
            {
                var crewStateroomIds = crews.Items.RetrieveIds(a => a.StateroomId);
                if (!string.IsNullOrWhiteSpace(crewStateroomIds))
                {
                    staterooms = await this.RetrieveStaterooms(crewStateroomIds.TrimEnd(','), null);
                }
            }

            PersonMapper.MapPersonsByCrews(crews, staterooms, personList);
            var alerts = await this.RetrievePersonAlerts(personSearchParameter, personList.Items.RetrieveIds(p => p.PersonId));
            PersonMapper.MapPersonAlerts(alerts, personList);
            personList.AssignItems(personList.Items.Where(item => isAlertCount ? item.AlertCount > 0 : item.MessageCount > 0).ToList());
            personList.TotalResults = personList.Items.Count;
            personList.CrewTotalResults = personList.Items.Count;
            return personList;
        }
        /// <summary>
        /// Retrieves the person alerts.
        /// </summary>
        /// <param name="personSearchParameter">The person search parameter.</param>
        /// <param name="personIds">The person ids.</param>
        /// <returns>
        /// The alerts.
        /// </returns>
        private async Task<ListResult<Entities.AlertType>> RetrievePersonAlerts(PersonSearchParameter personSearchParameter, string personIds)
        {
            var isMessage = false;
            var isAlert = false;

            if (personSearchParameter.IsMessageCount != null && Convert.ToBoolean(personSearchParameter.IsMessageCount, CultureInfo.CurrentCulture))
            {
                isMessage = true;
            }

            if (personSearchParameter.IsAlertCount != null && Convert.ToBoolean(personSearchParameter.IsAlertCount, CultureInfo.CurrentCulture))
            {
                isAlert = true;
            }

            var alertSearchParameter = new AlertListRequestSearchParameters
            {
                ApplicationId = Convert.ToString(this.applicationSettings.ApplicationId, CultureInfo.CurrentCulture),
                PersonIds = personIds,
                IsMessage = isMessage,
                IsAlert = isAlert,
                IsExpiredAlert = false
            };
            if (string.IsNullOrWhiteSpace(personSearchParameter.ShipTime))
            {
                var shipTimeTask = await this.shipTimeRepository.GetByIdAsync(this.applicationSettings.ShipId, null);
                alertSearchParameter.ShipTime = string.IsNullOrWhiteSpace(shipTimeTask) ? DateTime.Now : DateTime.UtcNow.AddMinutes(Convert.ToDouble(shipTimeTask));
            }
            else
            {
                alertSearchParameter.ShipTime = DateTime.Parse(personSearchParameter.ShipTime, CultureInfo.InvariantCulture);
            }

            var result = new ListResult<Entities.AlertType>();
            var alertTemplate = new Entities.AlertTypeCollection();
            var alertDetails = await this.RetrieveAlertDetails(alertSearchParameter);

            foreach (var alert in alertDetails.Items)
            {
                if ((alert.ExpiryDate.HasValue && alert.ExpiryDate.Value > alertSearchParameter.ShipTime) || !alert.ExpiryDate.HasValue)
                {
                    var active = alert.Alerts.Any(personAlert => personAlert.StatusId == "1");
                    if (active)
                    {
                        alertTemplate.Add(alert);
                    }
                }
            }

            result.AssignItems(alertTemplate);
            return result;
        }
        public void ResetMessagePassengersTest()
        {
            try
            {
                SessionData.Instance.User = CommonHelper.SetupUserData();
                var messagePresenter = new MessagePresenter();
                string templateValue = string.Empty;
                Alert alertDetailResult = SetUpAlertData();
                alertDetailResult.Persons = new PersonCollection { new Person { PersonId = "1228", PersonTypeId = "3", PersonalDetail = new PersonalDetail { FirstName = "R", LastName = "Della", DepartmentId = string.Empty, CitizenshipCountryId = "102", Gender = "M", Title = "Mr." } } };

                if (alertDetailResult.Persons.Count > 0 && string.IsNullOrEmpty(templateValue))
                {
                    var personList = new ListResult<Person>();
                    personList.AssignItems(alertDetailResult.Persons);

                    messagePresenter.AssignPersonSearchResult(personList);

                    foreach (var person in alertDetailResult.Persons)
                    {
                        SessionData.Instance.SelectedPersonIds.Add(person.PersonId);
                    }

                    SessionData.Instance.AssignFilterPersonResult(alertDetailResult.Persons);
                }

                this.messageController.ResetPassengers(new MessagePresenter());
                Assert.IsTrue(true);
            }
            finally
            {
                this.Dispose();
            }
        }
        public async Task CreatedMessageListTest()
        {
            SessionData.Instance.User = CommonHelper.SetupUserData();
            var messagePresenter = SetUpMessagePresenter();
            var alertItem = new List<Alert>();
            alertItem.Add(new Alert { AddedDate = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture) });
            var alertItemList = new ListResult<Alert>();
            alertItemList.AssignItems(new List<Alert>());
            this.alertManager.Setup(mockItem => mockItem.AlertTypeAsync(It.IsNotNull<string>(), It.IsNotNull<bool>(), It.IsNotNull<bool>(), It.IsNotNull<bool>(), It.IsNotNull<string>(), It.IsNotNull<bool>(), It.IsAny<string>())).Returns(Task.FromResult(alertItemList));
            var result = await this.messageController.CreatedMessageList(messagePresenter);
            Assert.IsNotNull(result);

            alertItemList.AssignItems(alertItem);
            this.alertManager.Setup(mockItem => mockItem.AlertTypeAsync(It.IsNotNull<string>(), It.IsNotNull<bool>(), It.IsNotNull<bool>(), It.IsNotNull<bool>(), It.IsNotNull<string>(), It.IsNotNull<bool>(), It.IsAny<string>())).Returns(Task.FromResult(alertItemList));
            result = await this.messageController.CreatedMessageList(messagePresenter);
            Assert.IsNotNull(result);
        }
 public async Task MessageControllerIndexTest()
 {
     try
     {
         SessionData.Instance.User = CommonHelper.SetupUserData();
         MessagePresenter messagePresenter = SetUpMessagePresenter();
         var alertList = new ListResult<Alert>();
         alertList.AssignItems(new List<Alert> { SetUpAlertData() });
         this.alertManager.Setup(mockItem => mockItem.AlertTypeAsync(It.IsNotNull<string>(), It.IsNotNull<bool>(), It.IsNotNull<bool>(), It.IsNotNull<bool>(), It.IsNotNull<string>(), It.IsNotNull<bool>(), It.IsAny<string>())).Returns(Task.FromResult(alertList));
         var result = await this.messageController.Index(messagePresenter) as ViewResult;
         Assert.IsTrue(true);
     }
     finally
     {
         this.Dispose();
     }
 }
        public void MessageDeletePassengerTest()
        {
            try
            {
                SessionData.Instance.User = CommonHelper.SetupUserData();
                MessagePresenter messagePresenter = SetUpMessagePresenter();
                string templateValue = null;
                string alertId = "2";
                Alert alertDetailResult = SetUpAlertData();
                alertDetailResult.Persons = new PersonCollection { new Person { PersonId = "1228", PersonTypeId = "3", PersonalDetail = new PersonalDetail { FirstName = "R", LastName = "Della", DepartmentId = string.Empty, CitizenshipCountryId = "102", Gender = "M", Title = "Mr." } } };
                messagePresenter.SelectedAlertTypes = Convert.ToString(alertDetailResult.TypeId, CultureInfo.InvariantCulture);
                messagePresenter.UserName = alertDetailResult.UserName;
                messagePresenter.StartDate = alertDetailResult.StartDate.ToString("MM-dd-yyyy HH':'mm':'ss", CultureInfo.InvariantCulture);
                messagePresenter.ExpiryDate = alertDetailResult.ExpiryDate.Value.ToString("MM-dd-yyyy HH':'mm':'ss", CultureInfo.InvariantCulture);
                messagePresenter.PersonCount = alertDetailResult.PersonCount;
                messagePresenter.IsOverrideAllowed = alertDetailResult.IsOverride;
                messagePresenter.IsSoundEnable = alertDetailResult.IsSoundEnable;
                SessionData.Instance.ActiveAlertId = alertId;
                SessionData.Instance.AssignAlertData(alertDetailResult);
                if (alertDetailResult.Persons.Count > 0 && string.IsNullOrEmpty(templateValue))
                {
                    var personList = new ListResult<Person>();
                    personList.AssignItems(alertDetailResult.Persons);

                    messagePresenter.AssignPersonSearchResult(personList);

                    foreach (var person in alertDetailResult.Persons)
                    {
                        SessionData.Instance.SelectedPersonIds.Add(person.PersonId);
                    }

                    SessionData.Instance.AssignFilterPersonResult(alertDetailResult.Persons);
                }

                var result = this.messageController.MessageDeletePassenger(new MessagePresenter(), "1228", "SetData") as JsonResult;
                Assert.IsTrue(result.Data.Equals(true));
                Assert.IsTrue(true);
            }
            finally
            {
                this.Dispose();
            }
        }
        public void PagingTest()
        {
            var persons = SetUpPersonData();
            var personList = persons.Items.ToList();
            SessionData.Instance.AssignFilterPersonResult(personList);
            this.personManager.Setup(mockItem => mockItem.GetPersonsAsync(It.IsNotNull<SearchFilters>(), It.IsAny<string>())).Returns(Task.FromResult(persons));
            var pagingResult = this.alertController.Paging(new AlertPresenter(), "1", AlertPassengerListPartialView) as PartialViewResult;
            Assert.AreEqual(pagingResult.ViewName, AlertPassengerListPartialView);

            this.personManager.Setup(mockItem => mockItem.GetPersonsAsync(It.IsNotNull<SearchFilters>(), It.IsAny<string>())).Returns(Task.FromResult(persons));
            pagingResult = this.alertController.Paging(new AlertPresenter(), "0", string.Empty) as PartialViewResult;
            Assert.AreEqual(pagingResult.ViewName, AlertListPartialView);

            var alertResult = new ListResult<Alert>();
            var alertList = new List<Alert>();
            alertList.Add(new Alert());
            alertList.Add(new Alert());
            alertList.Add(new Alert());
            alertResult.AssignItems(alertList);

            SessionData.Instance.AssignAlertSearchResult(alertResult);
            this.personManager.Setup(mockItem => mockItem.GetPersonsAsync(It.IsNotNull<SearchFilters>(), It.IsAny<string>())).Returns(Task.FromResult(persons));
            pagingResult = this.alertController.Paging(new AlertPresenter(), "0", string.Empty) as PartialViewResult;
            Assert.AreEqual(pagingResult.ViewName, AlertListPartialView);

            this.personManager.Setup(mockItem => mockItem.GetPersonsAsync(It.IsNotNull<SearchFilters>(), It.IsAny<string>())).Returns(Task.FromResult(persons));
            pagingResult = this.alertController.Paging(new AlertPresenter(), "0", AlertTemplateListPartialView) as PartialViewResult;
            Assert.AreEqual(pagingResult.ViewName, AlertTemplateListPartialView);
        }
 public async Task AlertControllerIndexTest()
 {
     try
     {
         SessionData.Instance.User = CommonHelper.SetupUserData();
         var alertPresenter = SetUpAlertPresenter();
         var alertItem = new List<Alert>();
         alertItem.Add(new Alert { AddedDate = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture) });
         var alertItemList = new ListResult<Alert>();
         alertItemList.AssignItems(alertItem);
         this.alertManager.Setup(mockItem => mockItem.AlertTypeAsync(It.IsNotNull<string>(), It.IsNotNull<bool>(), It.IsNotNull<bool>(), It.IsNotNull<bool>(), It.IsNotNull<string>(), It.IsNotNull<bool>(), It.IsNotNull<string>())).Returns(Task.FromResult(alertItemList));
         var result = await this.alertController.Index(alertPresenter) as ViewResult;
         Assert.IsTrue(true);
     }
     finally
     {
         this.Dispose();
     }
 }
        /// <summary>
        /// Maps the gangway history.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <returns>List result of Gangway History</returns>
        internal static async Task<ListResult<GangwayHistory>> MapGangwayHistory(SqlDataReader dataReader)
        {
            var historyList = new ListResult<GangwayHistory>();
            var gangwayHistoryCollection = new Collection<GangwayHistory>();

            if (dataReader != null)
            {
                while (await dataReader.ReadAsync())
                {
                    gangwayHistoryCollection.Add(MapHistory(dataReader));
                }

                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }
            }

            historyList.AssignItems(gangwayHistoryCollection);
            return await Task.FromResult(historyList);
        }
        /// <summary>
        /// Retrieves the person list asynchronous.
        /// </summary>
        /// <param name="personSearchParameter">The person search parameter.</param>
        /// <returns>
        /// Return person list
        /// </returns>
        public async Task<ListResult<Person>> RetrieveListAsync(PersonSearchParameter personSearchParameter)
        {
            bool isAlertCount = false;
            if ((string.IsNullOrEmpty(personSearchParameter.IsAlertCount) && string.IsNullOrEmpty(personSearchParameter.IsMessageCount)) || (!string.IsNullOrEmpty(personSearchParameter.IsAlertCount) && Convert.ToBoolean(personSearchParameter.IsAlertCount, CultureInfo.InvariantCulture)))
            {
                isAlertCount = true;
            }

            var personList = new ListResult<Person>();
            var stateroomId = string.Empty;
            var staterooms = new ListResult<Stateroom>();

            if (!string.IsNullOrWhiteSpace(personSearchParameter.Stateroom) && (string.IsNullOrEmpty(personSearchParameter.PersonTypeId) || !personSearchParameter.PersonTypeId.Equals("3")))
            {
                staterooms = await this.shipRepository.GetStateroomListAsync(this.applicationSettings.ShipId, null, personSearchParameter.Stateroom, null, null);
                stateroomId = PersonMapper.MapStateroomId(personSearchParameter.Stateroom, staterooms).StateroomId;
                if (string.IsNullOrEmpty(stateroomId))
                {
                    return personList;
                }

                if (string.IsNullOrEmpty(personSearchParameter.PersonTypeId) || (!string.IsNullOrEmpty(personSearchParameter.PersonTypeId) && string.Equals(personSearchParameter.PersonTypeId, "2")))
                {
                    var guests = await this.guestRepository.RetrieveGuests(null, stateroomId, personSearchParameter.VoyageId, null, null, personSearchParameter.Citizenship, null, 1, int.MaxValue);
                    PersonMapper.MapPersonsByGuests(guests, staterooms, personList);
                    var alerts = await this.RetrievePersonAlerts(personSearchParameter, personList.Items.RetrieveIds(p => p.PersonId));
                    PersonMapper.MapPersonAlerts(alerts, personList);
                    personList.AssignItems(personList.Items.Where(item => isAlertCount ? item.AlertCount > 0 : item.MessageCount > 0).ToList());
                    personList.TotalResults = personList.Items.Count;
                    personList.GuestTotalResults = personList.TotalResults;
                }
                else if (string.Equals(personSearchParameter.PersonTypeId, "1") || (string.IsNullOrEmpty(personSearchParameter.PersonTypeId) && personList.Items.Count == 0))
                {
                    var crews = await this.crewClientRepository.RetrieveCrewmembersList(null, null, stateroomId, null, null, 1, int.MaxValue, CrewDepths.Crew);
                    PersonMapper.MapPersonsByCrews(crews, staterooms, personList);
                    var alerts = await this.RetrievePersonAlerts(personSearchParameter, personList.Items.RetrieveIds(p => p.PersonId));
                    PersonMapper.MapPersonAlerts(alerts, personList);
                    personList.AssignItems(personList.Items.Where(item => isAlertCount ? item.AlertCount > 0 : item.MessageCount > 0).ToList());
                    personList.TotalResults = personList.Items.Count;
                    personList.CrewTotalResults = personList.TotalResults;
                }

                return personList;
            }

            List<string> guestIds = new List<string>(), crewIds = new List<string>(), visitorIds = new List<string>();
            string personVoyageId = null;
            if (!string.IsNullOrEmpty(personSearchParameter.PersonTypeId) && personSearchParameter.PersonTypeId.Equals("2") && (!personSearchParameter.IsAll.HasValue || !personSearchParameter.IsAll.Value))
            {
                personVoyageId = personSearchParameter.VoyageId;
            }

            if (isAlertCount)
            {
                var personAlerts = await this.alertClientRepository.ListPersonAlertsAsync(personSearchParameter.IsAll.GetValueOrDefault(false) ? null : personSearchParameter.PersonTypeId, null, "1", this.applicationSettings.ShipId, personVoyageId, Parts);
                guestIds = personAlerts.Items.Where(item => item.PersonTypeId == "2").Select(item => item.PersonId).Distinct().ToList();
                crewIds = personAlerts.Items.Where(item => item.PersonTypeId == "1").Select(item => item.PersonId).Distinct().ToList();
                visitorIds = personAlerts.Items.Where(item => item.PersonTypeId == "3").Select(item => item.PersonId).Distinct().ToList();
            }
            else
            {
                var personMessages = await this.alertClientRepository.ListPersonMessagesAsync(personSearchParameter.IsAll.GetValueOrDefault(false) ? null : personSearchParameter.PersonTypeId, null, "1", this.applicationSettings.ShipId, personVoyageId, Parts);
                guestIds = personMessages.Items.Where(item => item.PersonTypeId == "2").Select(item => item.PersonId).Distinct().ToList();
                crewIds = personMessages.Items.Where(item => item.PersonTypeId == "1").Select(item => item.PersonId).Distinct().ToList();
                visitorIds = personMessages.Items.Where(item => item.PersonTypeId == "3").Select(item => item.PersonId).Distinct().ToList();
            }

            if (string.IsNullOrEmpty(personSearchParameter.PersonTypeId) || string.Equals(personSearchParameter.PersonTypeId, "2"))
            {
                personList = await this.RetrieveGuestsList(personSearchParameter, isAlertCount, guestIds);
                if (personSearchParameter.IsAll.HasValue && personSearchParameter.IsAll.Value)
                {
                    var crewResults = await this.RetrieveCrewLists(personSearchParameter, isAlertCount, crewIds);
                    personList.CrewTotalResults = crewResults.Items.Count;
                    if (string.IsNullOrEmpty(personSearchParameter.PersonTypeId) && personList.Items.Count == 0)
                    {
                        personList = crewResults;
                    }

                    var visitorResults = await this.RetrieveVisitorLists(personSearchParameter, visitorIds, isAlertCount);
                    personList.VisitorTotalResults = visitorResults.Items.Count;
                    if (string.IsNullOrEmpty(personSearchParameter.PersonTypeId) && personList.Items.Count == 0)
                    {
                        personList = visitorResults;
                    }
                }
            }
            else if (string.Equals(personSearchParameter.PersonTypeId, "1"))
            {
                personList = await this.RetrieveCrewLists(personSearchParameter, isAlertCount, crewIds);
                if (personSearchParameter.IsAll.HasValue && personSearchParameter.IsAll.Value)
                {
                    personList.GuestTotalResults = (await this.RetrieveGuestsList(personSearchParameter, isAlertCount, guestIds)).Items.Count;
                    personList.VisitorTotalResults = (await this.RetrieveVisitorLists(personSearchParameter, visitorIds, isAlertCount)).Items.Count;
                }
            }
            else if (string.Equals(personSearchParameter.PersonTypeId, "3"))
            {
                personList = await this.RetrieveVisitorLists(personSearchParameter, visitorIds, isAlertCount);
                if (personSearchParameter.IsAll.HasValue && personSearchParameter.IsAll.Value)
                {
                    personList.GuestTotalResults = (await this.RetrieveGuestsList(personSearchParameter, isAlertCount, guestIds)).Items.Count;
                    personList.CrewTotalResults = (await this.RetrieveCrewLists(personSearchParameter, isAlertCount, crewIds)).Items.Count;
                }
            }

            return personList;
        }
        /// <summary>
        /// Maps the crew member stateroom.
        /// </summary>
        /// <param name="shipId">The ship identifier.</param>
        /// <param name="crewmembers">The crew member s.</param>
        /// <param name="personstatus">The person status.</param>
        /// <returns>
        /// Return Nothing
        /// </returns>
        private async Task<ListResult<Crewmember>> MapCrewmemberStateroom(string shipId, ListResult<DataAccess.Entities.Crewmember> crewmembers, ListResult<PersonStatus> personstatus)
        {
            var staterooms = await DIContainer.Instance.Resolve<ShipClientRepository>().RetrieveStateroomListAsync(shipId);
            var shipTime = await this.shipTimeRepository.GetAsync(shipId);
            DateTime? shipDateTime = null;
            if (shipTime != null)
            {
                var utcOffSet = new TimeSpan(Convert.ToInt32(shipTime.UtcOffset, CultureInfo.CurrentCulture));
                shipDateTime = DateTime.UtcNow.Add(utcOffSet);
            }

            var list = new ListResult<Crewmember> { TotalResults = crewmembers.TotalResults };
            var safetyRoleIds = string.Empty;
            crewmembers.Items.ForEach(a => safetyRoleIds += CommaSeparator + a.SafetyDuties.RetrieveIds(b => b.SafetyRoleId));
            var safetyRoleList = await DIContainer.Instance.Resolve<ShipClientRepository>().RetrieveSafetyRoleListAsync(safetyRoleIds, shipId);
            var crewList = CrewmemberMapper.MapListAsync(crewmembers, staterooms.Items, shipDateTime, safetyRoleList.Items);
            var crewCollection = await MapCrewmemberPersonStatus(crewList, personstatus);
            if (crewCollection != null && crewCollection.Count > 0)
            {
                list.AssignItems(crewCollection);
            }

            return list;
        }
        /// <summary>
        /// Retrieves the visitor lists.
        /// </summary>
        /// <param name="personSearchParameter">The person search parameter.</param>
        /// <param name="visitorIds">The visitor ids.</param>
        /// <param name="isAlertCount">if set to <c>true</c> [is alert count].</param>
        /// <returns>The visitors list.</returns>
        private async Task<ListResult<Person>> RetrieveVisitorLists(PersonSearchParameter personSearchParameter, List<string> visitorIds, bool isAlertCount)
        {
            ListResult<Person> personList = new ListResult<Person>();
            if (visitorIds.Count == 0 || !string.IsNullOrWhiteSpace(personSearchParameter.Stateroom) || !string.IsNullOrWhiteSpace(personSearchParameter.ReservationNo))
            {
                return personList;
            }

            var visitor = await this.visitorClientRepository.RetrieveVisitors(visitorIds.RetrieveIds(id => id), personSearchParameter.LastNameContains, personSearchParameter.Citizenship, personSearchParameter.Birthdate, personSearchParameter.PassportNo, null, null, null, null, null, 1, int.MaxValue, VisitorDepths.Visitor, null);
            PersonMapper.MapPersonsByVisitors(visitor, personList);
            var alerts = await this.RetrievePersonAlerts(personSearchParameter, personList.Items.RetrieveIds(p => p.PersonId));
            PersonMapper.MapPersonAlerts(alerts, personList);
            personList.AssignItems(personList.Items.Where(item => isAlertCount ? item.AlertCount > 0 : item.MessageCount > 0).ToList());
            personList.TotalResults = personList.Items.Count;
            personList.VisitorTotalResults = personList.Items.Count;
            return personList;
        }
        /// <summary>
        /// Retrieves the visitor asynchronous.
        /// </summary>
        /// <param name="searchParameters">The search parameters.</param>
        /// <param name="personTypeList">The person type list.</param>
        /// <returns>
        /// Return Nothing
        /// </returns>
        private async Task<ListResult<Visitor>> RetrieveVisitorsAsync(PersonSearchParameter searchParameters, ListResult<PersonTypeEntity> personTypeList)
        {
            var visitorList = new ListResult<Visitor>();
            var visitors = await this.personRepository.RetrieveVisitor(searchParameters);
            var personTypeId = personTypeList.Items.FirstOrDefault(a => a.Name.Equals(PersonTypes.Visitor.ToString(), StringComparison.OrdinalIgnoreCase));

            if (visitors != null && visitors.Items.Count > 0)
            {
                var personstatus = personTypeId != null ? await this.RetrievePersonStatus(visitors.Items.RetrieveIds(a => a.VisitorId), PersonStatusConstant, personTypeId.PersonTypeId, searchParameters, 1, 0) : null;
                //// For Retrieve Visitor Department on the basis of visitor ids.
                var deparmentIds = visitors.Items.Count > 0 ? visitors.Items.RetrieveIds(a => a.PersonalDetail.DepartmentId) : null;
                var departments = deparmentIds != null ? this.personRepository.RetrieveDepartmentListAsync(deparmentIds) : null;
                ////var visitPurposeIds = visitors.Items.Count > 0 ? visitors.Items.RetrieveIds(a => a.VisitPurpose) : null;
                var visitPurposeList = this.personRepository.RetrieveVisitPurposeListAsync();
                var visitTypeList = this.personRepository.RetrieveVisitorTypeListAsync();
                await Task.WhenAll(visitPurposeList, visitTypeList, departments);
                if (visitors.Items.Count > 0)
                {
                    var mappedVisitoList = MapVisitorDetail(visitors.Items, personstatus, departments.Result != null ? departments.Result.Items : null, visitPurposeList.Result != null ? visitPurposeList.Result.Items : null, visitTypeList.Result != null ? visitTypeList.Result.Items : null);
                    if (mappedVisitoList != null)
                    {
                        visitorList.TotalResults = visitors.TotalResults;
                        visitorList.AssignItems(mappedVisitoList);
                    }
                }
            }

            return visitorList;
        }
        /// <summary>
        /// Retrieves the guests list.
        /// </summary>
        /// <param name="personSearchParameter">The person search parameter.</param>
        /// <param name="isAlertCount">if set to <c>true</c> [is alert count].</param>
        /// <param name="guestIds">The guest ids.</param>
        /// <returns>The guest list.</returns>
        private async Task<ListResult<Person>> RetrieveGuestsList(PersonSearchParameter personSearchParameter, bool isAlertCount, List<string> guestIds)
        {
            ListResult<Person> personList = new ListResult<Person>();
            if (guestIds.Count == 0 || !string.IsNullOrWhiteSpace(personSearchParameter.Birthdate))
            {
                return personList;
            }

            ListResult<Stateroom> staterooms = new ListResult<Stateroom>();
            var guests = await this.guestRepository.RetrieveGuests(personSearchParameter.LastNameContains, null, personSearchParameter.VoyageId, personSearchParameter.ReservationNo, personSearchParameter.PassportNo, personSearchParameter.Citizenship, guestIds.RetrieveIds(id => id), 1, int.MaxValue);
            if (string.IsNullOrWhiteSpace(personSearchParameter.Stateroom))
            {
                var guestStateroomIds = guests.Items.RetrieveIds(a => a.ReservationDetail.StateroomId);
                if (!string.IsNullOrWhiteSpace(guestStateroomIds))
                {
                    staterooms = await this.RetrieveStaterooms(guestStateroomIds.TrimEnd(','), null);
                }
            }

            PersonMapper.MapPersonsByGuests(guests, staterooms, personList);
            var alerts = await this.RetrievePersonAlerts(personSearchParameter, personList.Items.RetrieveIds(p => p.PersonId));
            PersonMapper.MapPersonAlerts(alerts, personList);
            personList.AssignItems(personList.Items.Where(item => isAlertCount ? item.AlertCount > 0 : item.MessageCount > 0).ToList());
            personList.TotalResults = personList.Items.Count;
            personList.GuestTotalResults = personList.Items.Count;
            return personList;
        }
        /// <summary>
        /// Retrieves the crew members.
        /// </summary>
        /// <param name="searchParameter">The search parameter.</param>
        /// <param name="personTypeList">The person type list.</param>
        /// <param name="staterooms">The staterooms.</param>
        /// <returns>
        /// Return instance of Person entity.
        /// </returns>
        private async Task<ListResult<Crewmember>> RetrieveCrewMembers(PersonSearchParameter searchParameter, ListResult<PersonTypeEntity> personTypeList, ListResult<DataAccess.Entities.Stateroom> staterooms)
        {
            var crewMemberList = new ListResult<Crewmember>();
            if (!string.IsNullOrEmpty(searchParameter.NameContains) || !string.IsNullOrEmpty(searchParameter.LastNameContains) || !string.IsNullOrEmpty(searchParameter.CrewmemberIds) || !string.IsNullOrEmpty(searchParameter.DocumentNo)
                   || !string.IsNullOrEmpty(searchParameter.StateroomIds) || !string.IsNullOrEmpty(searchParameter.EmployeeNumber) || !string.IsNullOrEmpty(searchParameter.AccessCardNumber))
            {
                var crewmembers = await this.personRepository.RetrieveCrew(searchParameter);
                var crewPersonType = personTypeList.Items.FirstOrDefault(a => a.Name.Equals(PersonTypes.Crew.ToString(), StringComparison.OrdinalIgnoreCase));
                if (crewPersonType != null && crewmembers.Items.Count > 0)
                {
                    var personstatus = await this.RetrievePersonStatus(crewmembers.Items.RetrieveIds(a => a.CrewmemberId), OnboardConstant, crewPersonType.PersonTypeId, searchParameter, null, null);
                    var collection = CrewmemberMapper.MapListAsync(crewmembers, staterooms.Items, null, null);

                    //// Retrieve Safety duties for the crew on the basis of Safety Role Id.

                    crewMemberList.TotalResults = crewmembers.TotalResults;
                    crewMemberList.AssignItems(await MapCrewmemberPersonStatus(collection, personstatus));
                }
            }

            return crewMemberList;
        }
        /// <summary>
        /// Setups the manager.
        /// </summary>
        private void SetTravelData()
        {
            var reservation = new DataAccess.Entities.Reservation();
            var reservationGuest = new DataAccess.Entities.ReservationGuest { BeaconId = "43", GuestId = "600001" };

            var guest = new Guest
            {
                CruiseDetail = new GuestCruiseDetail
                {
                    ////IsVip = false,
                    IsPrimary = false,
                    Stateroom = "xyz",
                    StateroomCategoryTypeId = "A",
                    ReservationStatusId = "1001",
                    ReservationNumber = "111",
                    ReservationId = "3",
                    LoyaltyLevelTypeId = "8",
                    BeaconId = "212",
                    HasRecovery = true,
                    CanDebarkAlone = false
                },
                PersonalDetail = new PersonalDetail { FirstName = "Robert", Gender = Gender.Male, },
                GuestId = "600001",
                SecurityPhotoAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23"
            };

            var portDebarkAuthorization = new PortDebarkAuthorization();

            var alert = new Collection<Alert> { new Alert { AlertId = "12", AlertType = "2", Message = new Message { Description = "Test", ImageAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23", Subject = "Test" } } };

            var debarkAuthorizedPersonCollection = new DebarkAuthorizedPersonCollection { new DebarkAuthorizedPerson { PersonId = "22", PersonTypeId = "323" } };

            portDebarkAuthorization.AssignDebarkAuthorizedPersons(debarkAuthorizedPersonCollection);

            var portDebarkAuthorizations = new PortDebarkAuthorizationCollection { new PortDebarkAuthorization { CanDebarkAlone = true } };

            guest.AssignAlerts(alert);
            guest.AssignPortAuthorizations(portDebarkAuthorizations);

            this.guests.Add(guest);
            var guestList = new ListResult<Guest>();
            guestList.AssignItems(this.guests);

            reservation.TravelPartyReservationIds.Add("600001");
            reservation.TravelPartyReservationIds.Add("xyz");
            reservation.ReservationGuests.Add(reservationGuest);

            this.reservationList.Items.Add(reservation);

            this.guestRepository.Setup(data => data.GetTravelWithPartyAsync(It.IsAny<GuestSearchParameters>())).Returns(Task.FromResult(this.reservationList));
            this.personRepository.Setup(data => data.RetrieveGuest(It.IsAny<PersonSearchParameter>())).Returns(Task.FromResult(guestList));
        }
        /// <summary>
        /// Retrieves the guests.
        /// </summary>
        /// <param name="searchParameters">The search parameters.</param>
        /// <param name="staterooms">The staterooms.</param>
        /// <param name="isReservationInfo">if set to <c>true</c> [is reservation information].</param>
        /// <returns>
        /// Task Instance
        /// </returns>
        private async Task<ListResult<Guest>> RetrieveGuests(PersonSearchParameter searchParameters, ListResult<DataAccess.Entities.Stateroom> staterooms, bool isReservationInfo)
        {
            var guestList = new ListResult<Guest>();
            var personSearchParameter = searchParameters;
            var guests = await this.personRepository.RetrieveGuest(searchParameters);

            if (guests != null && guests.Items.Count > 0)
            {
                guestList.TotalResults = guests.TotalResults;
                var personTypeList = await this.referenceDataRepository.RetrievePersonTypeListAsync();
                var guestPersonType = personTypeList.Items.FirstOrDefault(a => a.Name.Equals(PersonTypes.Guest.ToString(), StringComparison.OrdinalIgnoreCase));
                var personStatus = guestPersonType != null ? await this.RetrievePersonStatus(guests.Items.RetrieveIds(a => a.GuestId), PersonStatusConstant, guestPersonType.PersonTypeId, searchParameters, 1, 0) : null;
                personSearchParameter.GuestIds = guests.Items.RetrieveIds(a => a.GuestId);
                var guestReservationDetails = isReservationInfo ? await this.guestCruiseDetailManager.RetrieveReservation(personSearchParameter) : new Dictionary<string, DataAccess.Entities.GuestReservationDetail>();
                guestList.AssignItems(await this.guestCruiseDetailManager.MapGuestDetails(guests.Items, personStatus, searchParameters.ShipId, guestPersonType != null ? guestPersonType.PersonTypeId : string.Empty, guestReservationDetails, staterooms));
            }

            return guestList;
        }
        /// <summary>
        /// Creates the alert.
        /// </summary>
        /// <param name="alertId">The alert identifier.</param>
        /// <param name="isTemplate">The is template.</param>
        /// <param name="type">The type.</param>
        /// <returns>
        /// The create alert
        /// </returns>
        public async Task<ActionResult> CreateAlert(string alertId, string isTemplate, string type)
        {
            var alertPresenter = new AlertPresenter();
            alertPresenter.IsTemplate = string.IsNullOrEmpty(isTemplate) ? SessionData.Instance.AlertData != null && SessionData.Instance.AlertData.IsTemplate : Convert.ToBoolean(isTemplate, CultureInfo.InvariantCulture);
            BaseController.GetAboutUsInformation(alertPresenter);
            var saveUtcNow = BaseController.GenerateLocalDateTime(DateTime.UtcNow);

            SessionData.Instance.IsMessageMode = FalseConstantValue;
            if (!string.IsNullOrEmpty(alertId))
            {
                var alertDetailResult = await this.alertManager.GetAlertDetailsById(alertId, type);

                alertPresenter.SelectedCrewDepartment = Convert.ToString(alertDetailResult.CrewDepartmentId, CultureInfo.InvariantCulture);
                alertPresenter.SelectedAlertTypes = Convert.ToString(alertDetailResult.TypeId, CultureInfo.InvariantCulture);
                alertPresenter.UserName = alertDetailResult.UserName;
                alertPresenter.StartDate = alertDetailResult.StartDate.ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture);
                alertPresenter.ExpiryDate = !alertPresenter.IsTemplate ? alertDetailResult.ExpiryDate.Value.ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture) : string.Empty;
                ViewBag.startDate = alertPresenter.IsTemplate ? saveUtcNow.ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture) : alertDetailResult.StartDate.ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture);
                ViewBag.expireDate = alertPresenter.IsTemplate ? saveUtcNow.AddHours(1).ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture) : alertDetailResult.ExpiryDate.Value.ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture);
                alertPresenter.PersonCount = alertDetailResult.PersonCount;
                alertPresenter.IsOverrideAllowed = alertDetailResult.IsOverride;
                alertPresenter.IsSoundEnable = alertDetailResult.IsSoundEnable;
                SessionData.Instance.ActiveAlertId = alertId;
                SessionData.Instance.TypeId = type;

                SessionData.Instance.AssignAlertData(alertDetailResult);

                if (alertDetailResult.Persons.Count > 0 && string.IsNullOrEmpty(isTemplate))
                {
                    var personList = new ListResult<Person>();
                    personList.AssignItems(alertDetailResult.Persons);

                    alertPresenter.AssignPersonSearchResult(personList);

                    foreach (var person in alertDetailResult.Persons)
                    {
                        SessionData.Instance.SelectedPersonIds.Add(person.PersonId);
                    }

                    SessionData.Instance.AssignFilterPersonResult(alertDetailResult.Persons);
                }
            }

            if (SessionData.Instance.GlobalAlertPersonList != null && SessionData.Instance.GlobalAlertPersonList.Count > 0)
            {
                foreach (var person in SessionData.Instance.GlobalAlertPersonList)
                {
                    if (!SessionData.Instance.FilterPersonList.Any(p => p.PersonId == person.PersonId))
                    {
                        SessionData.Instance.AssignGlobalPersonResult(person);
                    }
                }

                SetPassengerData(alertPresenter);
            }

            if (SessionData.Instance.SelectedPersonIds != null && SessionData.Instance.SelectedPersonIds.Count > 0 && string.IsNullOrEmpty(isTemplate))
            {
                SetPassengerData(alertPresenter);
            }

            if (SessionData.Instance.AlertData != null)
            {
                alertPresenter.SelectedCrewDepartment = Convert.ToString(SessionData.Instance.AlertData.CrewDepartmentId, CultureInfo.InvariantCulture);
                alertPresenter.AlertType = SessionData.Instance.AlertData.AlertType;
                alertPresenter.Description = SessionData.Instance.AlertData.Description;
                alertPresenter.StartDate = SessionData.Instance.AlertData.StartDate.ToString(CultureInfo.InvariantCulture);
                alertPresenter.ExpiryDate = !alertPresenter.IsTemplate ? SessionData.Instance.AlertData.ExpiryDate.Value.ToString(CultureInfo.InvariantCulture) : string.Empty;
                alertPresenter.IsOverrideAllowed = SessionData.Instance.AlertData.IsOverride;
                alertPresenter.IsSoundEnable = SessionData.Instance.AlertData.IsSoundEnable;
                alertPresenter.SelectedAlertTypes = Convert.ToString(SessionData.Instance.AlertData.TypeId, CultureInfo.InvariantCulture);
                ViewBag.startDate = alertPresenter.StartDate;
                ViewBag.expireDate = alertPresenter.ExpiryDate;
            }
            else if (string.IsNullOrEmpty(alertId))
            {
                ViewBag.startDate = saveUtcNow.ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture);
                ViewBag.expireDate = saveUtcNow.AddHours(1).ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture);
                alertPresenter.StartDate = saveUtcNow.ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture);
                alertPresenter.ExpiryDate = saveUtcNow.AddHours(1).ToString(this.ApplicationSettings.DateFormat, CultureInfo.InvariantCulture);
                alertPresenter.IsOverrideAllowed = true;
                alertPresenter.IsSoundEnable = true;
            }

            return this.View(CreateView, alertPresenter);
        }
 public async Task ValidateGuestTest()
 {
     try
     {
         UserAccount userAccount = SetupUserAccountData();
         User user = SetUpUserPersonalDetails();
         this.authenticationManager.Setup(mockItem => mockItem.RetrieveAuthenticateUserPersonalDetails(It.IsNotNull<UserAccount>())).Returns(Task.FromResult(user));
         this.authenticationManager.Setup(mockItem => mockItem.AuthenticateUserAsync(It.IsNotNull<UserAccount>())).Returns(Task.FromResult(userAccount));
         var objLoginPresenter = new LoginPresenter();
         objLoginPresenter.UserName = "******";
         objLoginPresenter.Password = "******";
         this.authorizationManager.Setup(mock => mock.RetrieveUserAuthorizationFeaturesAsync(It.IsNotNull<string>(), It.IsNotNull<string>())).Returns(Task.FromResult(new ListResult<ApplicationRoles>()));
         var validateGuestResult = await this.loginController.ValidateGuest(objLoginPresenter) as JsonResult;
         Assert.IsTrue(!(bool)validateGuestResult.Data);
         var applicationRoles = new ListResult<ApplicationRoles>();
         applicationRoles.AssignItems(new Collection<ApplicationRoles> { new ApplicationRoles { ApplicationId = "1", ApplicationRoleId = "2", Description = "Test", Name = "Test" } });
         this.authorizationManager.Setup(mock => mock.RetrieveUserAuthorizationFeaturesAsync(It.IsNotNull<string>(), It.IsNotNull<string>())).Returns(Task.FromResult(applicationRoles));
         validateGuestResult = await this.loginController.ValidateGuest(objLoginPresenter) as JsonResult;
         Assert.IsTrue((bool)validateGuestResult.Data);
     }
     finally
     {
         this.Dispose();
     }
 }
        /// <summary>
        /// Paging the specified alert presenter.
        /// </summary>
        /// <param name="alertPresenter">The alert presenter.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="partialView">The partial view.</param>
        /// <returns>The Action Result for Next Page.</returns>
        public ActionResult Paging(AlertPresenter alertPresenter, string pageNumber, string partialView)
        {
            if (alertPresenter != null && !string.IsNullOrEmpty(pageNumber) && !pageNumber.Equals(UndefinedConstant))
            {
                if (!string.IsNullOrEmpty(partialView) && string.Equals(partialView, AlertPassengerListPartialView, StringComparison.OrdinalIgnoreCase))
                {
                    var filterPersons = SessionData.Instance.FilterPersonList.ToList();
                    var pagingResult = GetPagedResult(pageNumber, filterPersons);
                    if (pagingResult != null && pagingResult.Count > 0)
                    {
                        var pagingListResult = new ListResult<Person>();
                        pagingListResult.AssignItems(pagingResult);
                        alertPresenter.AssignPersonSearchResult(pagingListResult);
                        return this.PartialView(AlertPassengerListPartialView, alertPresenter);
                    }
                }
                else
                {
                    string partialViewScreen = AlertListPartialView;
                    if (!string.IsNullOrEmpty(partialView) && string.Equals(partialView, AlertTemplateListPartialView, StringComparison.OrdinalIgnoreCase))
                    {
                        partialViewScreen = partialView;
                    }

                    var alerts = SessionData.Instance.AlertItems.Items.OrderByDescending(item => item.AddedDate).ToList();
                    var pagingResult = GetPagedResult(pageNumber, alerts);
                    if (pagingResult != null && pagingResult.Count > 0)
                    {
                        alertPresenter.AssignAlertSearchResult(pagingResult);
                        return this.PartialView(partialViewScreen, alertPresenter);
                    }
                }
            }

            return this.PartialView(AlertListPartialView, alertPresenter);
        }
        /// <summary>
        /// Messages the type.
        /// </summary>
        /// <param name="alertTypeId">The alert type identifier.</param>
        /// <param name="isExpiredAlert">The is expired alert.</param>
        /// <param name="todaysAlert">The todays alert.</param>
        /// <param name="isCreatedMessage">The is created message.</param>
        /// <returns>
        /// The View for Action Result
        /// </returns>
        public async Task<ActionResult> MessageType(string alertTypeId, string isExpiredAlert, string todaysAlert, string isCreatedMessage)
        {
            var messagePresenter = new MessagePresenter();
            var shipTime = BaseController.GenerateLocalDateTime(DateTime.UtcNow).ToString(this.ApplicationSettings.ShipDateTimeFormat, CultureInfo.InvariantCulture);
            var addedDateParameter = string.Empty;
            var messageList = new ListResult<Alert>();

            if (isCreatedMessage.Equals(TrueConstant, StringComparison.InvariantCultureIgnoreCase))
            {
                addedDateParameter = shipTime;
            }

            var alertDetails = await this.alertManager.AlertTypeAsync(alertTypeId, Convert.ToBoolean(isExpiredAlert, CultureInfo.InvariantCulture), Convert.ToBoolean(todaysAlert, CultureInfo.InvariantCulture), true, shipTime, false, addedDateParameter);
            ModelState.Clear();

            foreach (var alert in alertDetails.Items)
            {
                var addedDate = Convert.ToDateTime(alert.AddedDate, CultureInfo.InvariantCulture);
                alert.AddedDate = Convert.ToString(BaseController.GenerateLocalDateTime(addedDate), CultureInfo.InvariantCulture);

                if (alert.Persons.Count > 0)
                {
                    messageList.Items.Add(alert);
                }
            }

            if (Convert.ToBoolean(isExpiredAlert))
            {
                var filterPersonCountResult = alertDetails.Items.Where(alerts => alerts.PersonCount > 0).ToList();
                var filteredPersonCountAlerts = new ListResult<Alert>();
                filteredPersonCountAlerts.AssignItems(filterPersonCountResult);
                SessionData.Instance.AssignAlertSearchResult(filteredPersonCountAlerts);
            }
            else
            {
                SessionData.Instance.AssignAlertSearchResult(messageList);
            }

            var maxPaging = DefaultPageSize > SessionData.Instance.AlertItems.Items.OrderByDescending(item => item.AddedDate).Count() ? SessionData.Instance.AlertItems.Items.Count() : DefaultPageSize;
            var pagingResult = SessionData.Instance.AlertItems.Items.OrderByDescending(item => item.AddedDate).Skip(0).Take(maxPaging - 0).ToList();
            messagePresenter.AssignAlertSearchResult(pagingResult);

            return this.PartialView(MessageListPartialView, messagePresenter);
        }
        /// <summary>
        /// Maps the message data from service.
        /// </summary>
        /// <param name="messageData">The message data.</param>
        /// <returns>Alert type list</returns>
        private static ListResult<Entities.AlertType> MapMessageDataListFromService(ListResult<Message> messageData)
        {
            var result = new ListResult<Entities.AlertType>();
            var messages = new AlertTypeCollection();

            foreach (var message in messageData.Items)
            {
                var messagesData = new Entities.AlertType();

                messagesData.AddedBy = message.AddedBy;
                messagesData.AddedDate = message.AddedDate.GetValueOrDefault();
                messagesData.Description = message.Description;
                messagesData.DueDate = message.DueDate;
                messagesData.ExpiryDate = message.ExpiryDate;
                messagesData.ModifiedBy = message.LastModifiedBy;
                messagesData.AlertTypeId = message.MessageId;
                messagesData.MessageFrom = message.MessageFrom;
                messagesData.IsMessage = true;
                messagesData.IsTemplate = false;
                messagesData.IsSoundEnable = message.IsSoundEnable;

                foreach (var personMessages in message.PersonMessages)
                {
                    var personMessage = new Entities.Alert();

                    personMessage.PersonId = personMessages.PersonId;
                    personMessage.PersonTypeId = personMessages.PersonTypeId;
                    personMessage.ShipId = personMessages.ShipId;
                    personMessage.VoyageId = personMessages.VoyageId;
                    personMessage.StatusId = personMessages.StatusId;
                    personMessage.AlertTypeId = personMessages.MessageId;
                    personMessage.PersonAlertId = personMessages.PersonMessageId;

                    messagesData.Alerts.Add(personMessage);
                }

                messages.Add(messagesData);
            }

            result.AssignItems(messages);

            return result;
        }
        private void SetupData()
        {
            var guest = new GangwayService.Entity.Guest
            {
                CruiseDetail = new GuestCruiseDetail
                {
                    ////IsVip = false,
                    IsPrimary = false,
                    Stateroom = "1",
                    StateroomCategoryTypeId = "A",
                    ReservationStatusId = "1001",
                    ReservationNumber = "111",
                    ReservationId = "3",
                    LoyaltyLevelTypeId = "8",
                    BeaconId = "212",
                    HasRecovery = true,
                    CanDebarkAlone = false,
                    StateroomOccupancy = "5"
                },
                PersonalDetail = new PersonalDetail
                {
                    FirstName = "Robert",
                    Gender = Gender.Male,
                    Birthdate = DateTime.Now,
                    Suffix = "MR.",
                    AnniversaryDate = DateTime.Now,
                    BirthCountryId = "2",
                    CitizenshipCountryId = "232",
                    LastName = "Singh",
                    MaritalStatus = "Single"
                },
                GuestId = "600001",
                LastDateTime = DateTime.Now.AddMinutes(5),
                LastEvent = "True",
                SecurityPhotoAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23"
            };

            var guest1 = new GangwayService.Entity.Guest
            {
                CruiseDetail = new GuestCruiseDetail
                {
                    ////IsVip = false,
                    IsPrimary = false,
                    Stateroom = "121",
                    StateroomCategoryTypeId = "A",
                    ReservationStatusId = "1001",
                    ReservationNumber = "111",
                    ReservationId = "3",
                    LoyaltyLevelTypeId = "8",
                    BeaconId = "212",
                    HasRecovery = true,
                    CanDebarkAlone = false,
                    StateroomOccupancy = "5"
                },
                PersonalDetail = new PersonalDetail
                {
                    FirstName = "Robert",
                    Gender = Gender.Male,
                    Birthdate = DateTime.Now,
                    Suffix = "MR.",
                    AnniversaryDate = DateTime.Now,
                    BirthCountryId = "2",
                    CitizenshipCountryId = "232",
                    LastName = "Singh",
                    MaritalStatus = "Single"
                },
                GuestId = "600001",
                LastDateTime = DateTime.Now.AddMinutes(5),
                LastEvent = "True",
                SecurityPhotoAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23"
            };

            var guest2 = new GangwayService.Entity.Guest
            {
                CruiseDetail = new GuestCruiseDetail
                {
                    ////IsVip = false,
                    IsPrimary = false,
                    Stateroom = "2",
                    StateroomCategoryTypeId = "A",
                    ReservationStatusId = "1001",
                    ReservationNumber = "111",
                    ReservationId = "3",
                    LoyaltyLevelTypeId = "8",
                    BeaconId = "212",
                    HasRecovery = true,
                    CanDebarkAlone = false,
                    StateroomOccupancy = "5"
                },
                PersonalDetail = new PersonalDetail
                {
                    FirstName = "Robert",
                    Gender = Gender.Male,
                    Birthdate = DateTime.Now,
                    Suffix = "MR.",
                    AnniversaryDate = DateTime.Now,
                    BirthCountryId = "2",
                    CitizenshipCountryId = "232",
                    LastName = "Singh",
                    MaritalStatus = "Single"
                },
                GuestId = "600001",
                LastDateTime = DateTime.Now.AddMinutes(5),
                LastEvent = "True",
                SecurityPhotoAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23"
            };

            var guest3 = new GangwayService.Entity.Guest
            {
                PersonalDetail = new PersonalDetail
                {
                    FirstName = "Robert",
                    Gender = Gender.Male,
                    Birthdate = DateTime.Now,
                    Suffix = "MR.",
                    AnniversaryDate = DateTime.Now,
                    BirthCountryId = "2",
                    CitizenshipCountryId = "232",
                    LastName = "Singh",
                    MaritalStatus = "Single"
                },
                GuestId = "600001",
                LastDateTime = DateTime.Now.AddMinutes(5),
                LastEvent = "True",
                SecurityPhotoAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23"
            };

            var crew = new DataAccess.Entities.Crewmember
            {
                CrewmemberId = "212",
                CrewmemberTypeId = "21",
                EmployeeNo = "22",
                StateroomId = "1",
                PersonalDetail = new PersonalDetail
                {
                    FirstName = "Robert"
                },
                SecurityPhotoAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23",
                EmbarkDetail = new EmbarkDetail { AshoreDate = DateTime.Now, OnboardDate = DateTime.Now }
            };

            var safetyDuty = new SafetyDuty
            {
                CrewmemberId = "212",
                SafetyRoleId = "1",
                EndDate = DateTime.Now,
                StartDate = DateTime.Now
            };

            var accessCard = new AccessCard { AccessCardId = "1", AddedDate = DateTime.Now, AccessCardNumber = "1234", ExpiryDate = DateTime.Now.AddDays(1) };
            crew.CrewmemberAccessCards.Add(accessCard);

            var identification = new Identification { DocumentTypeId = "1", Number = "12345" };
            crew.Identifications.Add(identification);

            var crewMemberRole = new CrewmemberRole { RoleId = "1" };
            crew.CrewmemberRoles.Add(crewMemberRole);

            crew.SafetyDuties.Add(safetyDuty);
            var visitor = new GangwayService.Entity.Visitor
            {
                HasAlert = true,
                PersonalDetail = new PersonalDetail
                {
                    DepartmentId = "1",
                    DepartmentName = "TesT",
                    FirstName = "Robert",
                    Gender = Gender.Male,
                    DepartmentPOC = "Test"
                },
                SecurityPhotoAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23",
                VisitorId = "22",
                VisitorTypeId = "21",
                VisitorInfo = new AdditionalInfo
                {
                    CompanyName = "234dfgfd",
                    ContactNumber = "23452456",
                    VisitPurpose = "retsrt"
                }
            };

            var portDebarkAuthorization = new PortDebarkAuthorization();

            var alert = new Collection<GangwayService.Entity.Alert> { new GangwayService.Entity.Alert { AlertId = "12", AlertType = "2", Message = new Message { Description = "Test", ImageAddress = "http://172.26.248.122/ImagingMediaService/MediaItems/23", Subject = "Test" } } };
            var message = new Collection<GangwayService.Entity.PersonMessage> { new GangwayService.Entity.PersonMessage { AddedBy = Environment.MachineName } };

            var debarkAuthorizedPersonCollection = new DebarkAuthorizedPersonCollection { new DebarkAuthorizedPerson { PersonId = "22", PersonTypeId = "2" }, new DebarkAuthorizedPerson { PersonId = "600001", PersonTypeId = "2" } };

            portDebarkAuthorization.AssignDebarkAuthorizedPersons(debarkAuthorizedPersonCollection);

            var portDebarkAuthorizations = new PortDebarkAuthorizationCollection { new PortDebarkAuthorization { CanDebarkAlone = true } };

            guest.AssignAlerts(alert);
            guest.AssignMessages(message);
            visitor.AssignAlerts(alert);

            guest.AssignPortAuthorizations(portDebarkAuthorizations);

            this.guests.Add(guest);
            this.guests.Add(guest1);
            this.guests.Add(guest2);
            this.guests.Add(guest3);
            this.crewmembers.Add(crew);
            this.visitors.Add(visitor);

            var guestList = new ListResult<GangwayService.Entity.Guest>();
            guestList.AssignItems(this.guests);
            guestList.TotalResults = this.guests.Count;

            var crewList = new ListResult<DataAccess.Entities.Crewmember>();
            crewList.AssignItems(this.crewmembers);
            crewList.TotalResults = this.crewmembers.Count;

            var visitorList = new ListResult<GangwayService.Entity.Visitor>();
            visitorList.AssignItems(this.visitors);
            visitorList.TotalResults = this.visitors.Count;

            this.personRepository.Setup(data => data.RetrieveGuest(It.IsAny<PersonSearchParameter>())).Returns(Task.FromResult(guestList));
            this.personRepository.Setup(data => data.RetrieveCrew(It.IsAny<PersonSearchParameter>())).Returns(Task.FromResult(crewList));
            this.personRepository.Setup(data => data.RetrieveVisitor(It.IsAny<PersonSearchParameter>())).Returns(Task.FromResult(visitorList));
        }
        /// <summary>
        /// Maps the alert template data from service.
        /// </summary>
        /// <param name="alertTemplateResults">The alert template results.</param>
        /// <returns>
        /// alert template data
        /// </returns>
        private static ListResult<Entities.AlertType> MapAlertTemplateDataListFromService(ListResult<AlertTemplate> alertTemplateResults)
        {
            var result = new ListResult<Entities.AlertType>();
            var alertTemplate = new AlertTypeCollection();

            foreach (var alert in alertTemplateResults.Items)
            {
                var alertTemplateData = new Entities.AlertType();
                alertTemplateData.Description = alert.Description;
                alertTemplateData.ModifiedBy = alert.LastModifiedBy;
                alertTemplateData.AlertTypeId = alert.AlertTemplateId;
                alertTemplateData.IsTemplate = true;
                alertTemplateData.IsMessage = false;
                alertTemplateData.TypeId = alert.AlertTypeId;

                alertTemplate.Add(alertTemplateData);
            }

            result.AssignItems(alertTemplate);

            return result;
        }
 /// <summary>
 /// Extracts the message paged records.
 /// </summary>
 /// <param name="presenter">The presenter.</param>
 private void ExtractMessagePagedRecords(PassengerPresenter presenter)
 {
     var maxPaging = DefaultPageSize > SessionData.Instance.MessageItems.Items.Count ? SessionData.Instance.MessageItems.Items.Count : DefaultPageSize;
     var pagingResult = SessionData.Instance.MessageItems.Items.Skip(0).Take(maxPaging - 0).ToList();
     if (pagingResult.Count > 0)
     {
         var pagingItems = new ListResult<Alert>();
         pagingItems.AssignItems(pagingResult);
         presenter.AssignMessageResult(pagingItems);
     }
 }