diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/BmcMessageStatusInput.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/BmcMessageStatusInput.cs new file mode 100644 index 0000000..85b9bf7 --- /dev/null +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/BmcMessageStatusInput.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BCS.BMC.FirebaseCloudMessaging.Dto +{ + public class BmcMessageStatusInput + { + public List UserId { get; set; } + public long? ScheduleGenerationId { get; set; } + public string Status { get; set; } + public string CompanyUrl { get; set; } + public bool IsSuccess { get; set; } + } +} diff --git a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs index 3026ec9..014e9a4 100755 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs @@ -12,5 +12,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto { public Notification notification { get; set; } public List FcmToken { get; set; } + + public BmcMessageStatusInput getResponseData { 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 c0c475f..192415c 100644 --- a/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs +++ b/BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs @@ -24,7 +24,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto public bool Status { get; set; } public List UserId { get; set; } public string CompanyUrl { get; set; } - public string ScheduleGenerationId { get; set; } + public long? ScheduleGenerationId { get; set; } } //[AutoMapFrom(typeof(NotificationModel))] diff --git a/BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginOrRegisterResponseMessageModel.cs b/BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginOrRegisterResponseMessageModel.cs index c893678..35ee838 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginOrRegisterResponseMessageModel.cs +++ b/BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginOrRegisterResponseMessageModel.cs @@ -16,9 +16,13 @@ namespace BCS.BMC.Models.TokenAuth public int statusCode { get; set; } public string userName { get; set; } + public string firstName { get; set; } + public string lastName { get; set; } + public string emailAddress { get; set; } public string userId { get; set; } public string employeeId { get; set; } public string phoneNo { get; set; } public string profilePictureId { 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 43ce44a..0f019f6 100644 --- a/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs +++ b/BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs @@ -17,6 +17,8 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http.Headers; +using System.Net.Http; using System.Threading.Tasks; namespace BCS.BMC.Web.Controllers @@ -52,11 +54,29 @@ namespace BCS.BMC.Web.Controllers public async Task SendNotification([FromBody] FireBaseResponseModel notification) { var result = await _notificationService.SendNotification(notification); - //To Do - //if () - //{ - // return Ok(result); - //} + + + if (result.SuccessCount>0) + { + if(notification.getResponseData != null) + { + notification.getResponseData.IsSuccess = true; + notification.getResponseData.Status = "Delivered"; + } + await UpdateBmcMessageStatus(notification.getResponseData); + return Ok(result); + } + if (result.FailureCount > 0) + { + if (notification.getResponseData != null) + { + notification.getResponseData.IsSuccess = false; + notification.getResponseData.Status = result.Responses[0].Exception.Message; + } + await UpdateBmcMessageStatus(notification.getResponseData); + return BadRequest(result.Responses); + } + return Ok(result.Responses); } @@ -65,7 +85,7 @@ namespace BCS.BMC.Web.Controllers { string path = AppDomain.CurrentDomain.BaseDirectory + @"firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json"; Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path); - var companyDetails = _companyMasterService.GetAllList().Where(x => x.Url.Trim() == notification.CompanyUrl.Trim()).FirstOrDefault(); + var companyDetails = _companyMasterService.GetAllList().Where(x => x.Url.Trim() == notification.CompanyUrl.Trim()).FirstOrDefault(); try { FirestoreDb db = FirestoreDb.Create("firechat-57601"); @@ -81,9 +101,16 @@ namespace BCS.BMC.Web.Controllers data.Status = notification.Status; data.UserId = notification.UserId; data.CompanyId = companyDetails.Id; - data.ScheduleGenerationId = notification.ScheduleGenerationId; + data.ScheduleGenerationId = notification.ScheduleGenerationId.ToString(); await db.Collection("BMC_Notification").Document().SetAsync(data); + var responseData = new BmcMessageStatusInput(); + { + responseData.UserId = notification.UserId; + responseData.ScheduleGenerationId = notification.ScheduleGenerationId; + responseData.CompanyUrl = notification.CompanyUrl; + } + int userId = 0; List tokenList = new List(); foreach (var item in notification.UserId) @@ -119,6 +146,7 @@ namespace BCS.BMC.Web.Controllers //ImageUrl = null }; sendNotificationInfo.notification = notifications; + sendNotificationInfo.getResponseData = responseData; await SendNotification(sendNotificationInfo); } catch (Exception ex) @@ -127,5 +155,39 @@ namespace BCS.BMC.Web.Controllers } return Ok(); } + [HttpPost] + public async Task UpdateBmcMessageStatus([FromBody] BmcMessageStatusInput bmcMessageStatusInput) + { + var companyDetails = _companyMasterService.GetAllList().Where(x => x.Url.Trim() == bmcMessageStatusInput.CompanyUrl.Trim()).FirstOrDefault(); + var baseUrl = companyDetails.Url + "api/services/bwac/updateBmcMessageStatus/UpdateMessageStatus"; + if (baseUrl == null) + { + return BadRequest("Invalid Company Url"); + } + using (HttpClient client = new HttpClient()) + { + List usrId = new List(); + foreach (var uId in bmcMessageStatusInput.UserId) + { + usrId.Add(uId.ToString()); + } + foreach (var userid in usrId) + { + var data = new + { + UserId =int.Parse(userid), + ScheduleGenerationId = bmcMessageStatusInput.ScheduleGenerationId, + Status = bmcMessageStatusInput.Status, + CompanyUrl = bmcMessageStatusInput.CompanyUrl, + IsSuccess = bmcMessageStatusInput.IsSuccess, + }; + var requestJson = JsonConvert.SerializeObject(data); + var requestContent = new StringContent(requestJson.ToString()); + requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json"); + HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent); + } + return Ok(); + } + } } } \ No newline at end of file