Compare commits

...

Author SHA1 Message Date
  Palash Biswas a8dea50c2c BMC:CompanyId Validation Message for Registration API 2 years ago
  Palash Biswas 9ecc2c1825 BMC: Validation Message For Company Id in Login API 2 years ago
  Palash Biswas 6180e3356a BMC: Internel server issue in Login API fixed 2 years ago
  Palash Biswas 086ab86095 BMC: Change DataType string to int For CompanyAccountId 2 years ago
  Palash Biswas 838d149d52 BMC: Add CompanyId With Registration response 2 years ago
  Palash Biswas 00af57fd4a BMC: Add CompanyAccountId In LoginInputModel 2 years ago
  Palash Biswas 9798125d18 BMC: Change Conditions for UpdateBmcMessageStatus method 2 years ago
  Palash Biswas e7999cda7d Bmc: Send Error Response 2 years ago
  Palash Biswas 5509295fd7 BMC: Add More Values fro login API 2 years ago
  Palash Biswas b8fdcf2561 BMC: Change Data Type for ScheduleGenerationId 2 years ago
  Palash Biswas 03dbd16d3e BMC: Add ScheduleGenerationId in GetNotifications Method 2 years ago
  Palash Biswas 974989b60a BMC: Validate Ulr From CompanyMaster 2 years ago
  Palash Biswas 097f0f1378 BMC: Send CompanyId in ValidateTenancy Response 2 years ago
  Palash Biswas 3682a17d53 BMC: Change msgSent datetime value in GetNotifications Method 2 years ago
  Palash Biswas 7617b41df0 BMC : Remove id property from NotificationModel 2 years ago
  Palash Biswas 84cb9d4251 BMC: Parameter binding issue in SendNotification Method 2 years ago
  Palash Biswas 7e4fd047f2 BMC: Add fcm token List In GetNotifications Method 2 years ago
  Palash Biswas 91a8f80b32 BMC: Added FireStoreNotificationModel 2 years ago
  Palash Biswas 724930efc9 BMC: Add FirebaseNotification class in NotificationModel Class 2 years ago
  Palash Biswas 2adb716ead BMC: Modification for NitoficationModel Class 2 years ago
  Palash Biswas c93955df68 BMC: Install FireShip sdk 2 years ago
  Palash Biswas 2750b3d25e BMC: Add from body attribute into GetNotification method 2 years ago
  Palash Biswas 02243079b2 BMC:Change controller Name FirebaseNotificationController to NotificationController 2 years ago
  Palash Biswas c38e4e6599 BMC: Add GetNotification Method 2 years ago
  Palash Biswas 9938bbabc7 BMC: Change SendNotification API format 2 years ago
  Palash Biswas f822cc9fe9 BMC: Set FCMTokent In Body 2 years ago
  Palash Biswas 6ef253f537 BMC: FCM token Delete Functionality 2 years ago
  Palash Biswas 2de5770939 BMC: Save FCM Token 2 years ago
35 changed files with 7055 additions and 113 deletions
Unified View
  1. +2
    -0
      BCS.BMC/src/BCS.BMC.Application/BCS.BMC.Application.csproj
  2. +59
    -11
      BCS.BMC/src/BCS.BMC.Application/CompanyMasters/CompanyMasterAppService.cs
  3. +14
    -0
      BCS.BMC/src/BCS.BMC.Application/CompanyMasters/Dto/ValidUrlResponseDto.cs
  4. +1
    -0
      BCS.BMC/src/BCS.BMC.Application/CompanyMasters/ICompanyMasterAppService.cs
  5. +18
    -0
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/BmcMessageStatusInput.cs
  6. +35
    -0
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs
  7. +6
    -5
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs
  8. +23
    -25
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/NotificationModel.cs
  9. +16
    -9
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs
  10. +3
    -1
      BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs
  11. +30
    -0
      BCS.BMC/src/BCS.BMC.Core/BMC/FirebaseCloudMessages/FirebaseCloudMessageDetails.cs
  12. +21
    -0
      BCS.BMC/src/BCS.BMC.Core/BMC/FirebaseCloudMessages/FirebaseToken.cs
  13. +2
    -0
      BCS.BMC/src/BCS.BMC.Core/Localization/SourceFiles/BMC.xml
  14. +3
    -1
      BCS.BMC/src/BCS.BMC.EntityFrameworkCore/EntityFrameworkCore/BMCDbContext.cs
  15. +2058
    -0
      BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124084114_FirebaeCloudMessageDetails.Designer.cs
  16. +45
    -0
      BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124084114_FirebaeCloudMessageDetails.cs
  17. +2102
    -0
      BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124113203_FirebaseToken.Designer.cs
  18. +41
    -0
      BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124113203_FirebaseToken.cs
  19. +2102
    -0
      BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124131235_RemoveIdFrom_FirebaseToken.Designer.cs
  20. +19
    -0
      BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124131235_RemoveIdFrom_FirebaseToken.cs
  21. +102
    -0
      BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/BMCDbContextModelSnapshot.cs
  22. +63
    -6
      BCS.BMC/src/BCS.BMC.Web.Core/Controllers/TokenAuthController.cs
  23. +21
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/CreateOrUpdateFireBaseModel.cs
  24. +14
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/FcmTokenDeleteInput.cs
  25. +22
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/FcmTokenResponseModel.cs
  26. +1
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginInputModel.cs
  27. +5
    -0
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginOrRegisterResponseMessageModel.cs
  28. +1
    -2
      BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/RegistrationInput.cs
  29. +2
    -0
      BCS.BMC/src/BCS.BMC.Web.Mvc/BCS.BMC.Web.Mvc.csproj
  30. +5
    -0
      BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/CompanyMasterController.cs
  31. +0
    -29
      BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs
  32. +176
    -0
      BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs
  33. +12
    -10
      BCS.BMC/src/BCS.BMC.Web.Mvc/Views/CompanyMaster/_CreateModal.cshtml
  34. +7
    -5
      BCS.BMC/src/BCS.BMC.Web.Mvc/Views/CompanyMaster/_EditModal.cshtml
  35. +24
    -9
      BCS.BMC/src/BCS.BMC.Web.Mvc/wwwroot/view-resources/Views/CompanyMaster/Index.js

