From 7617b41df012a4a41339de419762e943310d6fd7 Mon Sep 17 00:00:00 2001 From: Palash Biswas Date: Mon, 12 Dec 2022 23:23:09 +0530 Subject: [PATCH] BMC : Remove id property from NotificationModel --- .../Dto/FireStoreNotificationModel.cs | 6 ++-- .../Dto/NotificationModel.cs | 5 +-- .../Controllers/NotificationController.cs | 35 ++++++++++--------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs index c2721d9..1f9a711 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs @@ -12,8 +12,8 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto { [FirestoreProperty] public string FcmToken { get; set; } - [FirestoreProperty] - public List Id { get; set; } + //[FirestoreProperty] + //public List Id { get; set; } [FirestoreProperty] public string Message { get; set; } [FirestoreProperty] @@ -26,6 +26,6 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto [FirestoreProperty] public bool Status { get; set; } [FirestoreProperty] - public int UserId { get; set; } + public List UserId { get; set; } } } 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 d11bc15..8c3d2c5 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs @@ -19,7 +19,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto //public List Title { get; set; } //[JsonProperty("body")] public string FcmToken { get; set; } - public List Id { get; set; } + //public List Id { get; set; } public string Message { get; set; } public DateTime? MessageSentDateTime { get; set; } @@ -27,7 +27,8 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto public string SenderName { get; set; } public bool Status { get; set; } - public int UserId { get; set; } + public List UserId { get; set; } + } //[AutoMapFrom(typeof(NotificationModel))] 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 037a91e..d0fd6fb 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs +++ b/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs @@ -69,7 +69,7 @@ namespace BCS.BMC.Web.Controllers FireStoreNotificationModel data = new FireStoreNotificationModel(); data.FcmToken = notification.FcmToken; - data.Id = notification.Id; + // data.Id = notification.Id; data.Message = notification.Message; //data.MessageSentDateTime = notification.MessageSentDateTime; data.MessageSentDateTime = DateTime.UtcNow; @@ -77,16 +77,16 @@ namespace BCS.BMC.Web.Controllers data.SenderName = notification.SenderName; data.Status= notification.Status; data.UserId = notification.UserId; - await db.Collection("BMC_Notification").Document().SetAsync(data); - foreach (var item in notification.Id) + + foreach (var item in notification.UserId) { int userId = Convert.ToInt32(item); var getTokenDetails = _firebaseToken.GetAllList().Where(x => x.UserId == userId).FirstOrDefault(); List tokenList = new List(); tokenList.Add(getTokenDetails.FcmToken.ToString()); - + await db.Collection("BMC_Notification").Document().SetAsync(data); - if (getTokenDetails != null) + if (getTokenDetails != null) { var title = notification.SenderName.ToJsonString(); var body = notification.Message.ToJsonString(); @@ -104,20 +104,21 @@ namespace BCS.BMC.Web.Controllers sendNotificationInfo.notification = notifications; await SendNotification(sendNotificationInfo); } - } + var entity = new FirebaseCloudMessageDetails(); + entity.UserId = userId; + entity.SenderImageurl = notification.SenderImageurl; + entity.SenderName = notification.SenderName; + entity.MessageSentDateTime = notification.MessageSentDateTime; + entity.Status = notification.Status; + entity.Message = notification.Message; - var entity = new FirebaseCloudMessageDetails(); - entity.UserId = notification.UserId; - entity.SenderImageurl = notification.SenderImageurl; - entity.SenderName = notification.SenderName; - entity.MessageSentDateTime = notification.MessageSentDateTime; - entity.Status = notification.Status; - entity.Message = notification.Message; + if (entity != null) + { + await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity); + } + } - if(entity != null) - { - await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity); - } + } catch(Exception ex) {