public ActionResult Edit([Bind(Include = "Id,Price,Class, DeparturesInfo.Id")] FlightPrice flightPrice) { if (ModelState.IsValid) { PriceRepo.Update(flightPrice); return(RedirectToAction("Index")); } return(View(flightPrice)); }
public ActionResult Create([Bind(Include = "Id,Price,Class, DeparturesInfo.Id")] FlightPrice flightPrice) { if (ModelState.IsValid) // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. { PriceRepo.Insert(flightPrice); return(RedirectToAction("Index")); } PopulateFlightNumberDropDownList(flightPrice.DeparturesInfo.Id); return(View(flightPrice)); }
private Flight CreateOrUpdateFlightDb(AdministratorFlightDTO flight, Flight flightDb = null) { if (flightDb == null) { flightDb = new Flight(); } else { context.FlightPrices.RemoveRange(flightDb.Prices); context.SaveChanges(); } flightDb.AircraftId = flight.AircraftId; flightDb.ArrivalDateTime = flight.ArrivalDateTime; flightDb.CarrierId = flight.CarrierId; flightDb.DepartureDateTime = flight.DepartureDateTime; flightDb.DestinationAirportId = flight.DestinationAirportId; flightDb.OriginAirportId = flight.OriginAirportId; flightDb.Prices = new List <FlightPrice>(); var currency = context.Currencies.Find(flight.CurrencyId); if (currency != null) { foreach (var price in flight.Prices) { var flightPrice = new FlightPrice { Price = price.Price * (currency.IsDefault ? 1 : currency.ExchangeRate), TravelClass = price.TravelClass, TravelerType = price.TravelerType }; flightDb.Prices.Add(flightPrice); } } return(flightDb); }