private bool ValidateModel(Aeroplane aeroplane, bool isPost) { if (aeroplane.numSeats < 1) { return(false); } // na googlu pise da najveci putnicki avio prima max 525 putnika (Airbus A380-800) if (aeroplane.numSeats > 525) { return(false); } // TO DO: // Proveri da li vec postoji naziv aviona u bazi, // ako npr. postoji Boing 747, baci false! // prilikom POST i PUT ne moze se logicki obrisati jer to je namenjeno za DELETE! if (aeroplane.deleted == true) { return(false); } return(true); }
public async Task <IActionResult> UpdatePlane(Aeroplane aeroplane) { var retAeroplane = await planeRepo.UpdatePlane(_context, aeroplane); if (retAeroplane == null) { return(NotFound()); } //_context.Entry(aeroplane).State = EntityState.Modified; //try //{ // await _context.SaveChangesAsync(); //} //catch (DbUpdateConcurrencyException) //{ // if (!PlaneExists(aeroplane.id)) // { // return NotFound(); // } // else // { // throw; // } //} return(Ok()); }
public async Task <ActionResult <Aeroplane> > AddPlane(Aeroplane aeroplane) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (ValidateModel(aeroplane, true)) { var plane = await planeRepo.AddPlane(_context, aeroplane); if (plane == null) { return(BadRequest()); } return(CreatedAtAction("GetAeroplane", new { id = aeroplane.id }, aeroplane)); //_context.Aeroplanes.Add(aeroplane); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetAeroplane", new { id = aeroplane.id }, aeroplane); } else { return(BadRequest()); } }
public async Task <Aeroplane> AddAeroplaneAsycn( [FromBody] Aeroplane aeroplane, CancellationToken ct ) { return(await _aeroplaneServices.CreateAsync(aeroplane, ct)); }
// Use this for initialization public void InitialisePlane(BezierCurve _trajectory) { plane = gameObject.GetComponent <Aeroplane>(); //indexNum = plane.indexNum; trajectory = _trajectory; }
public async Task <Aeroplane> UpdateAeroplaneAsync( int id, [FromBody] Aeroplane aeroplane, CancellationToken ct ) { return(await _aeroplaneServices.UpdateAsync(aeroplane, ct)); }
static void Main(string[] args) { var x = new Aeroplane(); var flyService = new FlyService(); flyService.Fly(x); Console.WriteLine("Hello World!"); }
void SpawnPlane() { Aeroplane planeComponent = Instantiate(planePrefab) as Aeroplane; planeComponent.SetIndexNum(indexNum); planeComponent.GetComponent <PlaneMovement> ().InitialisePlane(getTrajectory(indexNum)); planes.Add(planeComponent); SendToConsole(planes[indexNum]); //radarScreen.SpawnPlaneOnScreen (/*planeComponent*/); indexNum++; }
public void GetConsumptionTest() { Aeroplane aeroplane = _mockAeroplanesCollection.GetCollection().Entities.First(); Flight flight = _mockFlightCollection.GetCollection().Entities.First(); var distance = flight.GetFlightDistance(); var consumption = aeroplane.GetPlaneConsumption(distance); Assert.IsTrue(distance == 4115.29); Assert.IsTrue(consumption == 4098828.84); }
public bool IsPlaneInTrigger(Aeroplane plane) { for (int i = 0; i < planes.Count; i++) { if (planes [i] == plane) { return(true); } } return(false); }
public void AddAeroplaneTest() { var aeroplane = new Aeroplane { Id = 6, Name = "Boeing 787", Capacity = 243, TakeoffEffortPerOccupiedSeat = 5.38, FuelConsumptionPerSeat = 2.77 }; _mockAeroplaneCollection.GetCollection().Entities.Add(aeroplane); Assert.IsTrue( _mockAeroplaneCollection.GetCollection().Entities.Contains(aeroplane) && _mockAeroplaneCollection.GetCollection().Entities.Count == 6 ); }
public async Task <List <int> > GetTakenSeats(Flight f, Aeroplane a) { var reservations = await _repository.GetFlightReservationsByFlightId(f.FlightId); List <int> takenSeats = new List <int>(); if (reservations != null) { foreach (FlightReservation fr in reservations) { takenSeats.Add(fr.SeatNumber); } } return(takenSeats); }
/// <summary> /// Второе задание. Поиск по номеру рейса /// </summary> private void SearchByFlightNumberButton_OnClick(object sender, RoutedEventArgs e) { try { ListBox.Items.Clear(); Aeroplane aeroplane = airport.GetAeroplane(Convert.ToInt32(FlightNumberTextBox.Text)); string text = aeroplane.ToString(); MessageBox.Show(text); } catch (FormatException) { MessageBox.Show("Введите значение еще раз"); } catch (NullReferenceException) { MessageBox.Show("В данный момент данные рейсы отсутствуют"); } }
public void ShouldMapToANewOneToManyViaIntermediateRelationship() { using (var mapper = Mapper.CreateNew()) { mapper.WhenMapping.TrackMappedObjects(); var pilot = new Pilot { Name = "Walls", Qualifications = new PilotQualifications { TrainedAeroplanes = new List <Aeroplane>() } }; var concorde = new Aeroplane { Model = "Concorde", Pilot = pilot }; var f16 = new Aeroplane { Model = "F16", Pilot = pilot }; pilot.Qualifications.TrainedAeroplanes.Add(concorde); pilot.Qualifications.TrainedAeroplanes.Add(f16); var clonedPilot = mapper.Clone(pilot); clonedPilot.ShouldNotBeSameAs(pilot); clonedPilot.Name.ShouldBe("Walls"); clonedPilot.Qualifications.ShouldNotBeNull(); clonedPilot.Qualifications.ShouldNotBeSameAs(pilot.Qualifications); clonedPilot.Qualifications.TrainedAeroplanes.ShouldNotBeNull(); clonedPilot.Qualifications.TrainedAeroplanes.Count.ShouldBe(2); clonedPilot.Qualifications.TrainedAeroplanes.First().ShouldNotBeSameAs(concorde); clonedPilot.Qualifications.TrainedAeroplanes.First().Model.ShouldBe("Concorde"); clonedPilot.Qualifications.TrainedAeroplanes.First().Pilot.ShouldBe(clonedPilot); clonedPilot.Qualifications.TrainedAeroplanes.Second().ShouldNotBeSameAs(f16); clonedPilot.Qualifications.TrainedAeroplanes.Second().Model.ShouldBe("F16"); clonedPilot.Qualifications.TrainedAeroplanes.Second().Pilot.ShouldBe(clonedPilot); } }
public async Task <Aeroplane> UpdateAsync(Aeroplane Aeroplane) { var jsonBody = JsonConvert.SerializeObject(Aeroplane); var content = new StringContent(jsonBody, Encoding.UTF8, "application/json"); using (var httpClient = new HttpClient()) { var response = await httpClient.PutAsync(SERVER_NAME + $"/api/Aeroplanes/{Aeroplane.Id}", content).ConfigureAwait(false); if (response.IsSuccessStatusCode) { string contentResponse = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <Aeroplane>(contentResponse)); } } throw new InvalidOperationException("Can`t update items on the server"); }
public async Task <Aeroplane> UpdatePlane(MAANPP20ContextFlight _context, Aeroplane aeroplane) { _context.Entry(aeroplane).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlaneExists(_context, aeroplane.id)) { return(null); } else { throw; } } return(aeroplane); }
public void ShouldMapToANewOneToManyViaIntermediateEntity() { var pilot = new Pilot { Name = "Walls", Qualifications = new PilotQualifications { TrainedAeroplanes = new List <Aeroplane>() } }; var concorde = new Aeroplane { Model = "Concorde", Pilot = pilot }; var f16 = new Aeroplane { Model = "F16", Pilot = pilot }; pilot.Qualifications.TrainedAeroplanes.Add(concorde); pilot.Qualifications.TrainedAeroplanes.Add(f16); var clonedPilot = Mapper.DeepClone(pilot); clonedPilot.ShouldNotBeSameAs(pilot); clonedPilot.Name.ShouldBe("Walls"); clonedPilot.Qualifications.ShouldNotBeNull(); clonedPilot.Qualifications.ShouldNotBeSameAs(pilot.Qualifications); clonedPilot.Qualifications.TrainedAeroplanes.ShouldNotBeNull(); clonedPilot.Qualifications.TrainedAeroplanes.Count.ShouldBe(2); clonedPilot.Qualifications.TrainedAeroplanes.First().ShouldNotBeSameAs(concorde); clonedPilot.Qualifications.TrainedAeroplanes.First().Model.ShouldBe("Concorde"); clonedPilot.Qualifications.TrainedAeroplanes.First().Pilot.ShouldBe(clonedPilot); clonedPilot.Qualifications.TrainedAeroplanes.Second().ShouldNotBeSameAs(f16); clonedPilot.Qualifications.TrainedAeroplanes.Second().Model.ShouldBe("F16"); clonedPilot.Qualifications.TrainedAeroplanes.Second().Pilot.ShouldBe(clonedPilot); }
public void setPlane(Aeroplane pln) { plane = pln; }
public void SpawnPlaneOnScreen(Aeroplane plane) { Instantiate(littlePlane, new Vector3(0.14f, 0.72f, -0.4f), Quaternion.identity); littlePlane.setPlane(plane); }
public async Task <Aeroplane> Post([FromBody] Aeroplane aeroplane) { var posted = await aeroplaneService.WriteAsync(aeroplane); return(posted); }
public async Task <Aeroplane> Put(Aeroplane aeroplane) { var posted = await aeroplaneService.WriteAsync(aeroplane); return(posted); }
public async Task AddAeroplane(Aeroplane a) { _context.Aeroplanes.Add(a); await _context.SaveChangesAsync(); }
public async Task RemoveAeroplane(Aeroplane a) { _context.Aeroplanes.Remove(a); await _context.SaveChangesAsync(); }
public async Task <ActionResult <Aeroplane> > AddPlane(MAANPP20ContextFlight _context, Aeroplane aeroplane) { _context.Aeroplanes.Add(aeroplane); await _context.SaveChangesAsync(); return(aeroplane); }
private static bool CapacityIsValid(this Aeroplane entity) { return(entity.Capacity > 0); }
public static bool IsValid(this Aeroplane entity) { return(entity.NameIsNotNull() && entity.CapacityIsValid() && entity.CunsumpltionIsValid()); }
private static bool CunsumpltionIsValid(this Aeroplane entity) { return(entity.FuelConsumptionPerSeat > 0 && entity.TakeoffEffortPerOccupiedSeat > 0); }
public async Task <IActionResult> CreateAvioCompany([FromBody] AvioCompanyDTO avioCompanyDTO) { if (ModelState.IsValid) { if (await AvioService.CompanyExists(avioCompanyDTO.Name)) { return(BadRequest("Company already exists with the same name.")); } var profile = new AvioCompanyProfile() { Name = avioCompanyDTO.Name, Address = avioCompanyDTO.Address, PromoDescription = avioCompanyDTO.Description }; // add destinations var dest = new List <Destination>(); string[,] destinations = { { "Belgrade", "44.786568", "20.448921" }, { "Tokyo", "35.689487", "139.691711" }, { "New York", "40.712776", "-74.005974" }, { "Berlin", "52.520008", "13.404954" }, { "Rome", "41.9028", "12.4964" }, { "Zurich", "47.3768880", "8.541694" } }; for (int j = 0; j < destinations.GetLength(0); ++j) { Destination destination = new Destination() { Name = destinations[j, 0], Latitude = double.Parse(destinations[j, 1], CultureInfo.InvariantCulture), Longitude = double.Parse(destinations[j, 2], CultureInfo.InvariantCulture), }; dest.Add(destination); } AvioCompany company = new AvioCompany() { Destinations = dest }; await AvioService.CreateCompany(company, profile); // create planes for companies var aeroplaneA380 = new Aeroplane() { AvioCompanyId = company.AvioCompanyId, Name = "Airbus A380" }; var aeroplane737 = new Aeroplane() { AvioCompanyId = company.AvioCompanyId, Name = "Boeing 737" }; if (!await AeroplaneService.AeroplaneExists(company.AvioCompanyId, aeroplaneA380.Name)) { await AeroplaneService.AddAeroplane(aeroplaneA380); } if (!await AeroplaneService.AeroplaneExists(company.AvioCompanyId, aeroplane737.Name)) { await AeroplaneService.AddAeroplane(aeroplane737); } // create seats for planes var seatsA380 = new Seats() { AeroplaneId = aeroplaneA380.AeroplaneId, SeatCount = 240, InOneRow = 6 }; var seats737 = new Seats() { AeroplaneId = aeroplane737.AeroplaneId, SeatCount = 320, InOneRow = 8 }; if (!await SeatService.SeatsExist(aeroplaneA380.AeroplaneId)) { await SeatService.AddSeats(seatsA380); } if (!await SeatService.SeatsExist(aeroplane737.AeroplaneId)) { await SeatService.AddSeats(seats737); } return(Ok(200)); } return(BadRequest("No sufficient data provided.")); }
private static bool NameIsNotNull(this Aeroplane entity) { return(!String.IsNullOrEmpty(entity.Name)); }
public void SendToConsole(Aeroplane _plane) { //variable in console: public Aeroplane }