+ 2
- 0
BCS.BMC/src/BCS.BMC.Application/BCS.BMC.Application.csproj View File

@ -19,6 +19,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FirebaseAdmin" Version="2.3.0" /> <PackageReference Include="FirebaseAdmin" Version="2.3.0" />
<PackageReference Include="FireSharp" Version="2.0.4" />
<PackageReference Include="Google.Cloud.Firestore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.9" /> <PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.9" />
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.9" /> <PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.9" />
</ItemGroup> </ItemGroup>

+ 59
- 11
BCS.BMC/src/BCS.BMC.Application/CompanyMasters/CompanyMasterAppService.cs View File

@ -36,7 +36,8 @@ using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using Newtonsoft.Json; using Newtonsoft.Json;
using Abp.Json; using Abp.Json;
using System.Diagnostics;
using static Grpc.Core.Metadata;
namespace BCS.BMC.CompanyMasters namespace BCS.BMC.CompanyMasters
{ {
@ -125,11 +126,11 @@ namespace BCS.BMC.CompanyMasters
protected async Task<int> Create(CreateOrUpdateCompanyMasterInput input) protected async Task<int> Create(CreateOrUpdateCompanyMasterInput input)
{ {
int companyId = 0; int companyId = 0;
// await GetUrlIsValid(input.Url);
var company = from m in _companyMaster.GetAllList().Where(m => m.Url.ToLower().Trim() == input.Url.ToLower().Trim()) var company = from m in _companyMaster.GetAllList().Where(m => m.Url.ToLower().Trim() == input.Url.ToLower().Trim())
select m;
select m;
var entity = input.MapTo<CompanyMaster>(); var entity = input.MapTo<CompanyMaster>();
// entity.TenantId = AbpSession.TenantId; // entity.TenantId = AbpSession.TenantId;
@ -147,17 +148,64 @@ namespace BCS.BMC.CompanyMasters
} }
} }
entity.DomainName = host; entity.DomainName = host;
if (company == null || company.Count() == 0)
if (company == null || company.Count() == 0)
{ {
companyId = await _companyMaster.InsertAndGetIdAsync(entity); companyId = await _companyMaster.InsertAndGetIdAsync(entity);
} }
else else
{
{
throw new UserFriendlyException("The Input Url Already Exist"); throw new UserFriendlyException("The Input Url Already Exist");
} }
return companyId; return companyId;
} }
public async Task<ValidUrlResponseDto> UrlIsValid(string url)
{
bool istrue = false;
var entity= new ValidUrlResponseDto();
try
{
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
request.Timeout = 5000; //set the timeout to 5 seconds to keep the user from waiting too long for the page to load
request.Method = "HEAD"; //Get only the header information -- no need to download any content
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
int statusCode = (int)response.StatusCode;
if (statusCode >= 100 && statusCode < 400) //Good requests
{
entity.IsSuccess = true;
Uri uri = new Uri(url, UriKind.Absolute);
var host = uri.Host;
if (host.Split('.').Length > 2)
{
int lastIndex = host.LastIndexOf(".");
int index = host.LastIndexOf(".", lastIndex - 1);
var subdomain = host.Substring(0, index);
if (subdomain != "www")
{
entity.TenantName = subdomain;
}
}
}
else if (statusCode >= 500 && statusCode <= 510) //Server Errors
{
//log.Warn(String.Format("The remote server has thrown an internal error. Url is not valid: {0}", url));
Debug.WriteLine(String.Format("The remote server has thrown an internal error. Url is not valid: {0}", url));
istrue = false;
}
}
}
catch (Exception ex)
{
// log.Error(String.Format("Could not test url {0}.", url), ex);
}
return entity;
}
protected async Task Update(CreateOrUpdateCompanyMasterInput input) protected async Task Update(CreateOrUpdateCompanyMasterInput input)
{ {
var entity = await _companyMaster.FirstOrDefaultAsync(x => x.Id == input.Id); var entity = await _companyMaster.FirstOrDefaultAsync(x => x.Id == input.Id);
@ -166,7 +214,7 @@ namespace BCS.BMC.CompanyMasters
//throw new UserFriendlyException(NotFoundRecord ("Name", input.ClientName)); //throw new UserFriendlyException(NotFoundRecord ("Name", input.ClientName));
throw new UserFriendlyException("No Record Found"); throw new UserFriendlyException("No Record Found");
} }
var getclient = from m in _companyMaster.GetAllList() var getclient = from m in _companyMaster.GetAllList()
.Where(m => m.Id == input.Id && m.CompanyName.ToLower().Trim() == input.CompanyName.ToLower().Trim() && m.Id != input.Id) .Where(m => m.Id == input.Id && m.CompanyName.ToLower().Trim() == input.CompanyName.ToLower().Trim() && m.Id != input.Id)
@ -217,11 +265,11 @@ namespace BCS.BMC.CompanyMasters
} }
var company = await _companyMaster.FirstOrDefaultAsync(x => x.Url == input.CompanyUrl.ToString()); var company = await _companyMaster.FirstOrDefaultAsync(x => x.Url == input.CompanyUrl.ToString());
if(company == null)
if (company == null)
{ {
return new HttpStatusCodeResult(HttpStatusCode.BadRequest); return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
} }
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{ {
Uri uri = new Uri(input.CompanyUrl); Uri uri = new Uri(input.CompanyUrl);
@ -245,7 +293,7 @@ namespace BCS.BMC.CompanyMasters
return new HttpStatusCodeResult(HttpStatusCode.OK, responseStream); return new HttpStatusCodeResult(HttpStatusCode.OK, responseStream);
} }
} }
return new HttpStatusCodeResult(HttpStatusCode.OK);
return new HttpStatusCodeResult(HttpStatusCode.OK);
} }
} }
} }

+ 14
- 0
BCS.BMC/src/BCS.BMC.Application/CompanyMasters/Dto/ValidUrlResponseDto.cs View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.CompanyMasters.Dto
{
public class ValidUrlResponseDto
{
public bool IsSuccess { get; set; }
public string TenantName { get; set; }
}
}

