BMC: Add FirebaseNotification class in NotificationModel Class

This commit is contained in:
Palash Biswas 2022-12-07 19:57:39 +05:30
parent 2adb716ead
commit 724930efc9
2 changed files with 18 additions and 20 deletions

View File

@ -14,7 +14,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
public class NotificationModel
{
public string Id { get; set; }
[JsonProperty("title")]
public List<string> Title { get; set; }
[JsonProperty("body")]
@ -27,20 +27,9 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
public string Message { get; set; }
}
public class GoogleNotification
[AutoMapFrom(typeof(NotificationModel))]
public class FirebaseNotification : NotificationModel
{
public class DataPayload
{
[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; }
public string Id { get; set; }
}
}

View File

@ -13,6 +13,7 @@ using FireSharp.Interfaces;
using FireSharp.Response;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@ -50,11 +51,13 @@ namespace BCS.BMC.Web.Controllers
[HttpPost]
public async Task<IActionResult> GetNotifications([FromBody]NotificationModel notification)
{
var model = ObjectMapper.Map<FirebaseNotification>(notification);
client = new FireSharp.FirebaseClient(config);
var data = notification;
PushResponse response = client.Push("notification/", data);
data.Id = response.Result.name;
SetResponse setResponse = client.Set("notification/" + data.Id, data);
PushResponse response = client.Push("notification/", model);
model.Id = response.Result.name;
SetResponse setResponse = client.Set("notification/" + model.Id, model);
if (setResponse.StatusCode == System.Net.HttpStatusCode.OK)
{
ModelState.AddModelError(string.Empty, "Added Succesfully");
@ -63,9 +66,15 @@ namespace BCS.BMC.Web.Controllers
{
ModelState.AddModelError(string.Empty, "Something went wrong!!");
}
try
{
var entity = notification.MapTo<FirebaseCloudMessageDetails>();
await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity);
}catch(Exception ex)
{
}
// var result = _notificationService.GetNotification(notification);
return Ok();
}