private void TestFlightDestination(FlightDestination destination) { Assert.AreEqual(destination.RegionID, 601906); Assert.AreEqual(destination.LongName, "Long Name"); Assert.AreEqual(destination.Country, "ABC"); Assert.AreEqual(destination.City, "city"); Assert.AreEqual(destination.TLA, "TLA"); Assert.AreEqual(destination.MetroCode, "SDQ"); }
private bool ValidateModel(FlightDestination flightDestination) { // u realnoj situaciji mozda bi moglo da se potrefi da postoje u istoj drzavi 2 grada pod istim imenom i na istoj adresi, // ali u nasem sistemu to ne moze da se desi if (flightDestination.startAddress.streetAndNumber == null || flightDestination.endAddress.streetAndNumber == null) { return(false); } if (flightDestination.startAddress.streetAndNumber == flightDestination.endAddress.streetAndNumber) { return(false); } if (flightDestination.startAddress.city == null || flightDestination.endAddress.city == null) { return(false); } if (flightDestination.startAddress.city == flightDestination.endAddress.city) { return(false); } if (flightDestination.startAddress.country == null || flightDestination.endAddress.country == null) { return(false); } // samo necemo proveravati istu drzavu jer moze da se leti iz New York-a za Los Angeles if ((flightDestination.startAddress.city == flightDestination.startAddress.streetAndNumber) || (flightDestination.startAddress.country == flightDestination.startAddress.streetAndNumber)) { return(false); } if ((flightDestination.endAddress.city == flightDestination.endAddress.streetAndNumber) || (flightDestination.endAddress.country == flightDestination.endAddress.streetAndNumber)) { return(false); } // prilikom POST i PUT ne moze se logicki obrisati jer to je namenjeno za DELETE! if (flightDestination.deleted == true) { return(false); } return(true); }
//Конструктор public Flight(int number,Random rand) { Number = number; //случайный тип рейса type = (FlightType)rand.Next(0, 2); //случайный город(в зависимости от типа) if(type==FlightType.Domestic) { destination = (FlightDestination)rand.Next(0,7); } else { destination = (FlightDestination)rand.Next(7, 14); } status=FlightStatus.NoRegistration; }
public async Task <ActionResult <FlightDestination> > AddFlightCompany(FlightDestination flightDestination) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (ValidateModel(flightDestination)) { var flightDestinationRet = await flightDestinationRepo.AddFlightCompany(_context, flightDestination); if (flightDestinationRet == null) { return(BadRequest()); } return(CreatedAtAction("GetFlightDestination", new { id = flightDestination.id }, flightDestination)); // daj mi komapniju //var flightCompany = await _context.FlightCompanies //.Include(address => address.address) //.Include(destinations => destinations.destinations) //.Include(flights => flights.flights) //.Include(ocene => ocene.ocene) //.FirstOrDefaultAsync(i => i.id == flightDestination.CompanyID); // if (flightCompany == null) // { // return BadRequest(); // } // //dodaj mu destinaciju i sacuvaj izmene u kompaniji // flightCompany.destinations.Add(flightDestination); // _context.FlightDestinations.Add(flightDestination); // await _context.SaveChangesAsync(); // return CreatedAtAction("GetFlightDestination", new { id = flightDestination.id }, flightDestination); } else { return(BadRequest()); } }
public async Task <IActionResult> UpdateFlightCompany(FlightDestination flightDestination) { if (ValidateModel(flightDestination)) { var flightDestinationRet = await flightDestinationRepo.UpdateFlightCompany(_context, flightDestination); if (flightDestinationRet == null) { return(NotFound()); } return(Ok()); //_context.Entry(flightDestination).State = EntityState.Modified; //try //{ // await _context.SaveChangesAsync(); //} //catch (DbUpdateConcurrencyException) //{ // if (!FlightDestinationExists(flightDestination.id)) // { // return NotFound(); // } // else // { // throw; // } //} //return Ok(); } else { return(BadRequest()); } }
public async Task <FlightDestination> UpdateFlightCompany(MAANPP20ContextFlight _context, FlightDestination flightDestination) { _context.Entry(flightDestination.startAddress).State = EntityState.Modified; _context.Entry(flightDestination.endAddress).State = EntityState.Modified; _context.Entry(flightDestination).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FlightDestinationExists(_context, flightDestination.id)) { return(null); } else { throw; } } return(flightDestination); }
public async Task <ActionResult <FlightDestination> > AddFlightCompany(MAANPP20ContextFlight _context, FlightDestination flightDestination) { var flightCompany = await _context.FlightCompanies .Include(address => address.address) .Include(destinations => destinations.destinations) .Include(flights => flights.flights) .Include(ocene => ocene.ocene) .FirstOrDefaultAsync(i => i.id == flightDestination.CompanyID); if (flightCompany == null) { return(null); } //dodaj mu destinaciju i sacuvaj izmene u kompaniji flightCompany.destinations.Add(flightDestination); _context.FlightDestinations.Add(flightDestination); await _context.SaveChangesAsync(); return(flightDestination); }