public async Task <CarRead> GetCar(string id) { var car = _dataAccess.GetCar(new Guid(id)); if (car.Locked) { if (CarHasBeenLocked40Seconds(car)) { //Lock timed out and can be ignored and set to false var updateCarLockedStatus = new UpdateCarLockedStatus { LockedStatus = false, CarId = car.CarId, CompanyId = car.CompanyId, UpdateCarLockedTimeStamp = DateTime.Now.Ticks }; await _endpointInstancePriority.Publish(updateCarLockedStatus).ConfigureAwait(false); } } var CarRead = new CarRead(car.CarId) { CompanyId = car.CompanyId, CreationTime = car.CreationTime, Locked = car.Locked, Online = car.Online, Speed = car.Speed, RegNr = car.RegNr, VIN = car.VIN }; return(CarRead); }
public async Task AddCar([FromBody] CarRead carRead) { var createCar = new CreateCar { CompanyId = carRead.CompanyId, CreationTime = carRead.CreationTime, CarId = carRead.CarId, RegNr = carRead.RegNr, VIN = carRead.VIN, Locked = carRead.Locked, Online = carRead.Online, Speed = carRead.Speed, CreateCarTimeStamp = DateTime.Now.Ticks }; var createOnlineStatus = new CreateCarOnlineStatus { CarId = carRead.CarId, CompanyId = carRead.CompanyId, OnlineStatus = carRead.Online, CreateCarOnlineTimeStamp = DateTime.Now.Ticks }; var createLockedStatus = new CreateCarLockedStatus { CarId = carRead.CarId, CompanyId = carRead.CompanyId, LockedStatus = carRead.Locked, CreateCarLockedTimeStamp = DateTime.Now.Ticks }; var createSpeed = new CreateCarSpeed { CarId = carRead.CarId, CompanyId = carRead.CompanyId, Speed = carRead.Speed, CreateCarSpeedTimeStamp = DateTime.Now.Ticks }; await _endpointInstance.Send(Helpers.ServerEndpoint, createCar).ConfigureAwait(false); await _endpointInstance.Send(Helpers.ServerEndpoint, createOnlineStatus).ConfigureAwait(false); await _endpointInstance.Send(Helpers.ServerEndpoint, createLockedStatus).ConfigureAwait(false); await _endpointInstance.Send(Helpers.ServerEndpoint, createSpeed).ConfigureAwait(false); }
public async Task UpdateCarOnline([FromBody] CarRead CarRead) { var oldCar = GetCar(CarRead.CarId.ToString()); if (oldCar == null) { return; } var updateCarOnlineStatus = new UpdateCarOnlineStatus { OnlineStatus = CarRead.Online, CarId = CarRead.CarId, CompanyId = CarRead.CompanyId, UpdateCarOnlineTimeStamp = DateTime.Now.Ticks }; await _endpointInstance.Send(Helpers.ServerEndpoint, updateCarOnlineStatus).ConfigureAwait(false); }
public async Task UpdateCarLocked([FromBody] CarRead CarRead) { var oldCar = GetCar(CarRead.CarId.ToString()); if (oldCar == null) { return; } var updateCarLockedStatus = new UpdateCarLockedStatus { LockedStatus = CarRead.Locked, CarId = CarRead.CarId, CompanyId = CarRead.CompanyId, UpdateCarLockedTimeStamp = DateTime.Now.Ticks }; await _endpointInstancePriority.Publish(updateCarLockedStatus).ConfigureAwait(false); }
private static bool CarHasBeenLocked40Seconds(CarRead car) { return(new DateTime(car.LockedTimeStamp).AddMilliseconds(40000) < DateTime.Now); }