+ 1
- 0
BCS.BMC/src/BCS.BMC.Application/CompanyMasters/ICompanyMasterAppService.cs View File

@ -28,5 +28,6 @@ namespace BCS.BMC.CompanyMasters
Task DeleteCompany(EntityDto<int> input); Task DeleteCompany(EntityDto<int> input);
[HttpPost] [HttpPost]
Task<HttpStatusCodeResult> TokenByCompanyUrl(GetInputUrl input); Task<HttpStatusCodeResult> TokenByCompanyUrl(GetInputUrl input);
Task<ValidUrlResponseDto> UrlIsValid(string url);
} }
} }

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

@ -0,0 +1,18 @@
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 List<long> BmcIDs { get; set; }
public string Status { get; set; }
public string CompanyUrl { get; set; }
public bool IsSuccess { get; set; }
}
}

+ 35
- 0
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FireStoreNotificationModel.cs View File

@ -0,0 +1,35 @@
using Google.Cloud.Firestore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.FirebaseCloudMessaging.Dto
{
[FirestoreData]
public class FireStoreNotificationModel
{
[FirestoreProperty]
public string FcmToken { get; set; }
//[FirestoreProperty]
//public List<string> Id { get; set; }
[FirestoreProperty]
public string Message { get; set; }
[FirestoreProperty]
public DateTime? MessageSentDateTime { get; set; }
[FirestoreProperty]
public string SenderImageurl { get; set; }
[FirestoreProperty]
public string SenderName { get; set; }
[FirestoreProperty]
public bool Status { get; set; }
[FirestoreProperty]
public List<string> UserId { get; set; }
[FirestoreProperty]
public int CompanyId { get; set; }
[FirestoreProperty]
public string ScheduleGenerationId { get; set; }
}
}

+ 6
- 5
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/Dto/FirebaseResponseModel.cs View File

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using FirebaseAdmin.Messaging;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,9 +10,9 @@ namespace BCS.BMC.FirebaseCloudMessaging.Dto
{ {
public class FireBaseResponseModel public class FireBaseResponseModel
{ {
[JsonProperty("isSuccess")]
public bool IsSuccess { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
public Notification notification { get; set; }
public List<string> FcmToken { get; set; }
public BmcMessageStatusInput getResponseData { get; set; }
} }
} }

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

@ -1,38 +1,36 @@
using Newtonsoft.Json;
using Abp.AutoMapper;
using BCS.BMC.BMC.FirebaseCloudMessages;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BCS.BMC.FirebaseCloudMessaging.Dto namespace BCS.BMC.FirebaseCloudMessaging.Dto
{ {
[AutoMapTo(typeof (FirebaseCloudMessageDetails))]
public class NotificationModel public class NotificationModel
{ {
[JsonProperty("deviceId")]
public string DeviceId { get; set; }
[JsonProperty("isAndroidDevice")]
public bool IsAndroidDevice { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("body")]
public string Body { get; set; }
}
public string FcmToken { get; set; }
public class GoogleNotification
{
public class DataPayload
{
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("body")]
public string Body { get; set; }
}
[JsonProperty("priority")]
public string Priority { get; set; } = "high";
[JsonProperty("data")]
public DataPayload Data { get; set; }
[JsonProperty("notification")]
public DataPayload Notification { get; set; }
public string Message { get; set; }
public DateTime? MessageSentDateTime { get; set; }
public string SenderImageurl { get; set; }
public string SenderName { get; set; }
public bool Status { get; set; }
public List<string> UserId { get; set; }
public List<long> BmcIDs { get; set; }
public string CompanyUrl { get; set; }
public long? ScheduleGenerationId { get; set; }
} }
//[AutoMapFrom(typeof(NotificationModel))]
//public class FirebaseNotification : NotificationModel
//{
// public List<string> Id { get; set; }
//}
} }

+ 16
- 9
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/FirebaseNotificationAppService.cs View File

@ -3,7 +3,10 @@ using System.Threading.Tasks;
using FirebaseAdmin; using FirebaseAdmin;
using Google.Apis.Auth.OAuth2; using Google.Apis.Auth.OAuth2;
using System; using System;
using BCS.BMC.FirebaseCloudMessaging.Dto;
using System.Collections.Generic;
using Abp.Json;
using Microsoft.Extensions.Logging;
namespace BCS.BMC.FirebaseCloudMessaging namespace BCS.BMC.FirebaseCloudMessaging
{ {
@ -22,23 +25,27 @@ namespace BCS.BMC.FirebaseCloudMessaging
} }
public static async Task<string> SendNotification(string fcmToken, Notification notification)
public async Task<BatchResponse> SendNotification(FireBaseResponseModel notification)
{ {
try try
{ {
var message = new Message()
var message = new MulticastMessage()
{ {
Notification = notification,
Token = fcmToken,
Notification = notification.notification,
Tokens = notification.FcmToken,
}; };
return await FirebaseMessaging.DefaultInstance.SendAsync(message) ;
var response = await FirebaseMessaging.DefaultInstance.SendMulticastAsync(message);
return response;
} }
catch(Exception ex)
catch (Exception ex)
{ {
throw ex; throw ex;
} }
}
}
public async Task GetNotification(NotificationModel notification)
{
var data = notification;
}
} }
} }

+ 3
- 1
BCS.BMC/src/BCS.BMC.Application/FirebaseCloudMessaging/IFirebaseNotificationAppService.cs View File

@ -1,4 +1,5 @@
using Abp.Application.Services; using Abp.Application.Services;
using BCS.BMC.FirebaseCloudMessaging.Dto;
using FirebaseAdmin.Messaging; using FirebaseAdmin.Messaging;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -6,6 +7,7 @@ namespace BCS.BMC.FirebaseCloudMessaging
{ {
public interface IFirebaseNotificationAppService : IApplicationService public interface IFirebaseNotificationAppService : IApplicationService
{ {
// Task<string> SendNotification(string fcmToken, Notification notification);
Task<BatchResponse> SendNotification(FireBaseResponseModel notification);
Task GetNotification(NotificationModel notification);
} }
} }

