public async Task <ActionResult> DeviceOffline([FromBody] DeviceTokenDto devTok) { if (devTok == null || string.IsNullOrWhiteSpace(devTok.deviceToken)) { this._logger.LogError("InternalCommsController_DevOff_NoToken"); return(BadRequest()); } DeviceToken dt = this._context.DeviceTokens.FirstOrDefault(d => d.Token == devTok.deviceToken); if (dt == null) { this._logger.LogError("InternalCommsController_DevOff_NoSuchDevice"); return(StatusCode(500, "No User for this device token")); } dt.IsDeviceOnline = false; dt.DeviceEvents.Add(new DeviceEvent(DateTime.UtcNow, false)); await this._context.SaveChangesAsync(); User usr = this._context.Users.FirstOrDefault(u => u.Id == dt.UserId); if (usr == null) { this._logger.LogError("InternalCommsController_DevOff_NoUserForDeviceToken"); return(StatusCode(500, "No User for this device token")); } this._pushNotificationService.BroadcastDeviceOfflineNotification(usr, dt.Token); return(Ok()); }
public async Task <ActionResult> DeviceOnline([FromBody] DeviceTokenDto devTok) { if (devTok == null || string.IsNullOrWhiteSpace(devTok.deviceToken)) { this._logger.LogError("InternalCommsController_DevOn_NoToken"); return(BadRequest()); } DeviceToken dt = this._context.DeviceTokens.FirstOrDefault(d => d.Token == devTok.deviceToken); if (dt == null) { this._logger.LogError("InternalCommsController_DevOff_NoSuchDevice"); return(StatusCode(500)); } dt.IsDeviceOnline = true; dt.DeviceEvents.Add(new DeviceEvent(DateTime.UtcNow, true)); await this._context.SaveChangesAsync(); return(Ok()); }