From c93955df68a7b4d8dbd19947049784d5cd15b5cf Mon Sep 17 00:00:00 2001 From: Palash Biswas Date: Wed, 7 Dec 2022 16:17:37 +0530 Subject: [PATCH] BMC: Install FireShip sdk --- .../BCS.BMC.Application.csproj | 1 + .../Dto/NotificationModel.cs | 14 ++++++- .../BCS.BMC.Web.Mvc/BCS.BMC.Web.Mvc.csproj | 1 + .../Controllers/NotificationController.cs | 41 +++++++++++++++++-- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/BCS.BMC/src/BCS.BMC.Application/BCS.BMC.Application.csproj b/BCS.BMC/src/BCS.BMC.Application/BCS.BMC.Application.csproj index 77bbad6..0e8923e 100644 --- a/BCS.BMC/src/BCS.BMC.Application/BCS.BMC.Application.csproj +++ b/BCS.BMC/src/BCS.BMC.Application/BCS.BMC.Application.csproj @@ -19,6 +19,7 @@ + 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 fb9e70a..b95262b 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs @@ -1,22 +1,34 @@ -using Newtonsoft.Json; +using Abp.AutoMapper; +using BCS.BMC.BMC.FirebaseCloudMessages; +using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BCS.BMC.FirebaseCloudMessaging.Dto { + [AutoMapTo(typeof (FirebaseCloudMessageDetails))] public class NotificationModel { //[JsonProperty("deviceId")] //public string DeviceId { get; set; } //[JsonProperty("isAndroidDevice")] //public bool IsAndroidDevice { get; set; } + public string Id { get; set; } [JsonProperty("title")] public string Title { get; set; } [JsonProperty("body")] public string Body { get; set; } + public int UserId { get; set; } + public string FcmToken { get; set; } + public string SenderImageurl { get; set; } + public string SenderName { get; set; } + public DateTime? MessageSentDateTime { get; set; } + public bool Status { get; set; } + public string Message { get; set; } } public class GoogleNotification diff --git a/BCS.BMC/src/BCS.BMC.Web.Mvc/BCS.BMC.Web.Mvc.csproj b/BCS.BMC/src/BCS.BMC.Web.Mvc/BCS.BMC.Web.Mvc.csproj index 3878303..32b54c1 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Mvc/BCS.BMC.Web.Mvc.csproj +++ b/BCS.BMC/src/BCS.BMC.Web.Mvc/BCS.BMC.Web.Mvc.csproj @@ -32,6 +32,7 @@ + all 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 4712d03..2af72f8 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs +++ b/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs @@ -1,9 +1,16 @@ -using Abp.Json; +using Abp.AutoMapper; +using Abp.Domain.Repositories; +using Abp.Json; +using BCS.BMC.BMC.CompanyMasters; +using BCS.BMC.BMC.FirebaseCloudMessages; using BCS.BMC.Controllers; using BCS.BMC.FirebaseCloudMessaging; using BCS.BMC.FirebaseCloudMessaging.Dto; using BCS.BMC.Models.TokenAuth; using FirebaseAdmin.Messaging; +using FireSharp.Config; +using FireSharp.Interfaces; +using FireSharp.Response; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System.Collections.Generic; @@ -16,10 +23,20 @@ namespace BCS.BMC.Web.Controllers public class NotificationController : BMCControllerBase { private readonly IFirebaseNotificationAppService _notificationService; - - public NotificationController(IFirebaseNotificationAppService notificationService) + private readonly IRepository _firebaseCloudMessageDetails; + IFirebaseConfig config = new FirebaseConfig + { + AuthSecret = "n6DTPQEbpnLahrrk2EYu4bJ2Wd3jCk2N8kocazdI", + BasePath = "https://firechat-57601-default-rtdb.europe-west1.firebasedatabase.app/" + }; + IFirebaseClient client; + public NotificationController(IFirebaseNotificationAppService notificationService, + IRepository firebaseCloudMessageDetails) { _notificationService = notificationService; + _firebaseCloudMessageDetails = firebaseCloudMessageDetails; + + } @@ -31,8 +48,24 @@ namespace BCS.BMC.Web.Controllers } [HttpPost] - public async Task GetNotifications([FromBody] NotificationModel notification) + public async Task GetNotifications([FromBody]NotificationModel 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); + if (setResponse.StatusCode == System.Net.HttpStatusCode.OK) + { + ModelState.AddModelError(string.Empty, "Added Succesfully"); + } + else + { + ModelState.AddModelError(string.Empty, "Something went wrong!!"); + } + + var entity = notification.MapTo(); + await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity); // var result = _notificationService.GetNotification(notification); return Ok(); }