public async Task <IActionResult> SavePilot(VatsimClientPilotV1BindingTarget target)
        {
            VatsimClientPilotV1 pilot = target.ToVatsimClientPilotV1();
            await db.Pilots.AddAsync(pilot);

            await db.SaveChangesAsync();

            return(Ok(pilot));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(string cid, string callsign, string timelogon)
        {
            Pilot = await db.Pilots.FindAsync(cid, callsign, timelogon);

            if (Pilot == null)
            {
                return(RedirectToPage("NotFound"));
            }
            return(Page());
        }
        public VatsimClientPilotV1 GetVatsimClientPilotFromRecord()
        {
            VatsimClientPilotV1 pilot = new VatsimClientPilotV1();

            pilot.Callsign             = this.Callsign;
            pilot.Cid                  = this.Cid;
            pilot.Clienttype           = this.Clienttype;
            pilot.Latitude             = this.Latitude;
            pilot.Longitude            = this.Longitude;
            pilot.Realname             = this.Realname;
            pilot.Protrevision         = this.Protrevision;
            pilot.Server               = this.Server;
            pilot.TimeLastAtisReceived = this.TimeLastAtisReceived;
            pilot.TimeLogon            = this.TimeLogon;

            return(pilot);
        }
        public async Task <IActionResult> GetPilot(string cid, string callsign, string timelogon)
        {
            VatsimClientPilotV1 pilot = await db.Pilots.FindAsync(cid, callsign, timelogon);

            if (pilot == null)
            {
                return(NotFound());
            }
            // this is a projection as it is a subset of pilot properties
            return(Ok(new {
                Cid = pilot.Cid,
                Realname = pilot.Realname,
                Callsign = pilot.Callsign,
                Latitude = pilot.Latitude,
                Longitude = pilot.Longitude,
                TimeLogon = pilot.TimeLogon,
            }));
        }
Exemplo n.º 5
0
        public static void MapWebService(this IEndpointRouteBuilder app)
        {
            app.MapGet($"{BASEURL}/{{cid}}", async context => {
                long key                  = long.Parse(context.Request.RouteValues["cid"] as string);
                VatsimDbContext db        = context.RequestServices.GetService <VatsimDbContext>();
                VatsimClientPilotV1 pilot = db.Pilots.Find(key);
                if (pilot == null)
                {
                    context.Response.StatusCode = StatusCodes.Status404NotFound;
                }
                else
                {
                    context.Response.ContentType = "application/json";
                    await context.Response
                    .WriteAsync(JsonSerializer.Serialize <VatsimClientPilotV1>(pilot));
                }
            });

            /* honestly, we could stop here because we are getting data from the database, returned as JSON
             * through this endpoint.  The MVC stuff is to demonstrate how the REST Web API handles this stuff
             * "built in"
             */
            app.MapGet(BASEURL, async context => {
                VatsimDbContext data         = context.RequestServices.GetService <VatsimDbContext>();
                context.Response.ContentType = "application/json";
                await context.Response.WriteAsync(JsonSerializer
                                                  .Serialize <IEnumerable <VatsimClientPilotV1> >(data.Pilots));
            });

            // skipping write operations
            // app.MapPost(BASEURL, async context => {
            //     DataContext data = context.RequestServices.GetService<DataContext>();
            //     Product p = await
            //         JsonSerializer.DeserializeAsync<Product>(context.Request.Body);
            //     await data.AddAsync(p);
            //     await data.SaveChangesAsync();
            //     context.Response.StatusCode = StatusCodes.Status200OK;
            // });
        }
Exemplo n.º 6
0
        public static async void UpdateOrCreatePilotAsync(VatsimClientPilotV1 pilot)
        {
            using (var db = new VatsimDbContext())
            {
                var _pilot = await FindPilotAsync(pilot.Cid, pilot.Callsign, pilot.TimeLogon);

                // didn't find the pilot
                if (_pilot == null)
                {
                    await db.AddAsync(pilot);

                    await db.SaveChangesAsync();

                    Log.Information($"Added Pilot: {pilot} to DB");
                }
                else
                {
                    // DateTime old_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(_pilot.TimeLogon);
                    // DateTime new_time = VatsimDataState.GetDateTimeFromVatsimTimeStamp(pilot.TimeLogon);
                    if (LogonTimeIsMoreRecent(_pilot.TimeLogon, pilot.TimeLogon))
                    {
                        await db.AddAsync(pilot);

                        await db.SaveChangesAsync();

                        Log.Information($"Added Pilot: {pilot} to DB");
                    }
                    else
                    {
                        _pilot.Update(pilot);
                        db.Update(_pilot);
                        await db.SaveChangesAsync();

                        Log.Information($"Updated Pilot: {pilot} in DB");
                    }
                }
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Index(string cid = "1")
        {
            VatsimClientPilotV1 pilot = await db.Pilots.FindAsync(cid);

            return(View(pilot));
        }
 public async Task UpdateVatsimClientPilotV1(VatsimClientPilotV1 pilot)
 {
     db.Update(pilot);
     await db.SaveChangesAsync();
 }