+ 30
- 0
BCS.BMC/src/BCS.BMC.Core/BMC/FirebaseCloudMessages/FirebaseCloudMessageDetails.cs View File

@ -0,0 +1,30 @@
using Abp.Domain.Entities.Auditing;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.BMC.FirebaseCloudMessages
{
[Table("FirebaseCloudMessageDetails")]
public class FirebaseCloudMessageDetails : FullAuditedEntity
{
public const int SenderNameMaxLength = 32;
public const int SenderImageurlMaxLength = 256;
public const int FcmTokenMaxLength = 512;
public int Id { get; set; }
public int UserId { get; set; }
[MaxLength(FcmTokenMaxLength)]
public string FcmToken { get; set; }
[MaxLength(SenderImageurlMaxLength)]
public string SenderImageurl { get; set; }
[MaxLength(SenderNameMaxLength)]
public string SenderName { get; set; }
public DateTime? MessageSentDateTime { get; set; }
public bool Status { get; set; }
public string Message { get; set; }
}
}

+ 21
- 0
BCS.BMC/src/BCS.BMC.Core/BMC/FirebaseCloudMessages/FirebaseToken.cs View File

@ -0,0 +1,21 @@
using Abp.Domain.Entities.Auditing;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.BMC.FirebaseCloudMessages
{
[Table("FirebaseToken")]
public class FirebaseToken : FullAuditedEntity
{
public const int HostNameMaxLength = 512;
public int? UserId { get; set; }
[MaxLength(HostNameMaxLength)]
public string HostName { get; set; }
public string FcmToken { get; set; }
}
}

+ 2
- 0
BCS.BMC/src/BCS.BMC.Core/Localization/SourceFiles/BMC.xml View File

@ -126,5 +126,7 @@
<text name="CompanyMaster">Company Master</text> <text name="CompanyMaster">Company Master</text>
<text name="Url">Url</text> <text name="Url">Url</text>
<text name="Id">Id</text> <text name="Id">Id</text>
<text name="CreateNewCompany">Create New Company</text>
<text name="EditCompany">Edit Company</text>
</texts> </texts>
</localizationDictionary> </localizationDictionary>

+ 3
- 1
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/EntityFrameworkCore/BMCDbContext.cs View File

