public ActionResult AddFlight(FlightModel add) { if (ModelState.IsValid) //condition pass when all the model state validation is true { add.TotalSeat = 0; Flight flight = AutoMapper.Mapper.Map <FlightModel, Flight>(add); //Auto Mapper model to entity flightBL.AddFlight(flight); TempData["message"] = "Flight added successfully"; TempData["FlightId"] = flight.FlightId; return(RedirectToAction("CreateClass", "FlightTravelClasses")); } return(View()); //Calling View for the AddFlight (when the ModelState is in valid) }
public ActionResult AddFlight(FlightViewModel flightViewModel) { if (ModelState.IsValid) { var mapAccount = new MapperConfiguration(cfg => { cfg.CreateMap <FlightViewModel, Flight>(); }); IMapper mapper = mapAccount.CreateMapper(); var flight = mapper.Map <FlightViewModel, Flight>(flightViewModel); int flightId = flightBLayer.AddFlight(flight); TempData["FlightId"] = flightId; return(RedirectToAction("AddFlightClassDetail", "FlightClassDetail")); } else { ModelState.AddModelError("", "Invalid Values"); } return(View()); }