Exemple #1
0
        public async void recordTrack()
        {
            string query    = "SELECT * FROM Vehicles";
            var    vehicles = SqlDataAccess.LoadData <VehicleModel>(query);
            int    count    = 0;
            Random rand     = new Random();

            while (true)
            {
                Debug.WriteLine($@"Record Track {count} Start: {DateTime.Now}");
                for (int i = 0; i < vehicles.Count; i++)
                {
                    var    vehicle = vehicles[i];
                    double la      = 13.706555 + rand.NextDouble();
                    double lo      = 100.597545 + rand.NextDouble();
                    var    track   = new RegisterTrackViewModel()
                    {
                        VehicleSeqID = vehicle.VehicleSeqID,
                        Latitude     = Math.Round(la, 6),
                        Longitude    = Math.Round(lo, 6)
                    };

                    _ = await TrackProcessor.RegisterTrackAsync(track);
                }
                Debug.WriteLine($@"Record Track {count} End: {DateTime.Now}");
                await Task.Delay(30000);

                count++;
            }
        }
Exemple #2
0
        public async Task <ActionResult> RegisterTrackAsync([FromForm] RegisterTrackViewModel value)
        {
            // current user allows to add tracking record.
            // doens't allows to add tracking record for other vehicle.
            string userId        = User.Claims.First().Value;
            bool   IsUserVehicle = TrackProcessor.IsUserVehicle(userId, value.VehicleSeqID);

            if (User.IsInRole("Admin") || IsUserVehicle)
            {
                _ = await TrackProcessor.RegisterTrackAsync(value);
            }
            else
            {
                return(BadRequest("Logined user is not Admin or vehicle user."));
            }

            return(Ok("Track data has been registed"));
        }