|
|
@ -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<IActionResult> 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<string> tokenList = new List<string>(); |
|
|
|
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<IActionResult> 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<string> usrId = new List<string>(); |
|
|
|
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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |