public async Task <PushTokens> SaveToken(string userId, string token, string deviceId) { ILAUser user = await _context.Users.FindAsync(userId); PushTokens pushToken = await _context.PushTokens.Where(x => x.DeviceId == deviceId).SingleOrDefaultAsync(x => x.User.Id == userId); if (pushToken == null) { pushToken = new PushTokens { DeviceId = deviceId, User = user, Token = token }; await _context.PushTokens.AddAsync(pushToken); } else { pushToken.Token = token; pushToken.User = user; _context.PushTokens.Update(pushToken); } await _context.SaveChangesAsync(); pushToken.User = null; return(pushToken); }
public async Task DeleteToken(string userId, string deviceId) { PushTokens pushToken = await _context.PushTokens.Where(x => x.DeviceId == deviceId).SingleOrDefaultAsync(x => x.User.Id == userId); if (pushToken == null) { throw new UserException(404); } _context.PushTokens.Remove(pushToken); await _context.SaveChangesAsync(); }