From 724930efc92d9fe70542cf113dc5c6bd9f1c935b Mon Sep 17 00:00:00 2001 From: Palash Biswas Date: Wed, 7 Dec 2022 19:57:39 +0530 Subject: [PATCH] BMC: Add FirebaseNotification class in NotificationModel Class --- .../Dto/NotificationModel.cs | 19 ++++--------------- .../Controllers/NotificationController.cs | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs index 67a30ef..4ae421f 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs @@ -14,7 +14,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto public class NotificationModel { - public string Id { get; set; } + [JsonProperty("title")] public List 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; } } } diff --git a/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs b/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs index 2af72f8..5748b92 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs +++ b/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs @@ -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 GetNotifications([FromBody]NotificationModel notification) { + var model = ObjectMapper.Map(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(); + await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity); + }catch(Exception ex) + { - var entity = notification.MapTo(); - await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity); + } + // var result = _notificationService.GetNotification(notification); return Ok(); }