mirror of
https://github.com/yawaflua/PL_JusticeBot.git
synced 2025-12-08 19:39:27 +02:00
add notary module, utilities and server online in bot`s game
This commit is contained in:
@@ -50,7 +50,7 @@ namespace DiscordApp.Auth
|
|||||||
|
|
||||||
private bool IsValidApiKey(string apiKey)
|
private bool IsValidApiKey(string apiKey)
|
||||||
{
|
{
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
private bool CheckForInvalidCharacters(string value)
|
private bool CheckForInvalidCharacters(string value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,12 +29,6 @@ namespace DiscordApp.Controllers
|
|||||||
})
|
})
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
public static async Task<bool> isAllowed(IServiceProvider services)
|
|
||||||
{
|
|
||||||
var context = services.GetRequiredService<ActionContext>();
|
|
||||||
if (context.HttpContext.Request.Cookies["geff"] == "ok") { return true; }
|
|
||||||
else { return false; }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ namespace DiscordApp.Database.Tables
|
|||||||
public DateOnly Date { get; set; }
|
public DateOnly Date { get; set; }
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
public int DocumentId { get; set; }
|
public int DocumentId { get; set; }
|
||||||
|
public string DocumentType { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ namespace DiscordApp.Justice.Interactions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
User spApplicant = await User.CreateUser(applicant.Applicant);
|
User spApplicant = await User.CreateUser(applicant.Applicant);
|
||||||
var employees = new List<int>();
|
var employees = new List<int>
|
||||||
employees.Add(applicant.Id);
|
{
|
||||||
|
applicant.Id
|
||||||
|
};
|
||||||
|
|
||||||
Bizness biznessDB = new()
|
Bizness biznessDB = new()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
using Discord.Interactions;
|
using Discord;
|
||||||
|
using Discord.Interactions;
|
||||||
|
using DiscordApp.Database.Tables;
|
||||||
using DiscordApp.Justice.Modals;
|
using DiscordApp.Justice.Modals;
|
||||||
|
using DiscordApp.Types;
|
||||||
using DiscordApp.Utilities;
|
using DiscordApp.Utilities;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace DiscordApp.Justice.Interactions
|
namespace DiscordApp.Justice.Interactions
|
||||||
{
|
{
|
||||||
@@ -17,19 +21,75 @@ namespace DiscordApp.Justice.Interactions
|
|||||||
int passportId;
|
int passportId;
|
||||||
int documentId;
|
int documentId;
|
||||||
int certificateId;
|
int certificateId;
|
||||||
|
string thumbnailUrl;
|
||||||
|
Passport passport;
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
IdChecker.IdLenghtIsLower(out certificateId);
|
Utilities.Utilities.IdGenerator(out certificateId);
|
||||||
documentId = Startup.appDbContext.Certificates.OrderBy(t => t.Id).First().Id + 1;
|
documentId = Startup.appDbContext.Certificates.OrderBy(t => t.Id).FirstOrDefault().Id;
|
||||||
bool isInt = int.TryParse(modal.passportId, out passportId);
|
documentId += 1;
|
||||||
if (!isInt)
|
if (!int.TryParse(modal.passportId, out passportId))
|
||||||
{
|
{
|
||||||
await FollowupAsync($"Айди паспорта еще старое, попробуй использовать другого бота.", ephemeral: true);
|
await FollowupAsync($"Айди паспорта еще старое, попробуй использовать другого бота.", ephemeral: true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (Startup.appDbContext.Passport.Find(passportId) == null)
|
else if (Utilities.Utilities.IsPassport(passportId, out passport))
|
||||||
{
|
{
|
||||||
await FollowupAsync($"Паспорт не найден в базе данных, попробуй написать правильно", ephemeral: true);
|
await FollowupAsync($"Паспорт не найден в базе данных, попробуй написать правильно", ephemeral: true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Certificate certificate = new()
|
||||||
|
{
|
||||||
|
Date = DateOnly.FromDateTime(DateTime.Now),
|
||||||
|
DocumentId = documentId,
|
||||||
|
Employee = ((IGuildUser)Context.User).DisplayName,
|
||||||
|
Id = certificateId,
|
||||||
|
passport = passport,
|
||||||
|
Text = modal.documentText,
|
||||||
|
DocumentType = modal.documentType
|
||||||
|
};
|
||||||
|
Reports report = new()
|
||||||
|
{
|
||||||
|
Employee = Startup.sp.GetUser(Context.User.Id.ToString()).Result.Name,
|
||||||
|
type = ReportTypes.editPassport
|
||||||
|
};
|
||||||
|
await Startup.appDbContext.Reports.AddAsync(report);
|
||||||
|
await Startup.appDbContext.Certificates.AddAsync(certificate);
|
||||||
|
if (!modal.documentText.StartsWith("test"))
|
||||||
|
await Startup.appDbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
thumbnailUrl = spworlds.Types.User.CreateUser(passport.Applicant).Result.GetSkinPart(spworlds.Types.SkinPart.face);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
thumbnailUrl = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var author = new EmbedAuthorBuilder()
|
||||||
|
.WithName(((IGuildUser)Context.User).DisplayName)
|
||||||
|
.WithIconUrl(((IGuildUser)Context.User).GetDisplayAvatarUrl());
|
||||||
|
|
||||||
|
var field1 = new EmbedFieldBuilder()
|
||||||
|
.WithName("Данные документа:")
|
||||||
|
.WithValue($"ID документа: {documentId}\nID паспорта: {passport.Id}\nID сертификата: {certificateId}\n\nАпликант: {passport.Applicant}");
|
||||||
|
var field2 = new EmbedFieldBuilder()
|
||||||
|
.WithName("Текст документа:")
|
||||||
|
.WithValue($"```{modal.documentText}```");
|
||||||
|
var embed = new EmbedBuilder()
|
||||||
|
.WithTitle("Заверен новый документ")
|
||||||
|
.WithAuthor(author)
|
||||||
|
.WithThumbnailUrl(thumbnailUrl)
|
||||||
|
.WithFields(field1)
|
||||||
|
.WithFields(field2)
|
||||||
|
.WithColor(Color.DarkBlue)
|
||||||
|
.Build();
|
||||||
|
var channel = Context.Guild.GetChannel(1172879659193606164) as ITextChannel;
|
||||||
|
await channel.SendMessageAsync(embed: embed);
|
||||||
|
await FollowupAsync(embed: embed);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace DiscordApp.Justice.Interactions
|
|||||||
{
|
{
|
||||||
await DeferAsync(true);
|
await DeferAsync(true);
|
||||||
int passportId;
|
int passportId;
|
||||||
|
string thumbnailUrl;
|
||||||
Passport passport;
|
Passport passport;
|
||||||
bool isInteger = int.TryParse(modal.passport, out passportId);
|
bool isInteger = int.TryParse(modal.passport, out passportId);
|
||||||
if (isInteger)
|
if (isInteger)
|
||||||
@@ -42,11 +43,18 @@ namespace DiscordApp.Justice.Interactions
|
|||||||
new EmbedFieldBuilder().WithName("Годен до").WithValue($"<t:{passport.Date}:D>").WithIsInline(true),
|
new EmbedFieldBuilder().WithName("Годен до").WithValue($"<t:{passport.Date}:D>").WithIsInline(true),
|
||||||
new EmbedFieldBuilder().WithName("Паспортист").WithValue($"<@{passport.Employee}>").WithIsInline(true)
|
new EmbedFieldBuilder().WithName("Паспортист").WithValue($"<@{passport.Employee}>").WithIsInline(true)
|
||||||
};
|
};
|
||||||
var spUser = await spworlds.Types.User.CreateUser(passport.Applicant);
|
try
|
||||||
var embed = new EmbedBuilder()
|
{
|
||||||
|
thumbnailUrl = spworlds.Types.User.CreateUser(passport.Applicant).Result.GetSkinPart(spworlds.Types.SkinPart.face);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
thumbnailUrl = null;
|
||||||
|
}
|
||||||
|
var embed = new EmbedBuilder()
|
||||||
.WithTitle("**Информация о паспорте**")
|
.WithTitle("**Информация о паспорте**")
|
||||||
.WithFields(fields)
|
.WithFields(fields)
|
||||||
.WithThumbnailUrl(spUser.GetSkinPart(spworlds.Types.SkinPart.face))
|
.WithThumbnailUrl(thumbnailUrl)
|
||||||
.Build();
|
.Build();
|
||||||
await FollowupAsync(embed:embed, ephemeral: true);
|
await FollowupAsync(embed:embed, ephemeral: true);
|
||||||
|
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ namespace DiscordApp.Justice.Interactions
|
|||||||
DateTimeOffset toTime;
|
DateTimeOffset toTime;
|
||||||
DateOnly birthDate;
|
DateOnly birthDate;
|
||||||
int id;
|
int id;
|
||||||
Utilities.IdChecker.IdLenghtIsLower(out id);
|
Utilities.Utilities.IdGenerator(out id);
|
||||||
long unixBirthDateTime;
|
long unixBirthDateTime;
|
||||||
string cityName;
|
string cityName;
|
||||||
string cardNumber;
|
string cardNumber;
|
||||||
@@ -242,7 +242,7 @@ namespace DiscordApp.Justice.Interactions
|
|||||||
bool isUnical = false;
|
bool isUnical = false;
|
||||||
while (!isUnical)
|
while (!isUnical)
|
||||||
{
|
{
|
||||||
Utilities.IdChecker.IdLenghtIsLower(out id);
|
Utilities.Utilities.IdGenerator(out id);
|
||||||
passport.Id = id;
|
passport.Id = id;
|
||||||
Console.WriteLine(passport.Id);
|
Console.WriteLine(passport.Id);
|
||||||
if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result == null) { break; }
|
if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result == null) { break; }
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ using Discord.Interactions;
|
|||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using DiscordApp.Database;
|
using DiscordApp.Database;
|
||||||
using Microsoft.VisualBasic;
|
using Microsoft.VisualBasic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace DiscordApp
|
namespace DiscordApp
|
||||||
{
|
{
|
||||||
@@ -39,8 +40,17 @@ namespace DiscordApp
|
|||||||
|
|
||||||
private async Task ReadyAsync()
|
private async Task ReadyAsync()
|
||||||
{
|
{
|
||||||
await client.SetGameAsync("yaflay.ru", "https://yaflay.ru/", ActivityType.Watching);
|
HttpClient http = new HttpClient();
|
||||||
await handler.RegisterCommandsGloballyAsync(true);
|
await handler.RegisterCommandsGloballyAsync(true);
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var request = await http.GetAsync("https://api.mcsrvstat.us/3/pl.spworlds.ru");
|
||||||
|
JsonNode responseAboutPL = JsonNode.Parse(request.Content.ReadAsStringAsync().Result);
|
||||||
|
if (responseAboutPL["online"].Equals("false")) await client.SetGameAsync($"выключенный PL", "https://yaflay.ru/", ActivityType.Watching);
|
||||||
|
else await client.SetGameAsync($"онлайн на PL: {responseAboutPL["players"]["online"]}", "https://yaflay.ru/", ActivityType.Watching);
|
||||||
|
await Task.Delay(30000);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleInteraction(SocketInteraction interaction)
|
private async Task HandleInteraction(SocketInteraction interaction)
|
||||||
|
|||||||
302
Migrations/20231111140218_Migrate11111701.Designer.cs
generated
Normal file
302
Migrations/20231111140218_Migrate11111701.Designer.cs
generated
Normal file
@@ -0,0 +1,302 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using DiscordApp.Database;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DiscordApp.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(AppDbContext))]
|
||||||
|
[Migration("20231111140218_Migrate11111701")]
|
||||||
|
partial class Migrate11111701
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.13")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.ArtsPatents", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<long>("Date")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Employee")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int[]>("Number")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("integer[]");
|
||||||
|
|
||||||
|
b.Property<string>("Size")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("isAllowedToResell")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<int>("passportId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("passportId");
|
||||||
|
|
||||||
|
b.ToTable("ArtsPatent", "public");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.Autobranches", b =>
|
||||||
|
{
|
||||||
|
b.Property<decimal>("ChannelId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("numeric(20,0)");
|
||||||
|
|
||||||
|
b.Property<string>("BranchName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("ChannelId");
|
||||||
|
|
||||||
|
b.ToTable("Autobranches", "public");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ApplicantId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int[]>("BiznessEmployes")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("integer[]");
|
||||||
|
|
||||||
|
b.Property<string>("BiznessName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("BiznessType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("CardNumber")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<long>("Date")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Employee")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ApplicantId");
|
||||||
|
|
||||||
|
b.ToTable("Bizness", "public");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Annotation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long>("Date")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Employee")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Janre")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("isAllowedToResell")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<int>("passportId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("passportId");
|
||||||
|
|
||||||
|
b.ToTable("BooksPatent", "public");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.Certificate", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateOnly>("Date")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
|
b.Property<int>("DocumentId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("DocumentType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Employee")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Text")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("passportId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("passportId");
|
||||||
|
|
||||||
|
b.ToTable("Certificate", "public");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Applicant")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long>("Date")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<decimal>("Employee")
|
||||||
|
.HasColumnType("numeric(20,0)");
|
||||||
|
|
||||||
|
b.Property<string>("Gender")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("RpName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("Support")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<long>("birthDate")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Passport", "public");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.Reports", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Employee")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("type")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Reports", "public");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.ArtsPatents", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("DiscordApp.Database.Tables.Passport", "passport")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("passportId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("passport");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("DiscordApp.Database.Tables.Passport", "Applicant")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ApplicantId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Applicant");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("DiscordApp.Database.Tables.Passport", "passport")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("passportId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("passport");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.Certificate", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("DiscordApp.Database.Tables.Passport", "passport")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("passportId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("passport");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
Migrations/20231111140218_Migrate11111701.cs
Normal file
56
Migrations/20231111140218_Migrate11111701.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DiscordApp.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Migrate11111701 : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Certificate",
|
||||||
|
schema: "public",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Employee = table.Column<string>(type: "text", nullable: false),
|
||||||
|
passportId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Date = table.Column<DateOnly>(type: "date", nullable: false),
|
||||||
|
Text = table.Column<string>(type: "text", nullable: false),
|
||||||
|
DocumentId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
DocumentType = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Certificate", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Certificate_Passport_passportId",
|
||||||
|
column: x => x.passportId,
|
||||||
|
principalSchema: "public",
|
||||||
|
principalTable: "Passport",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Certificate_passportId",
|
||||||
|
schema: "public",
|
||||||
|
table: "Certificate",
|
||||||
|
column: "passportId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Certificate",
|
||||||
|
schema: "public");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
using DiscordApp.Database;
|
using DiscordApp.Database;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
@@ -156,6 +157,42 @@ namespace DiscordApp.Migrations
|
|||||||
b.ToTable("BooksPatent", "public");
|
b.ToTable("BooksPatent", "public");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.Certificate", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateOnly>("Date")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
|
b.Property<int>("DocumentId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("DocumentType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Employee")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Text")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("passportId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("passportId");
|
||||||
|
|
||||||
|
b.ToTable("Certificate", "public");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b =>
|
modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -245,6 +282,17 @@ namespace DiscordApp.Migrations
|
|||||||
|
|
||||||
b.Navigation("passport");
|
b.Navigation("passport");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DiscordApp.Database.Tables.Certificate", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("DiscordApp.Database.Tables.Passport", "passport")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("passportId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("passport");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
namespace DiscordApp.Utilities
|
using DiscordApp.Database.Tables;
|
||||||
|
|
||||||
|
namespace DiscordApp.Utilities
|
||||||
{
|
{
|
||||||
public class IdChecker
|
public class Utilities
|
||||||
{
|
{
|
||||||
public static void IdLenghtIsLower(out int id)
|
public static void IdGenerator(out int id)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
id = random.Next(00001, 99999);
|
id = random.Next(00001, 99999);
|
||||||
while (id.ToString().Length < 5) { id = random.Next(00001, 99999); }
|
while (id.ToString().Length < 5) { id = random.Next(00001, 99999); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
public static bool IsPassport(int id, out Passport passport)
|
||||||
|
{
|
||||||
|
passport = Startup.appDbContext.Passport.FirstOrDefault(x => x.Id == id);
|
||||||
|
return passport == null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user