public async Task <string> UpdateAirport(Logic.Airport airport) { Airport e_airport = await dbcontext.Airport.FindAsync(airport.Name); if (e_airport == null) { //logger.Warn("airport not Found") return("no such airport"); } if (airport.Name != null) { e_airport.Name = airport.Name; } if (airport.Location != null) { e_airport.Location = airport.Location; } if (airport.Weather != null) { e_airport.Weather = airport.Weather; } await dbcontext.SaveChangesAsync(); //logger.Info(); return("update success"); }
public async Task <IActionResult> Delete(string name) { Logic.Airport air = new Logic.Airport(); air.Name = name; await iRepo.DeleteAirport(air); return(Ok()); }
public async Task <string> CreateAirport(Logic.Airport airport) { Airport e_airport = Mapper.MapAirportToE(airport); dbcontext.Add(e_airport); await dbcontext.SaveChangesAsync(); //logger.info(); return("New Flight Created!"); }
public async Task <ActionResult> Post([FromBody, Bind("Name, Location, Weather")] API.Models.APIAirport airport) { Logic.Airport air = new Logic.Airport { Name = airport.Name, Location = airport.Location, Weather = airport.Weather }; await iRepo.CreateAirport(air); return(CreatedAtRoute("GetAirport", new { name = air.Name }, air)); }
public void MapEToAirportTest() { d.Airport airport1 = new d.Airport { Name = "DAL", Location = "Dallas", Weather = "Sunny" }; l.Airport airport2 = d.Mapper.MapEToAirport(airport1); Assert.Equal(airport1.Name, airport2.Name); Assert.Equal(airport1.Location, airport2.Location); Assert.Equal(airport1.Weather, airport2.Weather); }
public async Task <string> DeleteAirport(Logic.Airport airport) { Airport e_Airport = await dbcontext.Airport.FindAsync(airport.Name); if (e_Airport == null) { //logger.Warn("Airport not found.") return("no such customer"); } dbcontext.Remove(dbcontext.Airport.Find(airport.Name)); await dbcontext.SaveChangesAsync(); //logger.info(); return("delete success"); }
public async Task <IActionResult> Put([FromBody] API.Models.APIAirport airport) { Logic.Airport air = new Logic.Airport(); air.Name = airport.Name; IEnumerable <Logic.Airport> Lairports = await iRepo.ReadAirportList(air); //Need exception handling here, maybe implement in repo? Logic.Airport newAir = new Logic.Airport { Name = airport.Name, Location = airport.Location, Weather = airport.Weather }; await iRepo.UpdateAirport(newAir); return(Ok()); }
public async Task <IEnumerable <API.Models.APIAirport> > GetByName(string name) { string find = await iRepo.GetAirPortName(name); if (find == null) { Logic.Airport LAir = new Logic.Airport(); LAir.Name = name; IEnumerable <Logic.Airport> airports = await iRepo.ReadAirportList(null); IEnumerable <API.Models.APIAirport> apiAirport = airports.Select(a => new API.Models.APIAirport { //APIModel = Logic Name = a.Name, Location = a.Location, Weather = a.Weather }); return(apiAirport); } else { Logic.Airport LAir = new Logic.Airport(); LAir.Name = name; IEnumerable <Logic.Airport> airports = await iRepo.ReadAirportList(LAir); IEnumerable <API.Models.APIAirport> apiAirport = airports.Select(a => new API.Models.APIAirport { //APIModel = Logic Name = a.Name, Location = a.Location, Weather = a.Weather }); return(apiAirport); } }
public async Task <List <Logic.Airport> > ReadAirportList(Logic.Airport airport) { if (airport == null) { List <Airport> airportFind = await dbcontext.Airport.ToListAsync(); return(airportFind.Select(Mapper.MapEToAirport).ToList()); } IQueryable <Airport> e_airport = dbcontext.Airport.Select(a => a); if (airport.Name != null) { e_airport = e_airport.Where(a => a.Name == airport.Name) .AsNoTracking(); } if (airport.Location != null) { e_airport = e_airport.Where(f => f.Location == airport.Location) .AsNoTracking(); } if (airport.Weather != null) { e_airport = e_airport.Where(f => f.Weather == airport.Weather) .AsNoTracking(); } List <Airport> airportFind2 = await e_airport.ToListAsync(); List <Logic.Airport> resultAirport = airportFind2.Select(Mapper.MapEToAirport).ToList(); if (resultAirport.Count < 1) { //logger.Warn(); return(null); } return(resultAirport); }