Add a Nuget Reference to:
Create an entity in your project named UserDevice. It should have the following properties. For each installation a record will be inserted into this table.
Note: It should implement: MSharp.Framework.Api.PushNotification.IUserDevice
public IHttpActionResult RegisterPushNotification(User user, string installationToken, string pushNotificationToken, string deviceType)
{
var device = UserDevice.FindByInstallationToken(installationToken)?.Clone() ?? new UserDevice();
device.InstallationToken = installationToken;
device.PushNotificationToken = pushNotificationToken;
device.DeviceType = deviceType;
device.InstallationTime = LocalTime.Now;
device.LastLogOff = null;
Database.Save(device);
}
[HttpPost, Route("push-notification/unregister")]
public IHttpActionResult UnregisterPushNotification(string installationToken)
{
var device = UserDevice.FindByInstallationToken(installationToken);
if (device != null) Database.Update(device, d => d.PushNotificationToken = null);
}
When the user logs off from the App, it should call an API and send the installation token with it to then update the user device record.
public IHttpActionResult Logout(string installationToken)
{
UserDevice.FindByInstallationToken(installationToken)?.SetDeviceAsOffline();
return Ok();
}
--------In the UserDevice logic file ------------