@ -4,6 +4,7 @@ using BCS.BMC.Authorization.Roles;
using BCS.BMC.Authorization.Users; using BCS.BMC.Authorization.Users;
using BCS.BMC.MultiTenancy; using BCS.BMC.MultiTenancy;
using BCS.BMC.BMC.CompanyMasters; using BCS.BMC.BMC.CompanyMasters;
using BCS.BMC.BMC.FirebaseCloudMessages;
namespace BCS.BMC.EntityFrameworkCore namespace BCS.BMC.EntityFrameworkCore
{ {
@ -11,7 +12,8 @@ namespace BCS.BMC.EntityFrameworkCore
{ {
/* Define a DbSet for each entity of the application */ /* Define a DbSet for each entity of the application */
public virtual DbSet<CompanyMaster> CompanyMasters { get; set; } public virtual DbSet<CompanyMaster> CompanyMasters { get; set; }
public virtual DbSet<FirebaseCloudMessageDetails> FirebaseCloudMessageDetail { get; set; }
public virtual DbSet<FirebaseToken> FirebaseTokens { get; set; }
public BMCDbContext(DbContextOptions<BMCDbContext> options) public BMCDbContext(DbContextOptions<BMCDbContext> options)
: base(options) : base(options)
{ {


+ 2058
- 0
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124084114_FirebaeCloudMessageDetails.Designer.cs
File diff suppressed because it is too large
View File


+ 45
- 0
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124084114_FirebaeCloudMessageDetails.cs View File

@ -0,0 +1,45 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BCS.BMC.Migrations
{
public partial class FirebaeCloudMessageDetails : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "FirebaseCloudMessageDetails",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: false),
FcmToken = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
SenderImageurl = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
SenderName = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
MessageSentDateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
Status = table.Column<bool>(type: "bit", nullable: false),
Message = table.Column<string>(type: "nvarchar(max)", nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorUserId = table.Column<long>(type: "bigint", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifierUserId = table.Column<long>(type: "bigint", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
DeleterUserId = table.Column<long>(type: "bigint", nullable: true),
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FirebaseCloudMessageDetails", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "FirebaseCloudMessageDetails");
}
}
}

+ 2102
- 0
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124113203_FirebaseToken.Designer.cs
File diff suppressed because it is too large
View File


+ 41
- 0
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124113203_FirebaseToken.cs View File

@ -0,0 +1,41 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BCS.BMC.Migrations
{
public partial class FirebaseToken : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "FirebaseToken",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(type: "int", nullable: true),
HostName = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
FcmToken = table.Column<string>(type: "nvarchar(max)", nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorUserId = table.Column<long>(type: "bigint", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifierUserId = table.Column<long>(type: "bigint", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
DeleterUserId = table.Column<long>(type: "bigint", nullable: true),
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_FirebaseToken", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "FirebaseToken");
}
}
}

+ 2102
- 0
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124131235_RemoveIdFrom_FirebaseToken.Designer.cs
File diff suppressed because it is too large
View File


+ 19
- 0
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124131235_RemoveIdFrom_FirebaseToken.cs View File

@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BCS.BMC.Migrations
{
public partial class RemoveIdFrom_FirebaseToken : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

+ 102
- 0
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/BMCDbContextModelSnapshot.cs View File

@ -1613,6 +1613,108 @@ namespace BCS.BMC.Migrations
b.ToTable("CompanyMaster"); b.ToTable("CompanyMaster");
}); });
modelBuilder.Entity("BCS.BMC.BMC.FirebaseCloudMessages.FirebaseCloudMessageDetails", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2");
b.Property<long?>("CreatorUserId")
.HasColumnType("bigint");
b.Property<long?>("DeleterUserId")
.HasColumnType("bigint");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime2");
b.Property<string>("FcmToken")
.HasMaxLength(512)
.HasColumnType("nvarchar(512)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime2");
b.Property<long?>("LastModifierUserId")
.HasColumnType("bigint");
b.Property<string>("Message")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("MessageSentDateTime")
.HasColumnType("datetime2");
b.Property<string>("SenderImageurl")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("SenderName")
.HasMaxLength(32)
.HasColumnType("nvarchar(32)");
b.Property<bool>("Status")
.HasColumnType("bit");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("FirebaseCloudMessageDetails");
});
modelBuilder.Entity("BCS.BMC.BMC.FirebaseCloudMessages.FirebaseToken", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2");
b.Property<long?>("CreatorUserId")
.HasColumnType("bigint");
b.Property<long?>("DeleterUserId")
.HasColumnType("bigint");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime2");
b.Property<string>("FcmToken")
.HasColumnType("nvarchar(max)");
b.Property<string>("HostName")
.HasMaxLength(512)
.HasColumnType("nvarchar(512)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime2");
b.Property<long?>("LastModifierUserId")
.HasColumnType("bigint");
b.Property<int?>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("FirebaseToken");
});
modelBuilder.Entity("BCS.BMC.MultiTenancy.Tenant", b => modelBuilder.Entity("BCS.BMC.MultiTenancy.Tenant", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")


+ 63
- 6
BCS.BMC/src/BCS.BMC.Web.Core/Controllers/TokenAuthController.cs View File

@ -29,6 +29,7 @@ using System.Text;
using System.IO; using System.IO;
using Abp.AutoMapper; using Abp.AutoMapper;
using Abp.Domain.Entities; using Abp.Domain.Entities;
using BCS.BMC.BMC.FirebaseCloudMessages;
namespace BCS.BMC.Controllers namespace BCS.BMC.Controllers
{ {
@ -43,6 +44,7 @@ namespace BCS.BMC.Controllers
private readonly IExternalAuthManager _externalAuthManager; private readonly IExternalAuthManager _externalAuthManager;
private readonly UserRegistrationManager _userRegistrationManager; private readonly UserRegistrationManager _userRegistrationManager;
private readonly IRepository<CompanyMaster, int> _companyMaster; private readonly IRepository<CompanyMaster, int> _companyMaster;
private readonly IRepository<FirebaseToken, int> _firebaseToken;
ResponseMessageModel responsemessage = new ResponseMessageModel(); ResponseMessageModel responsemessage = new ResponseMessageModel();
public TokenAuthController( public TokenAuthController(
LogInManager logInManager, LogInManager logInManager,
@ -52,7 +54,8 @@ namespace BCS.BMC.Controllers
IExternalAuthConfiguration externalAuthConfiguration, IExternalAuthConfiguration externalAuthConfiguration,
IExternalAuthManager externalAuthManager, IExternalAuthManager externalAuthManager,
UserRegistrationManager userRegistrationManager, UserRegistrationManager userRegistrationManager,
IRepository<CompanyMaster, int> companyMaster)
IRepository<CompanyMaster, int> companyMaster,
IRepository<FirebaseToken, int> firebaseToken)
{ {
_logInManager = logInManager; _logInManager = logInManager;
_tenantCache = tenantCache; _tenantCache = tenantCache;
@ -62,6 +65,7 @@ namespace BCS.BMC.Controllers
_externalAuthManager = externalAuthManager; _externalAuthManager = externalAuthManager;
_userRegistrationManager = userRegistrationManager; _userRegistrationManager = userRegistrationManager;
_companyMaster = companyMaster; _companyMaster = companyMaster;
_firebaseToken = firebaseToken;
} }
[HttpPost] [HttpPost]
@ -263,7 +267,12 @@ namespace BCS.BMC.Controllers
{ {
return BadRequest("Url Not Found"); return BadRequest("Url Not Found");
} }
return Ok("Success");
var result = new
{
CompanyId = company.Id,
};
return Ok(result);
} }
[HttpPost] [HttpPost]
@ -273,7 +282,7 @@ namespace BCS.BMC.Controllers
var protocol = ""; var protocol = "";
if (string.IsNullOrWhiteSpace(input.CompanyUrl)) if (string.IsNullOrWhiteSpace(input.CompanyUrl))
{ {
return BadRequest("Please Enter A Valid Url");
return BadRequest("Please enter a valid Url");
} }
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{ {
@ -296,6 +305,11 @@ namespace BCS.BMC.Controllers
{ {
return BadRequest("Invalid Company Url"); return BadRequest("Invalid Company Url");
} }
var companyAccountId = await _companyMaster.FirstOrDefaultAsync(x => x.CompanyName == input.CompanyId);
if (companyAccountId == null)
{
return BadRequest("Please enter valid Company Account ID");
}
// var baseUrl = uri + "api/BmcLogin"; // var baseUrl = uri + "api/BmcLogin";
var baseUrl = protocol + "://" + host + "/api/BmcLogin"; var baseUrl = protocol + "://" + host + "/api/BmcLogin";
@ -309,19 +323,36 @@ namespace BCS.BMC.Controllers
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json"); requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent); HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {
var responseStream = await response.Content.ReadAsStringAsync(); var responseStream = await response.Content.ReadAsStringAsync();
LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream); LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream);
result.result.CompanyId = company.Id;
var getTokenDetails = _firebaseToken.GetAllList().Where(x => x.HostName == host && x.UserId == int.Parse(result.result.userId)).FirstOrDefault();
if (getTokenDetails is null)
{
FirebaseToken entity = new FirebaseToken();
entity.UserId = int.Parse(result.result.userId);
entity.HostName = host;
entity.FcmToken = input.FcmToken;
await _firebaseToken.InsertAndGetIdAsync(entity);
}
if (getTokenDetails != null)
{
getTokenDetails.FcmToken = input.FcmToken;
await _firebaseToken.UpdateAsync(getTokenDetails);
}
return Ok(result); return Ok(result);
} }
else if (response.StatusCode == HttpStatusCode.InternalServerError) else if (response.StatusCode == HttpStatusCode.InternalServerError)
{ {
var contents = await response.Content.ReadAsStringAsync(); var contents = await response.Content.ReadAsStringAsync();
ResponseMessageModel result = JsonConvert.DeserializeObject<ResponseMessageModel>(contents); ResponseMessageModel result = JsonConvert.DeserializeObject<ResponseMessageModel>(contents);
return BadRequest(result.error.message == "Login Failed" ? "Invalid Username Or Password" : result.error.message);
return BadRequest(result.error.message == "Login Failed" ? "Please enter valid Username or Password" : result.error.message);
} }
return Ok(); return Ok();
} }
@ -342,6 +373,11 @@ namespace BCS.BMC.Controllers
{ {
return BadRequest("Url Not Found"); return BadRequest("Url Not Found");
} }
var companyAccountId = await _companyMaster.FirstOrDefaultAsync(x => x.CompanyName == input.CompanyAccountId);
if (companyAccountId == null)
{
return BadRequest("Please enter valid Company Account ID");
}
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{ {
var baseUrl = input.CompanyUrl + "/api/services/bwac/employeeRegister/RegisterEmployeeAsNewUser"; var baseUrl = input.CompanyUrl + "/api/services/bwac/employeeRegister/RegisterEmployeeAsNewUser";
@ -362,6 +398,7 @@ namespace BCS.BMC.Controllers
{ {
var responseStream = await response.Content.ReadAsStringAsync(); var responseStream = await response.Content.ReadAsStringAsync();
LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream); LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream);
result.result.CompanyId = company.Id;
return Ok(result); return Ok(result);
} }
else if (response.StatusCode == HttpStatusCode.InternalServerError) else if (response.StatusCode == HttpStatusCode.InternalServerError)
@ -373,5 +410,25 @@ namespace BCS.BMC.Controllers
} }
return BadRequest(); return BadRequest();
} }
[HttpPost]
public async Task<IActionResult> DeleteRegisteredFcmToken([FromBody] FcmTokenDeleteInput input)
{
Uri uri = new Uri(input.HostName);
var host = uri.Host;
var getTokenDetails = _firebaseToken.GetAllList().Where(x => x.HostName == host && x.UserId == input.UserId).FirstOrDefault();
if (getTokenDetails != null)
{
FirebaseToken entity = new FirebaseToken();
getTokenDetails.FcmToken = null;
await _firebaseToken.UpdateAsync(getTokenDetails);
}
else
{
return BadRequest("logout failed");
}
return Ok("Success");
}
} }
} }

