public async Task <IActionResult> Create(FlightCreateViewModel model) { if (ModelState.IsValid) { Flight flight = new Flight { Id = Guid.NewGuid().ToString(), LocationFrom = model.LocationFrom, LocationTo = model.LocationTo, FlightTakeOff = model.FlightTakeOff, FlightLanding = model.FlightLanding, PlaneModel = model.PlaneModel, PlaneId = model.PlaneId, PilotName = model.PilotName, CapacityNormal = model.CapacityNormal, CapacityBuisness = model.CapacityBuisness }; var checkFlight = _context.Flights.FirstOrDefault(f => f.PlaneId == flight.PlaneId); if (checkFlight != null) { ViewBag.Message = $"Plane id {flight.PlaneId} already exists"; return(View(model)); } _context.Add(flight); await _context.SaveChangesAsync(); return(Redirect("/Identity/FlightList")); } return(View(model)); }
public async Task <IActionResult> Create(ReservationCreateViewModel model) { if (ModelState.IsValid) { Reservation _reservation = new Reservation { Id = Guid.NewGuid().ToString(), Name = model.Name, MiddleName = model.MiddleName, Surname = model.Surname, PersonalId = model.PersonalId, Telephone = model.Telephone, Nationality = model.Nationality, FlightTypeId = _context.FlightTypes.FirstOrDefault(f => f.Type == model.TypeName).Id, PlaneId = model.PlaneId }; var CapacityBuisness = _context.Flights.FirstOrDefault(f => f.Id == model.PlaneId).CapacityBuisness; var CapacityNormal = _context.Flights.FirstOrDefault(f => f.Id == model.PlaneId).CapacityNormal; if (model.TypeName == "Buisness Class") { if (--CapacityBuisness < 0) { ViewBag.Message = $"No more seats left in the Buisness Class"; return(View(model)); } _context.Flights.FirstOrDefault(f => f.Id == model.PlaneId).CapacityBuisness--; await _context.SaveChangesAsync(); } else { if (--CapacityNormal < 0) { ViewBag.Message = $"No more seats left in the Economy Class"; return(View(model)); } _context.Flights.FirstOrDefault(f => f.Id == model.PlaneId).CapacityNormal--; await _context.SaveChangesAsync(); } _context.Add(_reservation); await _context.SaveChangesAsync(); return(Redirect("/")); } return(View(model)); }
public IActionResult SignUp(CheckCustomer customer) { if (!ModelState.IsValid) { return(View()); } var _customer = new Customer { email = customer.Email, name = customer.Name, password = customer.Password }; _context.Add(_customer); _context.SaveChanges(); return(View("~/Views/Login/Login.cshtml")); }
public void Create(Flight flight) { _flightDbContext.Add(flight); }