Browse Source

BMC: Add More Values fro login API

feature/ModificationForSentNotificationAPI
Palash Biswas 2 years ago
parent
commit
5509295fd7
5 changed files with 93 additions and 8 deletions
  1. +17
    -0
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/BmcMessageStatusInput.cs
  2. +2
    -0
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs
  3. +1
    -1
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs
  4. +4
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginOrRegisterResponseMessageModel.cs
  5. +69
    -7
      BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs

+ 17
- 0
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/BmcMessageStatusInput.cs View File

@ -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<string> UserId { get; set; }
public long? ScheduleGenerationId { get; set; }
public string Status { get; set; }
public string CompanyUrl { get; set; }
public bool IsSuccess { get; set; }
}
}

+ 2
- 0
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs View File

@ -12,5 +12,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
{ {
public Notification notification { get; set; } public Notification notification { get; set; }
public List<string> FcmToken { get; set; } public List<string> FcmToken { get; set; }
public BmcMessageStatusInput getResponseData { get; set; }
} }
} }

+ 1
- 1
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs View File

@ -24,7 +24,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
public bool Status { get; set; } public bool Status { get; set; }
public List<string> UserId { get; set; } public List<string> UserId { get; set; }
public string CompanyUrl { get; set; } public string CompanyUrl { get; set; }
public string ScheduleGenerationId { get; set; }
public long? ScheduleGenerationId { get; set; }
} }
//[AutoMapFrom(typeof(NotificationModel))] //[AutoMapFrom(typeof(NotificationModel))]


+ 4
- 0
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginOrRegisterResponseMessageModel.cs View File

@ -16,9 +16,13 @@ namespace BCS.BMC.Models.TokenAuth
public int statusCode { get; set; } public int statusCode { get; set; }
public string userName { 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 userId { get; set; }
public string employeeId { get; set; } public string employeeId { get; set; }
public string phoneNo { get; set; } public string phoneNo { get; set; }
public string profilePictureId { get; set; } public string profilePictureId { get; set; }
} }
} }

+ 69
- 7
BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs View File

@ -17,6 +17,8 @@ using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BCS.BMC.Web.Controllers namespace BCS.BMC.Web.Controllers
@ -52,11 +54,29 @@ namespace BCS.BMC.Web.Controllers
public async Task<IActionResult> SendNotification([FromBody] FireBaseResponseModel notification) public async Task<IActionResult> SendNotification([FromBody] FireBaseResponseModel notification)
{ {
var result = await _notificationService.SendNotification(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); 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"; string path = AppDomain.CurrentDomain.BaseDirectory + @"firechat-57601-firebase-adminsdk-anscp-e04366c4d4.json";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path); 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 try
{ {
FirestoreDb db = FirestoreDb.Create("firechat-57601"); FirestoreDb db = FirestoreDb.Create("firechat-57601");
@ -81,9 +101,16 @@ namespace BCS.BMC.Web.Controllers
data.Status = notification.Status; data.Status = notification.Status;
data.UserId = notification.UserId; data.UserId = notification.UserId;
data.CompanyId = companyDetails.Id; data.CompanyId = companyDetails.Id;
data.ScheduleGenerationId = notification.ScheduleGenerationId;
data.ScheduleGenerationId = notification.ScheduleGenerationId.ToString();
await db.Collection("BMC_Notification").Document().SetAsync(data); 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; int userId = 0;
List<string> tokenList = new List<string>(); List<string> tokenList = new List<string>();
foreach (var item in notification.UserId) foreach (var item in notification.UserId)
@ -119,6 +146,7 @@ namespace BCS.BMC.Web.Controllers
//ImageUrl = null //ImageUrl = null
}; };
sendNotificationInfo.notification = notifications; sendNotificationInfo.notification = notifications;
sendNotificationInfo.getResponseData = responseData;
await SendNotification(sendNotificationInfo); await SendNotification(sendNotificationInfo);
} }
catch (Exception ex) catch (Exception ex)
@ -127,5 +155,39 @@ namespace BCS.BMC.Web.Controllers
} }
return Ok(); 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();
}
}
} }
} }

Loading…
Cancel
Save