BMC: Add More Values fro login API
This commit is contained in:
parent
b8fdcf2561
commit
5509295fd7
@ -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; }
|
||||
}
|
||||
}
|
@ -12,5 +12,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
|
||||
{
|
||||
public Notification notification { get; set; }
|
||||
public List<string> FcmToken { get; set; }
|
||||
|
||||
public BmcMessageStatusInput getResponseData { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
|
||||
public bool Status { get; set; }
|
||||
public List<string> UserId { get; set; }
|
||||
public string CompanyUrl { get; set; }
|
||||
public string ScheduleGenerationId { get; set; }
|
||||
public long? ScheduleGenerationId { get; set; }
|
||||
}
|
||||
|
||||
//[AutoMapFrom(typeof(NotificationModel))]
|
||||
|
@ -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; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user