Browse Source

BMC: Add FirebaseNotification class in NotificationModel Class

feature/ModificationForSentNotificationAPI
Palash Biswas 2 years ago
parent
commit
724930efc9
2 changed files with 18 additions and 20 deletions
  1. +4
    -15
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs
  2. +14
    -5
      BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs

+ 4
- 15
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs 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; }
}
}

+ 14
- 5
BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs 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 entity = notification.MapTo<FirebaseCloudMessageDetails>();
await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity);
}
// var result = _notificationService.GetNotification(notification);
return Ok();
}


Loading…
Cancel
Save