BMC: Change msgSent datetime value in GetNotifications Method
This commit is contained in:
		
							parent
							
								
									7617b41df0
								
							
						
					
					
						commit
						3682a17d53
					
				| @ -40,7 +40,7 @@ namespace BCS.BMC.Web.Controllers | |||||||
|             IRepository<FirebaseToken, int> firebaseToken) |             IRepository<FirebaseToken, int> firebaseToken) | ||||||
|         { |         { | ||||||
|             _notificationService = notificationService; |             _notificationService = notificationService; | ||||||
|             _firebaseCloudMessageDetails = firebaseCloudMessageDetails;  |             _firebaseCloudMessageDetails = firebaseCloudMessageDetails; | ||||||
|             _firebaseToken = firebaseToken; |             _firebaseToken = firebaseToken; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -58,52 +58,35 @@ namespace BCS.BMC.Web.Controllers | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         public async Task<IActionResult> GetNotifications([FromBody]NotificationModel notification) |         public async Task<IActionResult> GetNotifications([FromBody] NotificationModel notification) | ||||||
|         { |         { | ||||||
|            string path = AppDomain.CurrentDomain.BaseDirectory + @"firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json"; |             string path = AppDomain.CurrentDomain.BaseDirectory + @"firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json"; | ||||||
|            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path); |             Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path); | ||||||
| 
 | 
 | ||||||
|             try |             try | ||||||
|             {    |             { | ||||||
|                 FirestoreDb db = FirestoreDb.Create("firechat-57601"); |                 FirestoreDb db = FirestoreDb.Create("firechat-57601"); | ||||||
|                 FireStoreNotificationModel data = new FireStoreNotificationModel(); |                 FireStoreNotificationModel data = new FireStoreNotificationModel(); | ||||||
| 
 | 
 | ||||||
|                 data.FcmToken = notification.FcmToken; |                 data.FcmToken = notification.FcmToken; | ||||||
|                // data.Id = notification.Id; |                 // data.Id = notification.Id; | ||||||
|                 data.Message = notification.Message; |                 data.Message = notification.Message; | ||||||
|                 //data.MessageSentDateTime = notification.MessageSentDateTime; |                 data.MessageSentDateTime = notification.MessageSentDateTime; | ||||||
|                 data.MessageSentDateTime = DateTime.UtcNow; |                 //data.MessageSentDateTime = DateTime.UtcNow; | ||||||
|                 data.SenderImageurl = notification.SenderImageurl; |                 data.SenderImageurl = notification.SenderImageurl; | ||||||
|                 data.SenderName = notification.SenderName; |                 data.SenderName = notification.SenderName; | ||||||
|                 data.Status= notification.Status; |                 data.Status = notification.Status; | ||||||
|                 data.UserId = notification.UserId; |                 data.UserId = notification.UserId; | ||||||
|                 |                 await db.Collection("BMC_Notification").Document().SetAsync(data); | ||||||
|  | 
 | ||||||
|  |                 int userId = 0; | ||||||
|  |                 List<string> tokenList = new List<string>(); | ||||||
|                 foreach (var item in notification.UserId) |                 foreach (var item in notification.UserId) | ||||||
|                 { |                 { | ||||||
|                     int userId = Convert.ToInt32(item); |                     userId = Convert.ToInt32(item); | ||||||
|                     var getTokenDetails = _firebaseToken.GetAllList().Where(x => x.UserId == userId).FirstOrDefault();                |                     var getTokenDetails = _firebaseToken.GetAllList().Where(x => x.UserId == userId).FirstOrDefault(); | ||||||
|                     List<string> tokenList = new List<string>(); |  | ||||||
|                     tokenList.Add(getTokenDetails.FcmToken.ToString()); |                     tokenList.Add(getTokenDetails.FcmToken.ToString()); | ||||||
|                     await db.Collection("BMC_Notification").Document().SetAsync(data); |  | ||||||
| 
 | 
 | ||||||
|                     if (getTokenDetails != null) |  | ||||||
|                 { |  | ||||||
|                         var title = notification.SenderName.ToJsonString(); |  | ||||||
|                         var body = notification.Message.ToJsonString(); |  | ||||||
|                         var sendNotificationInfo = new FireBaseResponseModel(); |  | ||||||
|                         { |  | ||||||
|                             sendNotificationInfo.FcmToken = tokenList; |  | ||||||
|                         } |  | ||||||
| 
 |  | ||||||
|                         Notification notifications = new Notification |  | ||||||
|                         { |  | ||||||
|                             Title = title, |  | ||||||
|                             Body = body, |  | ||||||
|                             //ImageUrl = null |  | ||||||
|                         }; |  | ||||||
|                         sendNotificationInfo.notification = notifications; |  | ||||||
|                         await SendNotification(sendNotificationInfo); |  | ||||||
|                 } |  | ||||||
|                     var entity = new FirebaseCloudMessageDetails(); |                     var entity = new FirebaseCloudMessageDetails(); | ||||||
|                     entity.UserId = userId; |                     entity.UserId = userId; | ||||||
|                     entity.SenderImageurl = notification.SenderImageurl; |                     entity.SenderImageurl = notification.SenderImageurl; | ||||||
| @ -117,10 +100,23 @@ namespace BCS.BMC.Web.Controllers | |||||||
|                         await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity); |                         await _firebaseCloudMessageDetails.InsertAndGetIdAsync(entity); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |                 var title = notification.SenderName.ToJsonString(); | ||||||
|  |                 var body = notification.Message.ToJsonString(); | ||||||
|  |                 var sendNotificationInfo = new FireBaseResponseModel(); | ||||||
|  |                 { | ||||||
|  |                     sendNotificationInfo.FcmToken = tokenList; | ||||||
|  |                 } | ||||||
| 
 | 
 | ||||||
|                  |                 Notification notifications = new Notification | ||||||
|  |                 { | ||||||
|  |                     Title = title, | ||||||
|  |                     Body = body, | ||||||
|  |                     //ImageUrl = null | ||||||
|  |                 }; | ||||||
|  |                 sendNotificationInfo.notification = notifications; | ||||||
|  |                 await SendNotification(sendNotificationInfo); | ||||||
|             } |             } | ||||||
|             catch(Exception ex) |             catch (Exception ex) | ||||||
|             { |             { | ||||||
| 
 | 
 | ||||||
|             } |             } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user