// GET: Security/VehicleMovement public ActionResult Index(int?page) { var movement = _dbcontext.VehicleMovements .Include(x => x.Department) .Include(x => x.Driver) .Include(x => x.Moto) .Include(x => x.Moto.MottorModel) .ToList().OrderByDescending(X => X.TimeOut).Select(x => VehicleMovementFactory.EntityToViewModel(x)); int pageSize = 3; int pageNumber = (page ?? 1); return(View(movement.ToPagedList(pageNumber, pageSize))); }
private Optional<VehicleMovementData> GetVehicleMovement() { Vehicle vehicle = Player.main.GetVehicle(); SubRoot sub = Player.main.GetCurrentSub(); NitroxId id; Vector3 position; Quaternion rotation; Vector3 velocity; Vector3 angularVelocity; TechType techType; float steeringWheelYaw = 0f, steeringWheelPitch = 0f; bool appliedThrottle = false; Vector3 leftArmPosition = new Vector3(0, 0, 0); Vector3 rightArmPosition = new Vector3(0, 0, 0); if (vehicle != null) { id = NitroxEntity.GetId(vehicle.gameObject); position = vehicle.gameObject.transform.position; rotation = vehicle.gameObject.transform.rotation; techType = CraftData.GetTechType(vehicle.gameObject); Rigidbody rigidbody = vehicle.gameObject.GetComponent<Rigidbody>(); velocity = rigidbody.velocity; angularVelocity = rigidbody.angularVelocity; // Required because vehicle is either a SeaMoth or an Exosuit, both types which can't see the fields either. steeringWheelYaw = (float)vehicle.ReflectionGet<Vehicle, Vehicle>("steeringWheelYaw"); steeringWheelPitch = (float)vehicle.ReflectionGet<Vehicle, Vehicle>("steeringWheelPitch"); // Vehicles (or the SeaMoth at least) do not have special throttle animations. Instead, these animations are always playing because the player can't even see them (unlike the cyclops which has cameras). // So, we need to hack in and try to figure out when thrust needs to be applied. if (vehicle && AvatarInputHandler.main.IsEnabled()) { if (techType == TechType.Seamoth) { bool flag = vehicle.transform.position.y < Ocean.main.GetOceanLevel() && vehicle.transform.position.y < vehicle.worldForces.waterDepth && !vehicle.precursorOutOfWater; appliedThrottle = flag && GameInput.GetMoveDirection().sqrMagnitude > .1f; } else if (techType == TechType.Exosuit) { Exosuit exosuit = vehicle as Exosuit; if (exosuit) { appliedThrottle = (bool)exosuit.ReflectionGet("_jetsActive") && (float)exosuit.ReflectionGet("thrustPower") > 0f; Transform leftAim = (Transform)exosuit.ReflectionGet("aimTargetLeft", true); Transform rightAim = (Transform)exosuit.ReflectionGet("aimTargetRight", true); Vector3 eulerAngles = exosuit.transform.eulerAngles; eulerAngles.x = MainCamera.camera.transform.eulerAngles.x; Quaternion quaternion = Quaternion.Euler(eulerAngles.x, eulerAngles.y, eulerAngles.z); leftArmPosition = leftAim.transform.position = MainCamera.camera.transform.position + quaternion * Vector3.forward * 100f; rightArmPosition = rightAim.transform.position = MainCamera.camera.transform.position + quaternion * Vector3.forward * 100f; } } } } else if (sub != null && Player.main.isPiloting) { id = NitroxEntity.GetId(sub.gameObject); position = sub.gameObject.transform.position; rotation = sub.gameObject.transform.rotation; Rigidbody rigidbody = sub.GetComponent<Rigidbody>(); velocity = rigidbody.velocity; angularVelocity = rigidbody.angularVelocity; techType = TechType.Cyclops; SubControl subControl = sub.GetComponent<SubControl>(); steeringWheelYaw = (float)subControl.ReflectionGet("steeringWheelYaw"); steeringWheelPitch = (float)subControl.ReflectionGet("steeringWheelPitch"); appliedThrottle = subControl.appliedThrottle && (bool)subControl.ReflectionGet("canAccel"); } else { return Optional.Empty; } VehicleMovementData model = VehicleMovementFactory.GetVehicleMovementData(techType, id, position, rotation, velocity, angularVelocity, steeringWheelYaw, steeringWheelPitch, appliedThrottle, leftArmPosition, rightArmPosition); return Optional.Of(model); }
public async Task <ActionResult> Create(VehicleMovementViewModel model) { // define our transaction scope using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { try { var mov = VehicleMovementFactory.ViewModelToEntity(model); var result = _dbcontext.VehicleMovements.Add(mov); var i = await _dbcontext.SaveChangesAsync(); if (i.Equals(1)) { var motto = _dbcontext.Mottors.SingleOrDefault(x => x.Id.Equals(mov.MotoId)); if (motto == null) { Danger("Something is wrong Internally, visit the admin"); return(View("Create")); } motto.IsAvailable = false; await _dbcontext.SaveChangesAsync(); //var savedMoveent = _dbcontext.VehicleMovements.Select().LastOrDefault(); var milage = MilageFactory.ViewmodelToEntity(result); _dbcontext.Milages.Add(milage); await _dbcontext.SaveChangesAsync(); var driver = _dbcontext.Drivers.SingleOrDefault(x => x.Id == mov.DriverId); if (driver == null) { Danger("Something is wrong Internally, visit the admin"); return(View("Create")); } driver.IsAvailable = false; await _dbcontext.SaveChangesAsync(); scope.Complete(); scope.Dispose(); } //Desig } catch (DbEntityValidationException e) { var outputLines = new List <string>(); foreach (var eve in e.EntityValidationErrors) { outputLines.Add(string.Format("{0}: Entity of type \"{1}\" in state \"{2}\" has the following validation errors: ", DateTime.Now, eve.Entry.Entity.GetType().Name, eve.Entry.State)); foreach (var ve in eve.ValidationErrors) { outputLines.Add(string.Format(" Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage)); } } Danger(outputLines.ToString(), false); System.IO.File.AppendAllLines(@"C:\errors.txt", outputLines); //throw; } } return(RedirectToAction("Index")); }