/// <summary> /// Searches the filters. /// </summary> /// <param name="passengerPresenter">The passenger presenter.</param> /// <param name="isExcept">if set to <c>true</c> [is except].</param> /// <param name="searchType">Type of the search.</param> /// <param name="pagingPageNumber">The paging page number.</param> /// <param name="option">The option.</param> /// <param name="isAll">The is all.</param> /// <returns> /// returns search filters /// </returns> private SearchFilters SetSearchFilters(PassengerPresenter passengerPresenter, bool isExcept, string searchType, int pagingPageNumber, string option, bool? isAll) { var exceptCountries = new List<string>(); List<string> selectedCountries = null; var filteredCountries = string.Empty; if (isExcept) { foreach (var country in passengerPresenter.Countries) { exceptCountries.Add(country.CountryId); } if (exceptCountries.Count > 0) { if (!string.IsNullOrEmpty(passengerPresenter.SelectedCitizenship)) { var exceptSelectedCountries = passengerPresenter.SelectedCitizenship.Split(CommaSeparatorChar).Select(i => i.Trim()).Where(i => !string.IsNullOrEmpty(i)).ToList(); foreach (var selectedCountry in exceptSelectedCountries) { exceptCountries.Remove(selectedCountry); } filteredCountries = exceptCountries.JoinWith(CommaSeparator); } } } var searchFilter = new SearchFilters(); switch (searchType) { case Stateroom: searchFilter.Stateroom = passengerPresenter.SearchText; break; case BookingNo: searchFilter.ReservationNo = passengerPresenter.SearchText; break; case PassportNo: searchFilter.PassportNo = passengerPresenter.SearchText; break; case LastName: searchFilter.LastNameContains = passengerPresenter.SearchText; break; case Birthdate: searchFilter.Birthdate = passengerPresenter.SearchText; break; default: searchFilter.LastNameContains = passengerPresenter.SearchText; break; } if (!string.IsNullOrEmpty(SessionData.Instance.IsMessageMode) && SessionData.Instance.IsMessageMode.Equals(TrueConstant, StringComparison.OrdinalIgnoreCase)) { searchFilter.IsMessageCount = true; searchFilter.IsMessage = true; passengerPresenter.IsMessage = true; searchFilter.IsAlertCount = false; } else { searchFilter.IsMessageCount = false; searchFilter.IsMessage = false; passengerPresenter.IsMessage = false; searchFilter.IsAlertCount = true; } searchFilter.PersonTypeId = !string.IsNullOrEmpty(option) ? option : passengerPresenter.SelectedPassengerType; searchFilter.VoyageId = passengerPresenter.SelectedVoyage; if (!string.IsNullOrWhiteSpace(passengerPresenter.SelectedCitizenship)) { selectedCountries = passengerPresenter.SelectedCitizenship.Split(',').ToList(); } searchFilter.Citizenship = isExcept ? filteredCountries : selectedCountries != null && selectedCountries.Count == SessionData.Instance.MasterData.Countries.Count ? string.Empty : passengerPresenter.SelectedCitizenship; searchFilter.MaxResult = ApplicationSettings.MaxPageSize; searchFilter.PageNumber = pagingPageNumber > 0 ? pagingPageNumber : 1; searchFilter.IsAll = isAll; return searchFilter; }
/// <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); } }
/// <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> /// Views the passenger. /// </summary> /// <param name="presenter">The presenter.</param> /// <param name="passengerId">The passenger identifier.</param> /// <param name="passengerTypeId">The passenger type identifier.</param> /// <returns>the task</returns> public async Task<ActionResult> ViewPassenger(PassengerPresenter presenter, string passengerId, string passengerTypeId) { ModelState.Clear(); if (presenter != null && !string.IsNullOrEmpty(passengerId)) { presenter.PassengerDetail = await this.personManager.GetPersonsByIdAsync(passengerId, passengerTypeId); SessionData.Instance.PersonItemListResult.Clear(); var personItemList = new List<Person>(); var person = new Person { PersonId = presenter.PassengerDetail.PersonId, PersonalDetail = presenter.PassengerDetail.PersonalDetail, PersonTypeId = presenter.PassengerDetail.PersonTypeId }; personItemList.Add(person); SessionData.Instance.AssignPersonSearchResult(personItemList); var alerts = await this.alertManager.ListAlertsAsync(ApplicationIds, passengerId, passengerTypeId); foreach (var alert in alerts.Items) { var addedDate = Convert.ToDateTime(alert.AddedDate, CultureInfo.InvariantCulture); alert.AddedDate = Convert.ToString(BaseController.GenerateLocalDateTime(addedDate), CultureInfo.InvariantCulture); } this.SetPagedRecordsForAlert(presenter, alerts); if (SessionData.Instance.MasterData != null && SessionData.Instance.MasterData.Ship != null && !string.IsNullOrEmpty(SessionData.Instance.MasterData.Ship.Name)) { presenter.ShipName = SessionData.Instance.MasterData.Ship.Name; } } return this.View(presenter); }
/// <summary> /// Passengers the count list. /// </summary> /// <param name="statusType">Type of the status.</param> /// <param name="personType">Type of the person.</param> /// <param name="pageNumber">The page number.</param> /// <returns> /// The passenger list view /// </returns> public async Task<ActionResult> PassengerCountList(string statusType, string personType, string pageNumber) { PassengerPresenter passengerPresenter = new PassengerPresenter(); BaseController.GetAboutUsInformation(passengerPresenter); var voyageIds = string.Empty; PersonStatusHistorySearchParameters searchFilters = SessionData.Instance.PersonStatusHistorySearchParameters != null && !string.IsNullOrEmpty(pageNumber) ? SessionData.Instance.PersonStatusHistorySearchParameters : new PersonStatusHistorySearchParameters(); if ((!string.IsNullOrEmpty(statusType) && !string.IsNullOrEmpty(personType)) && string.IsNullOrEmpty(pageNumber)) { SessionData.Instance.PersonStatusHistorySearchParameters = null; searchFilters.PersonTypeId = SessionData.Instance.MasterData.PersonTypes.Where(p => p.Name.Equals(personType)).Select(p => p.PersonTypeId).FirstOrDefault(); searchFilters.StatsDate = BaseController.GenerateLocalDateTime(DateTime.UtcNow).ToShortDateString(); searchFilters.StatusType = statusType; if (statusType.Equals(CheckedinConstant) && searchFilters.PersonTypeId.Equals(CrewConstant)) { statusType = SignedOnConstant; } else if (statusType.Equals(CheckedinConstant) && searchFilters.PersonTypeId.Equals(GuestConstant)) { statusType = CheckedinConstantValue; } else if (statusType.Equals(ExpectedTodayConstant) && (searchFilters.PersonTypeId.Equals(GuestConstant) || searchFilters.PersonTypeId.Equals(CrewConstant))) { statusType = ExpectedTodayConstantValue; } passengerPresenter.PassengerStatusName = personType + " " + statusType; if (SessionData.Instance.MasterData.Ship != null && !string.IsNullOrEmpty(SessionData.Instance.MasterData.Ship.ShipId)) { searchFilters.ShipId = SessionData.Instance.MasterData.Ship.ShipId; } searchFilters.MaxResult = ApplicationSettings.MaxPageSize; voyageIds += string.Join(CommaSeparator, SessionData.Instance.MasterData.Voyages.Where(voyage => voyage.IsActive).Select(voyage => voyage.VoyageId).ToArray()); searchFilters.VoyageIds = voyageIds; SessionData.Instance.AssignPersonStatusList(searchFilters); } else { if (searchFilters.PersonTypeId.Equals(GuestConstant)) { personType = "Guest"; } else if (searchFilters.PersonTypeId.Equals(CrewConstant)) { personType = "Crew"; } if (searchFilters.StatusType.Equals(CheckedinConstant) && searchFilters.PersonTypeId.Equals(CrewConstant)) { statusType = SignedOnConstant; } else if (searchFilters.StatusType.Equals(CheckedinConstant) && searchFilters.PersonTypeId.Equals(GuestConstant)) { statusType = CheckedinConstantValue; } else if (searchFilters.StatusType.Equals(ExpectedTodayConstant) && (searchFilters.PersonTypeId.Equals(GuestConstant) || searchFilters.PersonTypeId.Equals(CrewConstant))) { statusType = ExpectedTodayConstantValue; } passengerPresenter.PassengerStatusName = personType + " " + statusType; } searchFilters.PageNumber = (!string.IsNullOrEmpty(pageNumber) && !pageNumber.Equals(UndefinedConstant)) ? (Convert.ToInt32(pageNumber) > 0 ? Convert.ToInt32(pageNumber) / ApplicationSettings.MaxPageSize : 1) : 1; var personStatus = await this.personManager.GetPersonStatusHistoryAsync(searchFilters); if (personStatus != null) { passengerPresenter.AssignPersonStatusHistoryResult(personStatus); } if (!string.IsNullOrEmpty(pageNumber)) { return this.PartialView("_SearchPassengerCountList", passengerPresenter); } return this.View(passengerPresenter); }
/// <summary> /// Adds the passenger. /// </summary> /// <param name="passengerPresenter">The passenger presenter.</param> /// <returns> /// The JSON Result /// </returns> public JsonResult AddPassenger(PassengerPresenter passengerPresenter) { if (passengerPresenter != null) { if (!string.IsNullOrEmpty(passengerPresenter.PersonIds) || (SessionData.Instance.SelectedPassengerIds != null && SessionData.Instance.SelectedPassengerIds.Count > 0)) { var filteredPersonList = new List<Person>(); foreach (var persionId in SessionData.Instance.SelectedPassengerIds) { if (!SessionData.Instance.SelectedPersonIds.Contains(persionId)) { SessionData.Instance.SelectedPersonIds.Add(persionId); } } foreach (var personId in SessionData.Instance.SelectedPersonIds) { if (SessionData.Instance.PersonItemListResult != null) { foreach (var person in SessionData.Instance.PersonItemListResult) { if (person.PersonId == personId) { filteredPersonList.Add(person); } } } } if (filteredPersonList.Count > 0) { if (SessionData.Instance.FilterPersonList != null) { foreach (var person in SessionData.Instance.FilterPersonList) { if (!filteredPersonList.Any(p => p.PersonId == person.PersonId)) { filteredPersonList.Add(person); } } } } SessionData.Instance.AssignFilterPersonResult(filteredPersonList); } } return this.Json(true); }
/// <summary> /// Passengers the list. /// </summary> /// <param name="searchFilters">The search filters.</param> /// <returns> /// the task. /// </returns> public ActionResult PassengerList(SearchFilters searchFilters) { var passengerPresenter = new PassengerPresenter(); if (!string.IsNullOrEmpty(SessionData.Instance.IsMessageMode) && SessionData.Instance.IsMessageMode.Equals(TrueConstant, StringComparison.OrdinalIgnoreCase)) { passengerPresenter.IsMessage = true; } BaseController.GetAboutUsInformation(passengerPresenter); if (searchFilters != null) { } return this.View(passengerPresenter); }
/// <summary> /// Paging the specified passenger presenter. /// </summary> /// <param name="passengerPresenter">The passenger presenter.</param> /// <param name="pageNumber">The page number.</param> /// <param name="partialView">The partial view.</param> /// <param name="isExcept">if set to <c>true</c> [is except].</param> /// <param name="searchType">Type of the search.</param> /// <param name="option">The option.</param> /// <param name="isAll">The is all.</param> /// <returns> /// The Action Result. /// </returns> public async Task<ActionResult> Paging(PassengerPresenter passengerPresenter, string pageNumber, string partialView, bool isExcept, string searchType, string option, bool? isAll) { if (passengerPresenter != null && !string.IsNullOrEmpty(pageNumber) && !pageNumber.Equals(UndefinedConstant) && !string.IsNullOrEmpty(partialView)) { if (!string.IsNullOrEmpty(partialView) && string.Equals(partialView, SearchPassengerListPartialView, StringComparison.OrdinalIgnoreCase)) { var personsList = SessionData.Instance.PersonItemListResult.ToList(); var pagingResult = GetPagedResult(Convert.ToString(pageNumber), personsList); if (pagingResult != null && pagingResult.Count > 0) { var pagingListResult = new ListResult<Person>(); pagingListResult.AssignItems(pagingResult); pagingListResult.TotalResults = SessionData.Instance.TotalResults; passengerPresenter.AssignPersonSearchResult(pagingListResult); passengerPresenter.GuestTotalResults = SessionData.Instance.GuestTotal; passengerPresenter.CrewTotalResults = SessionData.Instance.CrewTotal; passengerPresenter.VisitorTotalResults = SessionData.Instance.VisitorTotal; passengerPresenter.IsMessage |= !string.IsNullOrEmpty(SessionData.Instance.IsMessageMode) && SessionData.Instance.IsMessageMode.Equals(TrueConstant, StringComparison.OrdinalIgnoreCase); if (!string.IsNullOrEmpty(option)) { passengerPresenter.SelectedOptionType = option; } else if (string.IsNullOrEmpty(passengerPresenter.SelectedPassengerType) && string.IsNullOrEmpty(option)) { passengerPresenter.SelectedOptionType = passengerPresenter.GuestTotalResults > 0 ? GuestConstant : passengerPresenter.CrewTotalResults > 0 ? CrewConstant : passengerPresenter.VisitorTotalResults > 0 ? VisitorConstant : string.Empty; } return this.PartialView(SearchPassengerListPartialView, passengerPresenter); } } else { if (string.IsNullOrEmpty(passengerPresenter.SelectedVoyage)) { foreach (var voyage in SessionData.Instance.MasterData.Voyages) { passengerPresenter.SelectedVoyage += voyage.VoyageId + CommaSeparator; } } var pagingPageNumber = Convert.ToInt32(pageNumber) > 0 ? Convert.ToInt32(pageNumber) / ApplicationSettings.MaxPageSize : 1; var persons = await this.personManager.GetPersonsAsync(this.SetSearchFilters(passengerPresenter, isExcept, searchType, pagingPageNumber, option, isAll), passengerPresenter.AuthenticationToken); passengerPresenter.GuestTotalResults = persons.GuestTotalResults; passengerPresenter.CrewTotalResults = persons.CrewTotalResults; passengerPresenter.VisitorTotalResults = persons.VisitorTotalResults; passengerPresenter.IsMessage |= !string.IsNullOrEmpty(SessionData.Instance.IsMessageMode) && SessionData.Instance.IsMessageMode.Equals(TrueConstant, StringComparison.OrdinalIgnoreCase); if (!string.IsNullOrEmpty(option)) { passengerPresenter.SelectedOptionType = option; } else if (string.IsNullOrEmpty(passengerPresenter.SelectedPassengerType) && string.IsNullOrEmpty(option)) { passengerPresenter.SelectedOptionType = passengerPresenter.GuestTotalResults > 0 ? GuestConstant : passengerPresenter.CrewTotalResults > 0 ? CrewConstant : passengerPresenter.VisitorTotalResults > 0 ? VisitorConstant : string.Empty; } SessionData.Instance.AssignPersonSearchResult(persons.Items.ToList()); passengerPresenter.AssignPersonSearchResult(persons); return this.PartialView(partialView, passengerPresenter); } } return this.PartialView(partialView, passengerPresenter); }
public async Task<ActionResult> SearchPassenger(PassengerPresenter passengerPresenter, bool isExcept, string searchType, bool passengerList, string option, bool? isAll) { ModelState.Clear(); if (string.IsNullOrEmpty(option)) { SessionData.Instance.SelectedPassengerIds.Clear(); } if (string.IsNullOrEmpty(passengerPresenter.SelectedVoyage)) { foreach (var voyage in SessionData.Instance.MasterData.Voyages) { passengerPresenter.SelectedVoyage += voyage.VoyageId + CommaSeparator; } } var partialView = PassengerListPartialView; if (passengerList) { partialView = SearchPassengerListPartialView; } var persons = new ListResult<Person>(); if (!string.IsNullOrEmpty(passengerPresenter.SelectedCitizenship)) { var selectedCitizenShip = passengerPresenter.SelectedCitizenship.Split(CommaSeparatorChar).ToList(); if ((!isExcept && selectedCitizenShip.Count != 0) || (isExcept && selectedCitizenShip.Count != 0 && selectedCitizenShip.Count < SessionData.Instance.MasterData.Countries.Count)) { if (passengerList) { persons = await this.personManager.GetPersonsAlertAndMessageAsync(this.SetSearchFilters(passengerPresenter, isExcept, searchType, 0, option, isAll)); SessionData.Instance.PersonItemListResult.Clear(); SessionData.Instance.GuestTotal = persons.GuestTotalResults; SessionData.Instance.CrewTotal = persons.CrewTotalResults; SessionData.Instance.VisitorTotal = persons.VisitorTotalResults; SessionData.Instance.TotalResults = persons.TotalResults; } else { persons = await this.personManager.GetPersonsAsync(this.SetSearchFilters(passengerPresenter, isExcept, searchType, 0, option, isAll), passengerPresenter.AuthenticationToken); } passengerPresenter.GuestTotalResults = persons.GuestTotalResults; passengerPresenter.CrewTotalResults = persons.CrewTotalResults; passengerPresenter.VisitorTotalResults = persons.VisitorTotalResults; SessionData.Instance.AssignPersonSearchResult(persons.Items.ToList()); var personList = new ListResult<Person>(); personList.AssignItems(persons.Items.Take(ApplicationSettings.MaxPageSize).ToList()); personList.GuestTotalResults = persons.GuestTotalResults; personList.CrewTotalResults = persons.CrewTotalResults; personList.VisitorTotalResults = persons.VisitorTotalResults; personList.TotalResults = persons.TotalResults; passengerPresenter.AssignPersonSearchResult(personList); } } if (!string.IsNullOrEmpty(option)) { passengerPresenter.SelectedOptionType = option; } else if (string.IsNullOrEmpty(passengerPresenter.SelectedPassengerType) && string.IsNullOrEmpty(option)) { passengerPresenter.SelectedOptionType = passengerPresenter.GuestTotalResults > 0 ? GuestConstant : passengerPresenter.CrewTotalResults > 0 ? CrewConstant : passengerPresenter.VisitorTotalResults > 0 ? VisitorConstant : GuestConstant; } return this.PartialView(partialView, passengerPresenter); }
/// <summary> /// Indexes this instance. /// </summary> /// <returns>The Action Result.</returns> public ActionResult Index() { var passengerPresenter = new PassengerPresenter(); BaseController.GetAboutUsInformation(passengerPresenter); SessionData.Instance.SelectedPassengerIds.Clear(); return this.View(IndexView, passengerPresenter); }
public void PassengerAddPassengerTest() { try { SessionData.Instance.User = CommonHelper.SetupUserData(); var passengerPresenter = new PassengerPresenter(); ListResult<Person> persons = SetUpPersonPagingData(); SessionData.Instance.AssignPersonSearchResult(persons.Items.ToList()); passengerPresenter.PersonIds = "917,1544"; SessionData.Instance.SelectedPersonIds.Add("1544"); var result = this.passengerController.AddPassenger(passengerPresenter) as JsonResult; Assert.IsNotNull(result); Assert.IsTrue(true); passengerPresenter.PersonIds = "1421,4103"; var result1 = this.passengerController.AddPassenger(passengerPresenter) as JsonResult; Assert.IsNotNull(result1); Assert.IsTrue(true); SessionData.Instance.SelectedPassengerIds.Add("4103"); SessionData.Instance.SelectedPersonIds.Add("917"); SessionData.Instance.AssignFilterPersonResult(persons.Items.ToList()); result = this.passengerController.AddPassenger(passengerPresenter) as JsonResult; Assert.IsNotNull(result); } finally { this.Dispose(); } }
public async Task SearchPassengerTest() { try { SessionData.Instance.User = CommonHelper.SetupUserData(); ListResult<Person> persons = SetUpPersonData(); var passengerPresenter = new PassengerPresenter(); passengerPresenter.SearchText = "Oliver"; this.personManager.Setup(mockItem => mockItem.GetPersonsAsync(It.IsNotNull<SearchFilters>(), It.IsAny<string>())).Returns(Task.FromResult(persons)); this.personManager.Setup(mockItem => mockItem.GetPersonsAlertAndMessageAsync(It.IsNotNull<SearchFilters>())).Returns(Task.FromResult(persons)); passengerPresenter.SelectedCitizenship = "1,2,3,4,5,17,18,19"; passengerPresenter.SearchText = "00828"; var task1 = await this.passengerController.SearchPassenger(passengerPresenter, true, "Stateroom", false, string.Empty, true) as PartialViewResult; Assert.IsTrue(true); var pagingResult = await this.passengerController.Paging((PassengerPresenter)task1.Model, "2", PassengerListPartialView, true, "Stateroom", string.Empty, true); Assert.IsTrue(true); pagingResult = await this.passengerController.Paging(null, "2", PassengerListPartialView, true, "Stateroom", string.Empty, true); Assert.IsTrue(true); SessionData.Instance.IsMessageMode = "true"; pagingResult = await this.passengerController.Paging((PassengerPresenter)task1.Model, "2", PassengerListPartialView, true, "Stateroom", "test", true); Assert.IsTrue(true); passengerPresenter.SearchText = "1B3GL3"; var task3 = this.passengerController.SearchPassenger(passengerPresenter, false, "BookingNo", false, string.Empty, true); await task3; Assert.IsTrue(true); passengerPresenter.SearchText = "526660239"; var task4 = this.passengerController.SearchPassenger(passengerPresenter, false, "PassportNo", false, string.Empty, true); await task4; Assert.IsTrue(true); passengerPresenter.SearchText = "Oliver"; var task5 = this.passengerController.SearchPassenger(passengerPresenter, false, "LastName", false, string.Empty, true); await task5; Assert.IsTrue(true); passengerPresenter.SearchText = "2015-05-12"; var task6 = this.passengerController.SearchPassenger(passengerPresenter, false, "Birthdate", false, string.Empty, true); await task6; Assert.IsTrue(true); var task7 = this.passengerController.SearchPassenger(passengerPresenter, false, "Birthdate", true, string.Empty, true); await task7; Assert.IsTrue(true); } finally { this.Dispose(); } }