+ 21
- 0
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/CreateOrUpdateFireBaseModel.cs View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BCS.BMC.BMC.CompanyMasters;
using Abp.AutoMapper;
using BCS.BMC.BMC.FirebaseCloudMessages;
namespace BCS.BMC.Models.TokenAuth
{
[AutoMap(typeof(FirebaseToken))]
public class CreateOrUpdateFireBaseModel
{
public int? UserId { get; set; }
public string HostName { get; set; }
public string FcmToken { get; set; }
}
}

+ 14
- 0
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/FcmTokenDeleteInput.cs View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.Models.TokenAuth
{
public class FcmTokenDeleteInput
{
public int UserId { get; set; }
public string HostName { get; set; }
}
}

+ 22
- 0
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/FcmTokenResponseModel.cs View File

@ -0,0 +1,22 @@
using FirebaseAdmin.Messaging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCS.BMC.Models.TokenAuth
{
public class FcmTokenResponseModel
{
public result results { get; set; }
}
public class results
{
public string message { get; set; }
}
}

+ 1
- 0
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/LoginInputModel.cs View File

@ -9,6 +9,7 @@ namespace BCS.BMC.Models.TokenAuth
public class LoginInputModel public class LoginInputModel
{ {
public string CompanyUrl { get; set; } public string CompanyUrl { get; set; }
public string CompanyId { get; set; }
public string UsernameOrEmailAddress { get; set; } public string UsernameOrEmailAddress { get; set; }
public string Password { get; set; } public string Password { get; set; }
public string FcmToken { get; set; } public string FcmToken { get; set; }


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

@ -16,9 +16,14 @@ 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; }
public int? CompanyId { get; set; }
} }
} }

+ 1
- 2
BCS.BMC/src/BCS.BMC.Web.Core/Models/TokenAuth/RegistrationInput.cs View File

@ -8,8 +8,7 @@ namespace BCS.BMC.Models.TokenAuth
{ {
public class RegistrationInput public class RegistrationInput
{ {
public string Firstname { get; set; }
public string Lastname { get; set; }
public string CompanyAccountId { get; set; }
public string UserNameOrEmail { get; set; } public string UserNameOrEmail { get; set; }
public string Phoneno { get; set; } public string Phoneno { get; set; }
public string Password { get; set; } public string Password { get; set; }


+ 2
- 0
BCS.BMC/src/BCS.BMC.Web.Mvc/BCS.BMC.Web.Mvc.csproj View File

@ -32,6 +32,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" /> <PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="FireSharp" Version="2.0.4" />
<PackageReference Include="Google.Cloud.Firestore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.4" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.4"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.4">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>


+ 5
- 0
BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/CompanyMasterController.cs View File

@ -37,5 +37,10 @@ namespace BCS.BMC.Web.Controllers
return PartialView("_EditModal", output); return PartialView("_EditModal", output);
} }
//public async Task<bool> GetUrlIsValid(string url)
//{
// bool isSuccess = await _companyasterService.GetUrlIsValid(url);
// return isSuccess;
//}
} }
} }

+ 0
- 29
BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/FirebaseNotificationController.cs View File

@ -1,29 +0,0 @@
using BCS.BMC.Controllers;
using BCS.BMC.FirebaseCloudMessaging;
using FirebaseAdmin.Messaging;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace BCS.BMC.Web.Controllers
{
//[Route("api/notification")]
//[ApiController]
public class FirebaseNotificationController : BMCControllerBase
{
private readonly FirebaseNotificationAppService _notificationService;
public FirebaseNotificationController(FirebaseNotificationAppService notificationService)
{
_notificationService = notificationService;
}
[Route("send")]
[HttpPost]
public async Task<IActionResult> Notification(string fcmToken, [FromBody] Notification notification)
{
var result = await FirebaseNotificationAppService.SendNotification(fcmToken, notification);
return Ok(result);
}
}
}

