コード例 #1
0
ファイル: TabletController.cs プロジェクト: ElrHolis/hitchBOT
        public async Task<IHttpActionResult> LogTabletStatus([FromBody] ReturnTabletStatus context)
        {
            if (!ModelState.IsValid)
                return BadRequest("Model sent was not valid.");

            using (var db = new Dal.DatabaseContext())
            {
                if (!db.TabletSerials.Where(l => l.TabletSerialNumber == context.TabletSerial)
                        .Any(l => l.HitchBotId == context.HitchBotId))
                {
                    return BadRequest("Tablet Serial Number is not registered to this hitchBOT OR Tablet Serial is invalid.");
                }
                db.TabletStatuses.Add(new TabletStatus(context)
                {
                    BatteryPercentage = context.BatteryPercentage,
                    BatteryTemp = context.BatteryTemp,
                    BatteryVoltage = context.BatteryVoltage,
                    IsCharging = context.IsCharging
                });

                await db.SaveChangesAsync();
            }

            return Ok();
        }
コード例 #2
0
        public async Task<IHttpActionResult> LogLocation([FromBody] ReturnLocation Context)
        {
            if (!ModelState.IsValid)
                return BadRequest("Model sent was not valid.");

            using (var db = new Dal.DatabaseContext())
            {
                if (!db.TabletSerials.Where(l => l.TabletSerialNumber == Context.TabletSerial)
                        .Any(l => l.HitchBotId == Context.HitchBotId))
                {
                    return BadRequest("Tablet Serial Number is not registered to this hitchBOT OR Tablet Serial is invalid.");
                }
                db.Locations.Add(
                    new Models.Location(Context)
                {
                    Latitude = Context.Latitude,
                    Longitude = Context.Longitude,
                    Altitude = Context.Altitude,
                    Accuracy = Context.Accuracy,
                    Velocity = Context.Velocity,
                    LocationProvider = Context._LocationProvider
                });

                await db.SaveChangesAsync();
            }
            return Ok();
        }