Ejemplo n.º 1
0
        public async Task <int?> Upsert(Job job)
        {
            try
            {
                foreach (var telemData in job.TelemData.ToList())
                {
                    await _context.TelemData.AddAsync(telemData);
                }

                if (job.Id == 0)
                {
                    await _context.Job.AddAsync(job);
                }
                else
                {
                    _context.Job.Update(job);
                }

                _context.Entry(job.Device).State = EntityState.Unchanged;

                await _context.SaveChangesAsync();

                return(job.Id);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public async Task <EntityState> Create(User user)
        {
            try
            {
                var userEntityState = _context.Entry(user).State = EntityState.Added;

                await _context.SaveChangesAsync();

                return(userEntityState);
            }
            catch
            {
                return(EntityState.Unchanged);
            }
        }
Ejemplo n.º 3
0
        public async Task <EntityState> AddDeviceToUser(string userId, Device device)
        {
            if (null != await _context.UserDevice.FindAsync(userId, device.BluetoothAddress))
            {
                return(EntityState.Unchanged);
            }

            var userEntity = await _context.User.FindAsync(userId);

            await _context.UserDevice.AddAsync(new UserDevice
            {
                User             = userEntity,
                UserId           = userId,
                BluetoothAddress = device.BluetoothAddress,
                Device           = await _context.Device.FindAsync(device.BluetoothAddress) ?? device
            });

            await _context.SaveChangesAsync();

            return(EntityState.Added);
        }
Ejemplo n.º 4
0
        public async Task CreateToken(ActiveToken token)
        {
            await _context.ActiveToken.AddAsync(token);

            await _context.SaveChangesAsync();
        }