BMC: Save FCM Token
This commit is contained in:
parent
057349ec60
commit
2de5770939
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using BCS.BMC.Authorization.Roles;
|
||||
using BCS.BMC.Authorization.Users;
|
||||
using BCS.BMC.MultiTenancy;
|
||||
using BCS.BMC.BMC.CompanyMasters;
|
||||
using BCS.BMC.BMC.FirebaseCloudMessages;
|
||||
|
||||
namespace BCS.BMC.EntityFrameworkCore
|
||||
{
|
||||
@ -11,7 +12,8 @@ namespace BCS.BMC.EntityFrameworkCore
|
||||
{
|
||||
/* Define a DbSet for each entity of the application */
|
||||
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)
|
||||
: base(options)
|
||||
{
|
||||
|
2058
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124084114_FirebaeCloudMessageDetails.Designer.cs
generated
Normal file
2058
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124084114_FirebaeCloudMessageDetails.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124113203_FirebaseToken.Designer.cs
generated
Normal file
2102
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124113203_FirebaseToken.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124131235_RemoveIdFrom_FirebaseToken.Designer.cs
generated
Normal file
2102
BCS.BMC/src/BCS.BMC.EntityFrameworkCore/Migrations/20221124131235_RemoveIdFrom_FirebaseToken.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1613,6 +1613,108 @@ namespace BCS.BMC.Migrations
|
||||
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 =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -29,6 +29,7 @@ using System.Text;
|
||||
using System.IO;
|
||||
using Abp.AutoMapper;
|
||||
using Abp.Domain.Entities;
|
||||
using BCS.BMC.BMC.FirebaseCloudMessages;
|
||||
|
||||
namespace BCS.BMC.Controllers
|
||||
{
|
||||
@ -43,6 +44,7 @@ namespace BCS.BMC.Controllers
|
||||
private readonly IExternalAuthManager _externalAuthManager;
|
||||
private readonly UserRegistrationManager _userRegistrationManager;
|
||||
private readonly IRepository<CompanyMaster, int> _companyMaster;
|
||||
private readonly IRepository<FirebaseToken, int> _firebaseToken;
|
||||
ResponseMessageModel responsemessage = new ResponseMessageModel();
|
||||
public TokenAuthController(
|
||||
LogInManager logInManager,
|
||||
@ -52,7 +54,8 @@ namespace BCS.BMC.Controllers
|
||||
IExternalAuthConfiguration externalAuthConfiguration,
|
||||
IExternalAuthManager externalAuthManager,
|
||||
UserRegistrationManager userRegistrationManager,
|
||||
IRepository<CompanyMaster, int> companyMaster)
|
||||
IRepository<CompanyMaster, int> companyMaster,
|
||||
IRepository<FirebaseToken, int> firebaseToken)
|
||||
{
|
||||
_logInManager = logInManager;
|
||||
_tenantCache = tenantCache;
|
||||
@ -62,6 +65,7 @@ namespace BCS.BMC.Controllers
|
||||
_externalAuthManager = externalAuthManager;
|
||||
_userRegistrationManager = userRegistrationManager;
|
||||
_companyMaster = companyMaster;
|
||||
_firebaseToken = firebaseToken;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -313,7 +317,24 @@ namespace BCS.BMC.Controllers
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var responseStream = await response.Content.ReadAsStringAsync();
|
||||
LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream);
|
||||
LoginOrRegisterResponseMessageModel result = JsonConvert.DeserializeObject<LoginOrRegisterResponseMessageModel>(responseStream);
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
FirebaseToken entity = new FirebaseToken();
|
||||
getTokenDetails.FcmToken = input.FcmToken;
|
||||
await _firebaseToken.UpdateAsync(getTokenDetails);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
else if (response.StatusCode == HttpStatusCode.InternalServerError)
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user