BMC: Add FirebaseNotification class in NotificationModel Class
This commit is contained in:
parent
2adb716ead
commit
724930efc9
@ -14,7 +14,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
|
|||||||
public class NotificationModel
|
public class NotificationModel
|
||||||
{
|
{
|
||||||
|
|
||||||
public string Id { get; set; }
|
|
||||||
[JsonProperty("title")]
|
[JsonProperty("title")]
|
||||||
public List<string> Title { get; set; }
|
public List<string> Title { get; set; }
|
||||||
[JsonProperty("body")]
|
[JsonProperty("body")]
|
||||||
@ -27,20 +27,9 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
|
|||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GoogleNotification
|
[AutoMapFrom(typeof(NotificationModel))]
|
||||||
|
public class FirebaseNotification : NotificationModel
|
||||||
{
|
{
|
||||||
public class DataPayload
|
public string Id { get; set; }
|
||||||
{
|
|
||||||
[JsonProperty("title")]
|
|
||||||
public string Title { get; set; }
|
|
||||||
[JsonProperty("body")]
|
|
||||||
public string Body { get; set; }
|
|
||||||
}
|
|
||||||
[JsonProperty("priority")]
|
|
||||||
public string Priority { get; set; } = "high";
|
|
||||||
[JsonProperty("data")]
|
|
||||||
public DataPayload Data { get; set; }
|
|
||||||
[JsonProperty("notification")]
|
|
||||||
public DataPayload Notification { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ using FireSharp.Interfaces;
|
|||||||
using FireSharp.Response;
|
using FireSharp.Response;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -50,11 +51,13 @@ namespace BCS.BMC.Web.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> GetNotifications([FromBody]NotificationModel notification)
|
public async Task<IActionResult> GetNotifications([FromBody]NotificationModel notification)
|
||||||
{
|
{
|
||||||
|
var model = ObjectMapper.Map<FirebaseNotification>(notification);
|
||||||
|
|
||||||
client = new FireSharp.FirebaseClient(config);
|
client = new FireSharp.FirebaseClient(config);
|
||||||
var data = notification;
|
var data = notification;
|
||||||
PushResponse response = client.Push("notification/", data);
|
PushResponse response = client.Push("notification/", model);
|
||||||
data.Id = response.Result.name;
|
model.Id = response.Result.name;
|
||||||
SetResponse setResponse = client.Set("notification/" + data.Id, data);
|
SetResponse setResponse = client.Set("notification/" + model.Id, model);
|
||||||
if (setResponse.StatusCode == System.Net.HttpStatusCode.OK)
|
if (setResponse.StatusCode == System.Net.HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
ModelState.AddModelError(string.Empty, "Added Succesfully");
|
ModelState.AddModelError(string.Empty, "Added Succesfully");
|
||||||
@ -63,9 +66,15 @@ namespace BCS.BMC.Web.Controllers
|
|||||||
{
|
{
|
||||||
ModelState.AddModelError(string.Empty, "Something went wrong!!");
|
ModelState.AddModelError(string.Empty, "Something went wrong!!");
|
||||||
}
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
var entity = notification.MapTo<FirebaseCloudMessageDetails>();
|
var entity = notification.MapTo<FirebaseCloudMessageDetails>();
|
||||||
await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity);
|
await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity);
|
||||||
|
}catch(Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// var result = _notificationService.GetNotification(notification);
|
// var result = _notificationService.GetNotification(notification);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user