+ 176
- 0
BCS.BMC/src/BCS.BMC.Web.Mvc/Controllers/NotificationController.cs View File

@ -0,0 +1,176 @@
using Abp.AutoMapper;
using Abp.Domain.Repositories;
using Abp.Json;
using BCS.BMC.BMC.CompanyMasters;
using BCS.BMC.BMC.FirebaseCloudMessages;
using BCS.BMC.Controllers;
using BCS.BMC.FirebaseCloudMessaging;
using BCS.BMC.FirebaseCloudMessaging.Dto;
using BCS.BMC.Models.TokenAuth;
using FirebaseAdmin.Messaging;
using FireSharp.Config;
using FireSharp.Interfaces;
using FireSharp.Response;
using Google.Cloud.Firestore;
using Microsoft.AspNetCore.Mvc;
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
{
[Route("api/[controller]/[action]")]
public class NotificationController : BMCControllerBase
{
private readonly IFirebaseNotificationAppService _notificationService;
private readonly IRepository<FirebaseCloudMessageDetails> _firebaseCloudMessageDetails;
private readonly IRepository<FirebaseToken, int> _firebaseToken;
private readonly IRepository<CompanyMaster, int> _companyMasterService;
//IFirebaseConfig config = new FirebaseConfig
//{
// AuthSecret = "n6DTPQEbpnLahrrk2EYu4bJ2Wd3jCk2N8kocazdI",
// BasePath = "https://firechat-57601-default-rtdb.europe-west1.firebasedatabase.app/"
//};
//IFirebaseClient client;
public NotificationController(IFirebaseNotificationAppService notificationService,
IRepository<FirebaseCloudMessageDetails> firebaseCloudMessageDetails,
IRepository<FirebaseToken, int> firebaseToken,
IRepository<CompanyMaster, int> companyMasterService)
{
_notificationService = notificationService;
_firebaseCloudMessageDetails = firebaseCloudMessageDetails;
_firebaseToken = firebaseToken;
_companyMasterService = companyMasterService;
}
[HttpPost]
public async Task<IActionResult> SendNotification([FromBody] FireBaseResponseModel notification)
{
var result = await _notificationService.SendNotification(notification);
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);
}
[HttpPost]
public async Task<IActionResult> GetNotifications([FromBody] NotificationModel notification)
{
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();
try
{
FirestoreDb db = FirestoreDb.Create("firechat-57601");
FireStoreNotificationModel data = new FireStoreNotificationModel();
data.FcmToken = notification.FcmToken;
// data.Id = notification.Id;
data.Message = notification.Message;
data.MessageSentDateTime = notification.MessageSentDateTime;
//data.MessageSentDateTime = DateTime.UtcNow;
data.SenderImageurl = notification.SenderImageurl;
data.SenderName = notification.SenderName;
data.Status = notification.Status;
data.UserId = notification.UserId;
data.CompanyId = companyDetails.Id;
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;
responseData.BmcIDs = notification.BmcIDs;
}
int userId = 0;
List<string> tokenList = new List<string>();
foreach (var item in notification.UserId)
{
userId = Convert.ToInt32(item);
var getTokenDetails = _firebaseToken.GetAllList().Where(x => x.UserId == userId).FirstOrDefault();
tokenList.Add(getTokenDetails.FcmToken.ToString());
var entity = new FirebaseCloudMessageDetails();
entity.UserId = userId;
entity.SenderImageurl = notification.SenderImageurl;
entity.SenderName = notification.SenderName;
entity.MessageSentDateTime = notification.MessageSentDateTime;
entity.Status = notification.Status;
entity.Message = notification.Message;
if (entity != null)
{
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;
sendNotificationInfo.getResponseData = responseData;
await SendNotification(sendNotificationInfo);
}
catch (Exception ex)
{
}
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";
using (HttpClient client = new HttpClient())
{
var requestJson = JsonConvert.SerializeObject(bmcMessageStatusInput);
var requestContent = new StringContent(requestJson.ToString());
requestContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
HttpResponseMessage response = await client.PostAsync(baseUrl, requestContent);
return Ok();
}
}
}
}

+ 12
- 10
BCS.BMC/src/BCS.BMC.Web.Mvc/Views/CompanyMaster/_CreateModal.cshtml View File

