public PromoCodeRule GetPromoCodeDiscountRule(SearchFlightResultViewModel searchInfo, MayFlower dbCtx = null) { dbCtx = dbCtx ?? new MayFlower(); var result = dbCtx.PromoCodeRules .Where( x => x.IsActive && DateTime.Now >= x.EffectiveFrom && DateTime.Now <= x.EffectiveTo && searchInfo.EndDate >= x.TravelDateFrom && searchInfo.BeginDate <= x.TravelDateTo && x.PromoCode == searchInfo.PromoCode && x.FlightPromo // Suggest use another table to indicate product rather than use column ); //Any Airport = "-" Expression <Func <PromoCodeRule, bool> > anyOrigin = (x => x.PromoFlightDestinations.Any(d => d.DepartureStation == "-" && d.ArrivalStation == searchInfo.ArrivalStation)); Expression <Func <PromoCodeRule, bool> > anyDestination = (x => x.PromoFlightDestinations.Any(d => d.ArrivalStation == "-" && d.DepartureStation == searchInfo.DepartureStation)); Expression <Func <PromoCodeRule, bool> > anyDesAndOri = (x => x.PromoFlightDestinations.Any(d => d.ArrivalStation == "-" && d.DepartureStation == "-")); bool anyOriginOK = result.Any(anyOrigin); bool anyDestinationOK = result.Any(anyDestination); bool anyDesOriOK = result.Any(anyDesAndOri); if (anyDesOriOK) { return(result.FirstOrDefault(anyDesAndOri)); } if (anyOriginOK) { return(result.FirstOrDefault(anyOrigin)); } else if (anyDestinationOK) { return(result.FirstOrDefault(anyDestination)); } else { return(result.FirstOrDefault(x => x.PromoFlightDestinations .Any(d => d.DepartureStation == searchInfo.DepartureStation && d.ArrivalStation == searchInfo.ArrivalStation))); } }
public async Task <IActionResult> SearchFlight(SearchFlightViewModel model) { if (!model.RoundTrip) { ModelState.Remove("ReturnDate"); } if (ModelState.IsValid) { var departFlight = from f in _context.Flights where f.Origin == model.Origin && (f.Destination == model.Destination) && (f.DepartureDateTime.Date == model.DepartureDate) select f; SearchFlightResultViewModel result = new SearchFlightResultViewModel { Passenger = model.Passenger, Depart = await departFlight.ToListAsync(), Origin = model.Origin, Destination = model.Destination, RoundTrip = model.RoundTrip, DepartDate = model.DepartureDate, }; if (model.RoundTrip) { var returnFlight = from f in _context.Flights where f.Origin == model.Destination && (f.Destination == model.Origin) && (f.DepartureDateTime.Date == model.ReturnDate) select f; result.Return = await returnFlight.ToListAsync(); result.ReturnDate = model.ReturnDate; } return(View(nameof(SearchFlightResult), result)); } //has error fallback return(View(model)); }
private CheckoutProduct GenerateTestProduct() { SearchFlightResultViewModel searchModel = new SearchFlightResultViewModel { ArrivalStation = "PEN", BeginDate = new DateTime(2018, 2, 2), DepartureStation = "KUL", CabinClass = "Y", DepartureTime = "00002359", DirectFlight = false, EndDate = new DateTime(2018, 2, 10), PrefferedAirlineCode = string.Empty, ReturnTime = "00002359", TripType = "Return", Adults = 1, Childrens = 1, Infants = 0 }; var contactPerson = new ContactPerson { Address1 = "asd", Address2 = "fgh", Address3 = "jkl", City = "rgrrgeg", CountryCode = "123123", Email = "*****@*****.**", GivenName = "werwe", Phone1 = "12573725", Phone1LocationCode = "08", Phone1Prefix = "0808", Phone1PrefixNo = "321", Phone1UseType = "cell", Phone2 = "312131", Phone2LocationCode = "321654", Phone2Prefix = "654", Phone2PrefixNo = "564", Phone2UseType = "phone", PostalCode = "56465", State = "asddd", Surname = "asdsad", Title = "Mr", DOB = new DateTime(1999, 08, 01), }; CheckoutProduct product = new CheckoutProduct { ContactPerson = contactPerson, }; product.InsertProduct(new ProductFlight { SearchFlightInfo = searchModel, ContactPerson = contactPerson, TravellerDetails = new List <TravellerDetail> { new TravellerDetail { Address1 = "asd", Address2 = "fgh", Address3 = "jkl", City = "rgrrgeg", CountryCode = "123123", Email = "*****@*****.**", GivenName = "werwe", Phone1 = "12573725", Phone1LocationCode = "08", Phone1Prefix = "0808", Phone1PrefixNo = "321", Phone1UseType = "cell", Phone2 = "312131", Phone2LocationCode = "321654", Phone2Prefix = "654", Phone2PrefixNo = "564", Phone2UseType = "phone", PostalCode = "56465", State = "asddd", Surname = "asdsad", Title = "Mr", DOB = new DateTime(1999, 08, 01), } } }); return(product); }
public IActionResult SearchFlightResult(SearchFlightResultViewModel result) { return(View(result)); }
public void AddFlightSearchCookie(SearchFlightResultViewModel model) { List <UserSearchFHCookiesModel> _userCookies = new List <UserSearchFHCookiesModel>(); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); string trackingUserSearchCookiesList; string encryptedCookies; if (Request.Cookies["SaveUserCookies"] != null) { encryptedCookies = Request.Cookies["SaveUserCookies"].Value; trackingUserSearchCookiesList = Cryptography.AES.Decrypt(encryptedCookies); _userCookies = jsSerializer.Deserialize <List <UserSearchFHCookiesModel> >(trackingUserSearchCookiesList).ToList(); } UserSearchFHCookiesModel addUserSearchFlightCookies = new UserSearchFHCookiesModel() { From = model.DepartureStation, Destination = model.ArrivalStation, ArrivalDate = model.BeginDate, DepartureDate = model.EndDate, AdultNo = model.Adults, ChildrenNo = model.Childrens, InfantNo = model.Infants, PrefferedAirlineCode = model.PrefferedAirlineCode, RoomNo = model.NoOfRoom, TripType = model.TripType, CabinClass = model.CabinClass, ProductType = "flight" }; UserSearchFHCookiesModel checkUserSearchFlightCookies = new UserSearchFHCookiesModel(); bool sameWithLast = false; if (_userCookies != null) { checkUserSearchFlightCookies = _userCookies.LastOrDefault(x => x.ProductType == "flight"); if (checkUserSearchFlightCookies != null) { if (checkUserSearchFlightCookies.Destination == addUserSearchFlightCookies.Destination && checkUserSearchFlightCookies.From == addUserSearchFlightCookies.From && ((checkUserSearchFlightCookies.DepartureDate.HasValue && addUserSearchFlightCookies.DepartureDate.HasValue && checkUserSearchFlightCookies.DepartureDate.Value.ToLocalTime() == addUserSearchFlightCookies.DepartureDate.Value) || (!checkUserSearchFlightCookies.DepartureDate.HasValue && !addUserSearchFlightCookies.DepartureDate.HasValue)) && ((checkUserSearchFlightCookies.ArrivalDate.HasValue && addUserSearchFlightCookies.ArrivalDate.HasValue && checkUserSearchFlightCookies.ArrivalDate.Value.ToLocalTime() == addUserSearchFlightCookies.ArrivalDate.Value) || (!checkUserSearchFlightCookies.ArrivalDate.HasValue && !addUserSearchFlightCookies.ArrivalDate.HasValue)) && checkUserSearchFlightCookies.AdultNo == addUserSearchFlightCookies.AdultNo && checkUserSearchFlightCookies.ChildrenNo == addUserSearchFlightCookies.ChildrenNo && checkUserSearchFlightCookies.InfantNo == addUserSearchFlightCookies.InfantNo && checkUserSearchFlightCookies.ChildrenNo == addUserSearchFlightCookies.ChildrenNo && checkUserSearchFlightCookies.PrefferedAirlineCode == addUserSearchFlightCookies.PrefferedAirlineCode && checkUserSearchFlightCookies.TripType == addUserSearchFlightCookies.TripType && checkUserSearchFlightCookies.CabinClass == addUserSearchFlightCookies.CabinClass) { sameWithLast = true; } } } //if same with last dont add if (!sameWithLast) { _userCookies.Add(addUserSearchFlightCookies); } if (_userCookies.Where(x => x.ProductType == "flight").Count() > 2) { var removeOldCookie = _userCookies.First(x => x.ProductType == "flight"); _userCookies.Remove(removeOldCookie); } string SerializeUserCookies = jsSerializer.Serialize(_userCookies); string encryptSerializeUserCookies = Cryptography.AES.Encrypt(SerializeUserCookies); var UserCookie = new System.Web.HttpCookie("SaveUserCookies", encryptSerializeUserCookies) { Expires = DateTime.Now.AddDays(15) }; HttpContext.Response.Cookies.Add(UserCookie); }
public ActionResult Index(FlightBookingModel model, [Bind(Exclude = "SearchResults")] SearchFlightResultViewModel searchModel) { tripid = Guid.NewGuid().ToString(); sessionNameBooking = Enumeration.SessionName.FlightBooking + tripid; #region 2017/02/28 - Development Region, For Get Result from Dummy Cloned Set bool useDumpResultList = false; bool.TryParse(Core.GetAppSettingValueEnhanced("UseDumpResultList"), out useDumpResultList); if (useDumpResultList) { var dumpModel = GetDumpFlightBookingModel("FlightListResultFullList.txt"); Session[sessionNameBooking] = dumpModel; Session["FullFlightSearchResult"] = dumpModel.FlightSearchResultViewModel.FullFlightSearchResult; Session["FullODOResult"] = JsonConvert.DeserializeObject <FlightBookingModel>(JsonConvert.SerializeObject(dumpModel)); Session.Remove("filterParam"); return(RedirectToAction("FlightSearchResult", "FlightSearch", new { tripid })); } #endregion /*20170210 RECEIVE DATA PASSING FROM MAYFLOWER CMS - START */ if (Request.Form["TripTypeCMS"] != null) { model.SearchFlightResultViewModel = new SearchFlightResultViewModel(); DateTime beginDate = DateTime.ParseExact(Request.Form["BeginDateCMS"].ToString(), "dd-MMM-yyyy h:mm:ss tt", null); DateTime endDate = DateTime.ParseExact(Request.Form["EndDateCMS"].ToString(), "dd-MMM-yyyy h:mm:ss tt", null); model.SearchFlightResultViewModel.TripType = Request.Form["TripTypeCMS"].ToString(); model.SearchFlightResultViewModel.DepartureTime = Request.Form["DepartureTimeCMS"].ToString(); model.SearchFlightResultViewModel.ReturnTime = Request.Form["ReturnTimeCMS"].ToString(); model.SearchFlightResultViewModel.DepartureStation = Request.Form["DepartureStationCMS"]?.ToString().ToUpper(); model.SearchFlightResultViewModel.ArrivalStation = Request.Form["ArrivalStationCMS"]?.ToString().ToUpper(); model.SearchFlightResultViewModel.BeginDate = beginDate; model.SearchFlightResultViewModel.EndDate = endDate; model.SearchFlightResultViewModel.PrefferedAirlineCode = Request.Form["PrefferedAirlineCodeCMS"].ToString(); if (model.SearchFlightResultViewModel.PrefferedAirlineCode == "") { model.SearchFlightResultViewModel.PrefferedAirlineCode = null; } model.SearchFlightResultViewModel.PromoCode = Request.Form["PromoCodeCMS"] == null ? null : Request.Form["PromoCodeCMS"].ToString(); model.SearchFlightResultViewModel.Adults = Convert.ToInt32(Request.Form["AdultsCMS"].ToString()); model.SearchFlightResultViewModel.Childrens = Convert.ToInt32(Request.Form["ChildrensCMS"].ToString()); model.SearchFlightResultViewModel.Infants = Convert.ToInt32(Request.Form["InfantsCMS"].ToString()); model.SearchFlightResultViewModel.CabinClass = Request.Form["CabinClassCMS"].ToString(); model.SearchFlightResultViewModel.DirectFlight = Convert.ToBoolean(Request.Form["DirectFlightCMS"].ToString()); model.SearchFlightResultViewModel.IsDynamic = Convert.ToBoolean(Request.Form["IsDynamic"] != null ? Request.Form["IsDynamic"].ToString() : "false"); model.SearchFlightResultViewModel.NoOfRoom = Convert.ToInt32(Request.Form["DynamicRoomCMS"] != null ? Request.Form["DynamicRoomCMS"].ToString() : "1"); model.SearchFlightResultViewModel.IsFixedPrice = Convert.ToBoolean(Request.Form["IsFixedPrice"] != null ? Request.Form["IsFixedPrice"].ToString() : "false"); model.SearchFlightResultViewModel.MarketingMessage = Request.Form["MarketingMessage"]; } /*20170210 RECEIVE DATA PASSING FROM MAYFLOWER CMS - END */ AddFlightSearchCookie(model.SearchFlightResultViewModel); if (searchModel != null && !string.IsNullOrWhiteSpace(searchModel.DepartureStationCode) && searchModel.BeginDate != null) { model.SearchFlightResultViewModel = searchModel; } else { var stateItem = typeof(SearchFlightResultViewModel).GetProperties(); foreach (var item in stateItem) { if (ModelState[item.Name] != null) { ModelState[item.Name].Errors.Clear(); } } } Session[sessionNameBooking] = model; // 0 represent as guest account int userid = User.Identity.IsAuthenticated ? Convert.ToInt32(User.Identity.Name) : 0; try { if (ModelState.IsValid) { if (model.SearchFlightResultViewModel.IsFixedPrice) { return(RedirectToAction("GetFixedHotelSearch", "Hotel", new { tripid })); } else { // 20161126 - For testing next page list flight START return(RedirectToAction("Search", "Flight", new { tripid })); // 20161126 - For testing next page list flight END } } else { return(View(model)); } } catch (Exception ex) { Logger logger = LogManager.GetCurrentClassLogger(); UtilitiesService.NlogExceptionForBookingFlow(logger, model, ex, userid, "HomeSearchFlightError", DateTime.Now.ToString(), ""); return(RedirectToAction("Index", "Home")); } }