Пример #1
0
        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"));
            }
        }