コード例 #1
0
        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");
        }
コード例 #2
0
        public async Task <IActionResult> Delete(string name)
        {
            Logic.Airport air = new Logic.Airport();
            air.Name = name;

            await iRepo.DeleteAirport(air);

            return(Ok());
        }
コード例 #3
0
        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!");
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
        }