public Task Consume(ConsumeContext <CreateTeltonikaGps> context) { try { var item = Item(context.Message); if (item.Result != null) { using (var contextFScope = _dbContextScopeFactory.Create()) { var position = new Position(); position.Box_Id = item.Result?.Id; position.Altitude = context.Message.Altitude; position.Direction = context.Message.Direction; position.Lat = context.Message.Lat; position.Long = context.Message.Long; position.Speed = context.Message.Speed; position.Id = Guid.NewGuid(); position.Priority = context.Message.Priority; position.Satellite = context.Message.Satellite; position.Timestamp = context.Message.Timestamp; position.MotionStatus = !context.Message.IsStop || context.Message.Speed > 0.0 ? MotionStatus.Moving : MotionStatus.Stopped; _posiRepository.Add(position); contextFScope.SaveChangesAsync().ConfigureAwait(false); } } } catch (Exception e) { Trace.WriteLine(e); //throw; } return(Task.FromResult(false)); }
private async Task <Scope> AddAsync(Scope scope, Application application) { if (application.Scopes.Any(s => s.Name == scope.Name)) { throw new ConflictException("Scope name already exists."); } _scopeRepository.Add(scope); await _scopeRepository.SaveAsync(); return(scope); }
public Task Consume(ConsumeContext <CreateBoxCommand> context) { using (var contextFScope = _dbContextScopeFactory.Create()) { _db = contextFScope.DbContexts.Get <SmartFleetObjectContext>(); var item = _db.Boxes.FirstOrDefaultAsync(b => b.Imei == context.Message.Imei).Result; if (item != null) { return(Task.FromResult(false)); } var box = new Box(); box.Id = Guid.NewGuid(); box.BoxStatus = BoxStatus.WaitPreparation; box.CreationDate = DateTime.UtcNow; box.Icci = String.Empty; box.PhoneNumber = String.Empty; box.Vehicle = null; box.Imei = context.Message.Imei; box.SerialNumber = String.Empty; try { _boxRepository.Add(box); contextFScope.SaveChangesAsync().ConfigureAwait(false); } catch (Exception e) { Trace.WriteLine(e); throw; } return(Task.FromResult(false)); } }