public IActionResult Index() { SearchFlightModel model = new SearchFlightModel(); model.RoutesList = GetListRoutes(); return(View(model)); }
public void TestFlightsExpectedResults() { SearchFlightModel inputSearch = new SearchFlightModel() { Origin = "LHR", Destination = "BOS" }; List <SearchFlightModel> expectedResult = new List <SearchFlightModel>(); SearchFlight source = new SearchFlight(); expectedResult = source.searchFlighsByOriginDestination(inputSearch); searchFlightsController controller = new searchFlightsController(); var view = controller.Index(inputSearch) as ViewResult; List <SearchFlightModel> actualResult = (List <SearchFlightModel>)view.ViewData.Model; Assert.AreEqual(expectedResult.Count, actualResult.Count); if (expectedResult.Count > 0) { for (int i = 0; i >= expectedResult.Count; i++) { Assert.AreEqual(expectedResult[i].Origin, actualResult[i].Origin); Assert.AreEqual(expectedResult[i].DepartureTime, actualResult[i].DepartureTime); Assert.AreEqual(expectedResult[i].Destination, actualResult[i].DestinationTime); Assert.AreEqual(expectedResult[i].DestinationTime, actualResult[i].DestinationTime); Assert.AreEqual(expectedResult[i].Price, actualResult[i].Price); } } }
public ActionResult Index(SearchFlightModel inputSearch) { if (ModelState.IsValid) { List <SearchFlightModel> result = new List <SearchFlightModel>(); SearchFlight source = new SearchFlight(); result = source.searchFlighsByOriginDestination(inputSearch); ViewBag.NoRecordFound = false; //check flight count if its zero then message is created & if its greater than zero, flight list will be display on view. if (result.Count <= 0) { ViewBag.NoRecordFound = true; ViewBag.Message = "No Flights Found for " + inputSearch.Origin + " --> " + inputSearch.Destination; } return(View(result)); } else { //Model state is not valid, for validation please check the model return(RedirectToAction("Index", "InvalidRequest")); } }
public IActionResult Insert(int idFligth) { SearchFlightModel model = HttpContext.Session.Get <SearchFlightModel>("Model"); try { Flight flight = model.FlightsList.Where(p => p.PK_IdFligth == idFligth).FirstOrDefault(); flight.PK_IdFligth = 0; if (oFlightDA.InsertFligth(flight)) { model.TipoError = "alert alert-success alert-dismissible fade show"; model.VerError = true; model.MensajeError = "El registro se insertó correctamente."; HttpContext.Session.Set("Model", model); } else { model.TipoError = "alert alert-warning alert-dismissible fade show"; model.VerError = true; model.MensajeError = "Ocurrió un error al insertar el registro, por favor intente nuevamente."; } return(View("Index", model)); } catch (Exception ex) { model.VerError = true; model.MensajeError = $"Se presentó un error, por favor comuníquese con el administrador del sistema."; oLogger.LogError(ex, "Error al insertar el registro"); return(View("Index", model)); } }
public IActionResult Index(SearchFlightModel model) { model.RoutesList = GetListRoutes(); try { if (ModelState.IsValid) { if (model.Origin == model.Destination) { model.VerError = true; model.MensajeError = "El destino el igual al origen, por favor seleccione un destino diferente."; return(View(model)); } model.FlightsList = oConsumeAPI.GetFlights(GetValuerModel(model)); HttpContext.Session.Set <SearchFlightModel>("Model", model); } return(View(model)); } catch (Exception ex) { model.VerError = true; model.MensajeError = "Se presentó un error, por favor comuníquese con el administrador del sistema."; oLogger.LogError(ex, "Error al consultar los vuelos disponibles."); return(View(model)); } }
public ActionResult Book(SearchFlightModel model) { if (model.Origin == null) { return(JavaScript("window.location = '" + Redirect("/Home/Index").Url + "'")); } return(View(model)); }
public void TestFlightsFound() { SearchFlightModel inputSearch = new SearchFlightModel() { Origin = "MIA", Destination = "ORD" }; searchFlightsController controller = new searchFlightsController(); var result = controller.Index(inputSearch) as ViewResult; Assert.AreEqual(false, result.ViewBag.NoRecordFound); }
public void TestNoFlightFound() { SearchFlightModel inputSearch = new SearchFlightModel() { Origin = "abc", Destination = "wxy" }; searchFlightsController controller = new searchFlightsController(); ViewResult view = controller.Index(inputSearch) as ViewResult; Assert.AreEqual(true, view.ViewBag.NoRecordFound); Assert.AreEqual("No Flights Found for " + inputSearch.Origin + " --> " + inputSearch.Destination, view.ViewBag.Message); }
public async Task <IActionResult> Index(SearchFlightModel model) { if (ModelState.IsValid) { var destinationFrom = await _destinationRepository.GetDestinationByNameAsync(model.From); //Confirmar a existência das cidades if (destinationFrom == null) { this.ModelState.AddModelError(string.Empty, "Destination From does not exist!"); return(View(model)); } var destinationTo = await _destinationRepository.GetDestinationByNameAsync(model.To); //Confirmar a existência das cidades if (destinationTo == null) { this.ModelState.AddModelError(string.Empty, "Destination To does not exist!"); return(View(model)); } ShowListFlightsModel modelView = new ShowListFlightsModel(); modelView.Flights = _flightRepository.GetFlightsFromToAndDeparture(model.From, model.To, model.Departure); if (modelView.Flights.Count == 0) { this.ModelState.AddModelError(string.Empty, "There are no flights from the selected airport!"); return(View(model)); } modelView.isRoundTrip = 2; // One-Way if (model.Trip == 1) // Roundtrip { modelView.FlightsReturn = _flightRepository.GetFlightsFromToAndDeparture(model.To, model.From, model.Return); modelView.isRoundTrip = 1; if (modelView.FlightsReturn.Count == 0) { modelView.isRoundTrip = 1; this.ModelState.AddModelError(string.Empty, "There are no flights from the return airport!"); return(View(model)); } } // Redireccionar para o booking (levar o modelo) TempData.Put("FlightsList", modelView); return(RedirectToAction("ViewFlights", "Home")); } return(View(model)); }
public void TestInvalidModelState() { SearchFlightModel inputSearch = new SearchFlightModel() { Origin = "", Destination = "" }; searchFlightsController controller = new searchFlightsController(); controller.ModelState.AddModelError("Required", "Required"); var result = controller.Index(inputSearch) as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); Assert.AreEqual("InvalidRequest", result.RouteValues["controller"]); }
private Dictionary <string, string> GetValuerModel(SearchFlightModel model) { try { Dictionary <string, string> ValuesAPI = new Dictionary <string, string>(); foreach (string item in oIConfiguration["ValuesAPI"].Split(',')) { PropertyInfo propertyInfo = model.GetType().GetProperty(item); ValuesAPI.Add(item, (string)propertyInfo.GetValue(model)); } return(ValuesAPI); } catch (Exception) { throw; } }
/// <summary> /// Returns the filtered & sorted flight data. This function combines data from all three sources and return filtered & sorted flight data /// </summary> /// <param name="inputSearch"> model having values for Orign & Destination</param> /// <returns>List of filtered,sorted </returns> public List <SearchFlightModel> ReadFlightData(SearchFlightModel model) { IDataRepository repository = new DataRepository(); DataTable resultDT = repository.ReadDataFromProvider(provider.GetProviderName(), provider.GetProviderFileSeprator()); //get the flight data from datatable List <SearchFlightModel> items = resultDT.AsEnumerable() .Where(row => row.Field <string>("Origin") == model.Origin && row.Field <string>("Destination") == model.Destination) .Select(row => new SearchFlightModel { Origin = row.Field <string>("Origin"), DepartureTime = row.Field <DateTime>("Departure Time"), Destination = row.Field <string>("Destination"), DestinationTime = row.Field <DateTime>("Destination Time"), Price = row.Field <float>("Price") }).Distinct().OrderBy(x => x.Price).ThenBy(x => x.DepartureTime).ToList(); return(items); }
/// <summary> /// Returns the filtered & sorted flight data. This function combines data from all three sources and return filtered & sorted flight data /// </summary> /// <param name="inputSearch"> model having values for Orign & Destination</param> /// <returns>List of filtered,sorted </returns> public List <SearchFlightModel> searchFlighsByOriginDestination(SearchFlightModel inputSearch) { //Depenancy Injection SearchFlightsRepo source1 = new SearchFlightsRepo((new DBProvider1())); SearchFlightsRepo source2 = new SearchFlightsRepo((new DBProvider2())); SearchFlightsRepo source3 = new SearchFlightsRepo((new DBProvider3())); //get filtered the data from provider List <SearchFlightModel> sourcedata1 = source1.ReadFlightData(inputSearch); List <SearchFlightModel> sourcedata2 = source2.ReadFlightData(inputSearch); List <SearchFlightModel> sourcedata3 = source3.ReadFlightData(inputSearch); //combines the result of all three provider var combinedResult = ((from p1 in sourcedata1 select p1) .Union(from p2 in sourcedata2 select p2) .Union(from p3 in sourcedata3 select p3)).ToList(); //remove the duplicate records & sort them by Price & departureTime List <SearchFlightModel> result = combinedResult.GroupBy(d => new { d.Origin, d.DepartureTime, d.Destination, d.DestinationTime, d.Price }) .Select(d => d.First()).OrderBy(x => x.Price).ThenBy(x => x.DepartureTime).ToList(); return(result); }
//[Route("Api/[controller]/[action]")] public ActionResult Search(SearchFlightModel model) { //var a = new VNAService(); //return a.TicketSearch(model); return(Notifization.TEST("ok")); }
public ActionResult BookFlight(SearchFlightModel model) { try { using (var ctx = new UIA_Entities()) { FlightRecord flight_record = new FlightRecord(); flight_record.Name = model.Name; flight_record.PassportNumber = model.PassportNumber; flight_record.SeatNo = model.SeatNo; flight_record.Time = model.Time; flight_record.Origin = model.Origin; flight_record.Destination = model.Destination; flight_record.SeatClass = model.Seat_Class; flight_record.Price = model.Price; flight_record.SeatNo = model.SeatNo; flight_record.UserId = model.UserId; flight_record.DateOfBirth = model.DateOfBirth; flight_record.Email = model.Email; flight_record.Id = Guid.NewGuid().ToString("N"); flight_record.FlightID = (from table in ctx.Flights where table.fromAirport == model.OriginAirport where table.toAirport == model.DestinationAirport select table.Id).Single(); ctx.FlightRecords.Add(flight_record); ctx.SaveChanges(); } using (var ctx = new UIA_Entities()) { if (model.hasReturn) { FlightRecord flight_record_return = new FlightRecord(); flight_record_return.Name = model.Name; flight_record_return.PassportNumber = model.PassportNumber; flight_record_return.SeatNo = model.SeatNo; flight_record_return.Time = model.TimeReturn; flight_record_return.Origin = model.OriginReturn; flight_record_return.Destination = model.DestinationReturn; flight_record_return.SeatClass = model.Seat_Class; flight_record_return.Price = model.PriceReturn; flight_record_return.SeatNo = model.SeatNo; flight_record_return.UserId = model.UserId; flight_record_return.DateOfBirth = model.DateOfBirth; flight_record_return.Email = model.Email; flight_record_return.Id = Guid.NewGuid().ToString("N"); flight_record_return.FlightID = (from table in ctx.Flights where table.fromAirport == model.OriginAirportReturn where table.toAirport == model.DestinationAirportReturn select table.Id).Single(); ctx.FlightRecords.Add(flight_record_return); ctx.SaveChanges(); } } using (var ctx = new UIA_Entities()) { PaymentRecord payment = new PaymentRecord(); payment.UserId = model.UserId; payment.CCV = model.CCV; payment.PurchaseDate = DateTime.Now; payment.CardHolderName = model.CardHolderName; payment.CardType = model.CardType; payment.CardNumber = model.CardNumber; payment.TotalPrice = model.TotalPrice; payment.PurchaseId = Guid.NewGuid().ToString("N"); payment.ExpiryDate = model.ExpiryDate; ctx.PaymentRecords.Add(payment); ctx.SaveChanges(); } } catch (Exception e) { throw e; } return(RedirectToAction("BookingConfirmed")); }
public List <SearchFlightModel> SearchFlight(SearchFlightQueryModel query) { List <SearchFlightModel> ibeFlightModels = _searchContainPolicyFlightBll.SearchFlight(query); List <SearchFlightModel> filterSearchlist = new List <SearchFlightModel>(); //个性化设置过滤 foreach (var searchFlightModel in ibeFlightModels) { //TODO:2)个性化不显示共享航班,如当前是共享航班,则不加入list if (query.IsShareFly == 0 && searchFlightModel.IsShared) { continue; } //TODO:3)协议价格是单独展示 //if (query.IsXYPrice == 1) //{ // List<SearchFlightDetailModel> interDetail = new List<SearchFlightDetailModel>(); // for (var i = 0; i < searchFlightModel.DetailList.Count; i++) // { // if (searchFlightModel.DetailList[i].PriceType != "C")//"C"不等于普通价格 // { // var SearchModel = searchFlightModel.DetailList[i]; // SearchFlightDetailModel SearchModelCopy = (SearchFlightDetailModel)searchFlightModel.DetailList[i].Clone();//TODO:mapper // SearchModelCopy.PriceType = "C";//更改成非协议 // SearchModelCopy.SalePrice = SearchModel.FacePrice;//把销售价更改成面单价 // SearchModelCopy.Rate = ((Convert.ToDecimal(SearchModelCopy.SalePrice) / Convert.ToDecimal(SearchModelCopy.BaseFacePrice)) * 10).ToString("0.0"); // interDetail.Add(SearchModelCopy); // } // } // searchFlightModel.DetailList.AddRange(interDetail); //} filterSearchlist.Add(searchFlightModel); } if (string.IsNullOrEmpty(query.CorpId)) //没有公司Id的直接返回ibe航班信息 { return(filterSearchlist); } if (filterSearchlist == null || filterSearchlist.Count == 0) { return(filterSearchlist); } foreach (var searchFlightModel in filterSearchlist) { if (string.IsNullOrEmpty(searchFlightModel.SharedFlightNo) || string.IsNullOrEmpty(searchFlightModel.AirlineNo) || string.IsNullOrEmpty(searchFlightModel.FlightNo)) { continue; } //通过实际航班找到它对应的信息 SearchFlightModel shared = filterSearchlist.Find(n => (n.AirlineNo + n.FlightNo) == searchFlightModel.SharedFlightNo); if (shared != null && shared.DetailList != null && shared.DetailList.Count > 0) { SearchFlightDetailModel priceDetail = shared.DetailList.Find(n => n.PriceType == "X" || n.PriceType == "G"); if (priceDetail != null) { searchFlightModel.IsSharedFlightNoHasXieYiPrice = true; } } } return(filterSearchlist); }
//public List<IEnumerable<TblFlightDetails>> SearchFlights(List<SearchFlightModel> searchFlightModels) //{ // List<IEnumerable<TblFlightDetails>> lstFlightResult = new List<IEnumerable<TblFlightDetails>>(); // foreach (var criteria in searchFlightModels) // { // lstFlightResult.Add(_dbContext.TblFlightDetails.Where(x => x.Origin.ToLower() == criteria.origin.ToLower() && x.Destination.ToLower() == criteria.destination.ToLower() && x.DepatureDate == criteria.depatureTime && x.NoOfSeat>=criteria.noOfSeat)); // } // return lstFlightResult; //} public List <TblFlightDetails> SearchFlights(SearchFlightModel searchFlightModels) { return(_dbContext.TblFlightDetails.Where(x => x.Origin.ToLower() == searchFlightModels.origin.ToLower() && x.Destination.ToLower() == searchFlightModels.destination.ToLower() && x.DepatureDate == searchFlightModels.depatureTime && x.NoOfSeat >= searchFlightModels.noOfSeat).ToList()); // List<IEnumerable<TblFlightDetails>> lstFlightResult = new List<IEnumerable<TblFlightDetails>>(); }
public ActionResult SearchResultPage(SearchFlightModel model) { if (currency == null) { string client_ip = GetIPAddress(); if (currency == null) { iplocation = HomeController.GetIPLocation(client_ip); if (currency == null) { currency = "$ "; } } } var euroCountries = new List <string>(); euroCountries.AddRange(new String[] { "DE", "DK", "SE", "IT", "NL", "PL", "NO", "FI" }); if (iplocation.CountryCode == "MY") { System.Web.HttpContext.Current.Items["currency"] = "RM "; currency = "RM "; } else if (euroCountries.Contains(iplocation.CountryCode)) { System.Web.HttpContext.Current.Items["currency"] = "€ "; currency = "€ "; } else { System.Web.HttpContext.Current.Items["currency"] = "$ "; currency = "$ "; } using (var ctx = new UIA_Entities()) { ApplicationUser appUser = UserManager.FindById(User.Identity.GetUserId()); model.Name = appUser.Name; model.Email = appUser.Email; model.PhoneNumber = appUser.PhoneNumber; model.UserId = appUser.Id; model.PassportNumber = appUser.PassportNumber; model.DateOfBirth = appUser.DateOfBirth; model.Destination = (from table in ctx.Airports where table.Id == model.DestinationAirport select table.City).Single(); model.Origin = (from table in ctx.Airports where table.Id == model.OriginAirport select table.City).Single(); model.Price = (from table in ctx.Flights where table.fromAirport == model.OriginAirport where table.toAirport == model.DestinationAirport select table.Price).Single(); TimeSpan timeTaken = (from table in ctx.Flights where table.fromAirport == model.OriginAirport where table.toAirport == model.DestinationAirport select table.DepartureTime).Single(); model.Time = model.Date.Add(timeTaken); int duration = (from table in ctx.Flights where table.fromAirport == model.OriginAirport where table.toAirport == model.DestinationAirport select table.Duration).Single(); model.ArrivalTime = model.Time.AddMinutes(duration); model.Duration = duration.ToString() + " minutes"; Console.WriteLine(model.Date); Console.WriteLine(model.Time); model.TotalPrice = model.Price; if (model.hasReturn) { model.hasReturn = true; model.DestinationReturn = model.Origin; model.OriginReturn = model.Destination; model.DestinationAirportReturn = model.OriginAirport; model.OriginAirportReturn = model.DestinationAirport; model.PriceReturn = (from table in ctx.Flights where table.fromAirport == model.OriginAirportReturn where table.toAirport == model.DestinationAirportReturn select table.Price).Single(); TimeSpan timeTakenReturn = (from table in ctx.Flights where table.fromAirport == model.OriginAirportReturn where table.toAirport == model.DestinationAirportReturn select table.DepartureTime).Single(); model.TimeReturn = model.DateReturn.AddTicks(timeTakenReturn.Ticks); int durationReturn = (from table in ctx.Flights where table.fromAirport == model.OriginAirportReturn where table.toAirport == model.DestinationAirportReturn select table.Duration).Single(); model.ArrivalTimeReturn = model.TimeReturn.AddMinutes(durationReturn); model.DurationReturn = durationReturn.ToString() + " minutes"; model.TotalPrice += model.PriceReturn; } } return(View(model)); }
public async Task <ActionResult <IEnumerable <Flight> > > SearchFlights(int airlineId, SearchFlightModel flight) { // po default-u // 1 januar 2001 00 00 00 var airline = await _context.Airlines .Include(x => x.Flights) .FirstOrDefaultAsync(x => x.Id == airlineId); if (!String.IsNullOrEmpty(flight.StartDestination)) { airline.Flights = airline.Flights.FindAll(x => x.StartDestination.ToLower().Contains(flight.StartDestination.ToLower())); } if (!String.IsNullOrEmpty(flight.EndDestination)) { airline.Flights = airline.Flights.FindAll(x => x.EndDestination.ToLower().Contains(flight.EndDestination.ToLower())); } if (flight.StartDate.Date.ToString("d") != new DateTime(2001, 1, 1).Date.ToString("d")) { airline.Flights = airline.Flights.FindAll(x => x.StartDateAndTime.Date.ToString("d") == flight.StartDate.Date.ToString("d")); } if (!String.IsNullOrEmpty(flight.TicketPrice)) { int lowerPrice = Int32.Parse(flight.TicketPrice.Split('-')[0]); int higherPrice = Int32.Parse(flight.TicketPrice.Split('-')[1]); airline.Flights = airline.Flights.FindAll(x => lowerPrice <= x.TicketPrice && x.TicketPrice <= higherPrice); } return(airline.Flights); }
public List <SearchFlightModel> SearchFlight(SearchFlightQueryModel query) { List <SearchFlightModel> polictFlightModels = _ibeFlightServiceBll.SearchFlight(query); #region 判断是否在名单内 bool flag1 = true; //人名判断 bool flag2 = true; //证件判断 query.PassengerNameList.ForEach(n => { if (!_checkPassengerIsInWhiteListBll.CheckPassengerName(n))//一旦有一个人不存在名单内,就设置不在名单 { flag1 = false; } }); query.CardNoList.ForEach(n => { if (!_checkPassengerIsInWhiteListBll.CheckPassengerCardNo(n))//一旦有一个人不存在名单内,就设置不在名单 { flag2 = false; } }); #endregion List <SearchFlightModel> tempFlightModels = new List <SearchFlightModel>(); foreach (SearchFlightModel polictFlightModel in polictFlightModels) { SearchFlightModel tempFlightModel = polictFlightModel; //根据不同的航司获取对应的名单判断规则 bool flag0 = flag2; //默认证件判断 if (CheckByNameAirlineNo.Contains(tempFlightModel.AirlineNo.ToUpper())) //人名判断 { flag0 = flag1; } List <SearchFlightDetailModel> tempFlightDetailModels = new List <SearchFlightDetailModel>(); foreach (SearchFlightDetailModel searchFlightDetailModel in polictFlightModel.DetailList) { //不在名单内,去除B2G价格,并且将协议价格转成普通价格 if (!flag0) { if (searchFlightDetailModel.PriceType == "C") { tempFlightDetailModels.Add(searchFlightDetailModel); } else if (searchFlightDetailModel.PriceType == "X") { searchFlightDetailModel.PriceType = "C"; searchFlightDetailModel.SalePrice = searchFlightDetailModel.FacePrice; searchFlightDetailModel.Rate = searchFlightDetailModel.FRate; tempFlightDetailModels.Add(searchFlightDetailModel); } } else //在名单内,不做任何处理 { tempFlightDetailModels.Add(searchFlightDetailModel); } } if (tempFlightDetailModels.Count > 0) { tempFlightModel.DetailList = tempFlightDetailModels; tempFlightModels.Add(tempFlightModel); } } return(tempFlightModels); }