Пример #1
0
        public async Task <bool> AddAsync(ObdTelemetry model)
        {
            var vehicle = _context.Vehicles.SingleOrDefault(v => v.DeviceId == model.DeviceId);

            if (vehicle == null)
            {
                return(false);
            }

            _context.ObdTelemetries.Add(model);
            return(await _context.SaveChangesAsync() > 0);
        }
Пример #2
0
        public async Task <bool> AddAsync(Vehicle model, string username)
        {
            if (_context.Vehicles.Any(v => v.DeviceId == model.DeviceId))
            {
                return(false);
            }

            _context.Users
            .Include(u => u.Vehicles)
            .Single(u => u.UserName.Equals(username))
            .Vehicles
            .Add(model);

            return(await _context.SaveChangesAsync() > 0);
        }