@ -12,7 +12,7 @@
<div class="modal fade" id="ClientMasterCreateModal" tabindex="-1" role="dialog" aria-labelledby="UserCreateModalLabel" data-backdrop="static"> <div class="modal fade" id="ClientMasterCreateModal" tabindex="-1" role="dialog" aria-labelledby="UserCreateModalLabel" data-backdrop="static">
<div class="modal-dialog modal-lg" role="document"> <div class="modal-dialog modal-lg" role="document">
<div class="modal-content"> <div class="modal-content">
@* @await Html.PartialAsync("~/Views/Shared/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("CreateNewUser")))*@
@await Html.PartialAsync("~/Views/Shared/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("CreateNewCompany")))
<form name="clientMasterCreateForm" role="form" class="form-horizontal"> <form name="clientMasterCreateForm" role="form" class="form-horizontal">
<div class="modal-body"> <div class="modal-body">
@*<ul class="nav nav-tabs" role="tablist"> @*<ul class="nav nav-tabs" role="tablist">
@ -24,20 +24,22 @@
</li> </li>
</ul>*@ </ul>*@
<div class="tab-content mt-4"> <div class="tab-content mt-4">
<div role="tabpanel" class="tab-pane container active" id="create-client-details">
<div role="tabpanel" class="tab-pane container active" id="create-client-details">
<div class="form-group row required"> <div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Company")</label>
<div class="col-md-9">
<input type="text" class="form-control" name="CompanyName" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
<label class="col-md-2 col-form-label">@L("Url")</label>
<div class="col-md-8">
<input type="text" class="form-control" id="Url" name="Url" required>
</div> </div>
<input type="submit" value="Check Url" class="btn btn-secondary btn-sm download-button" name="submit">
</div> </div>
<div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Url")</label>
<div class="col-md-9">
<input type="text" class="form-control" name="Url" required maxlength="@AbpUserBase.MaxNameLength">
<div class="form-group row" id="div_CompanyName" style="visibility : hidden">
<label class="col-md-2 col-form-label">@L("Company")</label>
<div class="col-md-8">
<input type="text" class="form-control" name="CompanyName" id="CompanyName" readonly>
</div> </div>
</div> </div>
@* <div class="form-group row required">
@* <div class="form-group row required">
<label class="col-md-3 col-form-label">@L("ClientSubDomainName")</label> <label class="col-md-3 col-form-label">@L("ClientSubDomainName")</label>
<div class="col-md-9"> <div class="col-md-9">
<input type="text" class="form-control" name="ClientSubDomainName" required maxlength="@AbpUserBase.MaxSurnameLength"> <input type="text" class="form-control" name="ClientSubDomainName" required maxlength="@AbpUserBase.MaxSurnameLength">


+ 7
- 5
BCS.BMC/src/BCS.BMC.Web.Mvc/Views/CompanyMaster/_EditModal.cshtml View File

@ -6,7 +6,7 @@
@{ @{
Layout = null; Layout = null;
} }
@await Html.PartialAsync("~/Views/Shared/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("EditCompany")))
<form name="EditCompanyForm" role="form" class="form-horizontal"> <form name="EditCompanyForm" role="form" class="form-horizontal">
<input type="hidden" name="Id" value="@Model.Id" /> <input type="hidden" name="Id" value="@Model.Id" />
<input type="hidden" name="DomainName" value="@Model.DomainName" /> <input type="hidden" name="DomainName" value="@Model.DomainName" />
@ -24,17 +24,19 @@
<div class="tab-content mt-4"> <div class="tab-content mt-4">
<div role="tabpanel" class="tab-pane container active" id="edit-company-details"> <div role="tabpanel" class="tab-pane container active" id="edit-company-details">
<div class="form-group row required"> <div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Company")</label>
<label class="col-md-3 col-form-label">@L("Url")</label>
<div class="col-md-9"> <div class="col-md-9">
<input id="CompanyName" type="text" class="form-control" name="CompanyName" value="@Model.CompanyName" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
<input id="url" type="text" class="form-control" name="Url" value="@Model.Url" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
</div> </div>
</div> </div>
<div class="form-group row required"> <div class="form-group row required">
<label class="col-md-3 col-form-label">@L("Domain")</label>
<label class="col-md-3 col-form-label">@L("Company")</label>
<div class="col-md-9"> <div class="col-md-9">
<input id="url" type="text" class="form-control" name="Url" value="@Model.Url" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
<input id="CompanyName" type="text" class="form-control" name="CompanyName" value="@Model.CompanyName" required maxlength="@AbpUserBase.MaxUserNameLength" minlength="2">
</div> </div>
</div> </div>
@* <div class="form-group row required"> @* <div class="form-group row required">
<label class="col-md-3 col-form-label">@L("ClientSubDomainName")</label> <label class="col-md-3 col-form-label">@L("ClientSubDomainName")</label>
<div class="col-md-9"> <div class="col-md-9">


+ 24
- 9
BCS.BMC/src/BCS.BMC.Web.Mvc/wwwroot/view-resources/Views/CompanyMaster/Index.js View File

@ -1,9 +1,9 @@
(function ($) { (function ($) {
var _companyService = abp.services.app.companyMaster var _companyService = abp.services.app.companyMaster
l = abp.localization.getSource('BMC'),
_$modal = $('#ClientMasterCreateModal'),
l = abp.localization.getSource('BMC'),
_$modal = $('#ClientMasterCreateModal'),
_$form = _$modal.find('form'), _$form = _$modal.find('form'),
_$table = $('#CompanyMasterTable');
_$table = $('#CompanyMasterTable');
var _$companyTable = _$table.DataTable({ var _$companyTable = _$table.DataTable({
paging: true, paging: true,
@ -42,12 +42,12 @@
targets: 2, targets: 2,
data: 'companyName', data: 'companyName',
sortable: false sortable: false
}, { }, {
targets: 3, targets: 3,
data: 'url', data: 'url',
sortable: false
},{
sortable: false
}, {
targets: 4, targets: 4,
data: 'domainName', data: 'domainName',
sortable: false sortable: false
@ -56,7 +56,7 @@
targets: 5, targets: 5,
data: 'subDomainName', data: 'subDomainName',
sortable: false sortable: false
},{
}, {
targets: 6, targets: 6,
data: null, data: null,
sortable: false, sortable: false,
@ -70,7 +70,7 @@
` <button type="button" class="btn btn-sm bg-danger delete-company" data-tenant-id="${row.id}" data-company-name="${row.name}">`, ` <button type="button" class="btn btn-sm bg-danger delete-company" data-tenant-id="${row.id}" data-company-name="${row.name}">`,
` <i class="fas fa-trash"></i> ${l('Delete')}`, ` <i class="fas fa-trash"></i> ${l('Delete')}`,
' </button>' ' </button>'
].join(''); ].join('');
} }
} }
@ -84,9 +84,24 @@
$('input[type="checkbox"]', rows).prop('checked', this.checked); $('input[type="checkbox"]', rows).prop('checked', this.checked);
}); });
_$form.find('.save-button').on('click', (e) => {
_$form.find('.download-button').on('click', (e) => {
e.preventDefault(); e.preventDefault();
var companydetails = _$form.serializeFormToObject();
//abp.ui.setBusy();
var companyUrl = companydetails.Url;
abp.notify.info(l('ValidatingUrl'));
var data = _companyService.urlIsValid(companyUrl);
data.done(function (result) {
$('#div_CompanyName').attr("style", "visibility : visible");
$('#CompanyName').val(result.tenantName);
});
})
_$form.find('.save-button').on('click', (e) => {
e.preventDefault();
if (!_$form.valid()) { if (!_$form.valid()) {
return; return;
} }


Loading…
Cancel
Save