From 7c3e88376b266de9151543341e25dbc85bdaf515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A8=D0=B8?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD=D1=81=D0=BA=D0=B8=D0=B9?= Date: Sun, 29 Oct 2023 21:23:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=82=D0=B5=D0=BD=D1=82=D1=8B,=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D1=8E,=20?= =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BF=D0=B0=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D1=80=D1=82=D0=B0,=20=D0=B8=D0=BF=20=D0=BE=D0=BE=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/AppDbContext.cs | 5 + .../Tables/{Patents.cs => ArtsPatents.cs} | 16 +- Database/Tables/Bizness.cs | 21 ++ Database/Tables/BooksPatents.cs | 22 ++ Database/Tables/Reports.cs | 16 ++ Justice/Commands/Bizness.cs | 27 ++ Justice/Commands/Passports.cs | 1 + Justice/Commands/Patents.cs | 29 ++ Justice/Commands/Settings.cs | 23 +- Justice/Interactions/BiznessInteractions.cs | 138 ++++++++++ Justice/Interactions/PassportInteraction.cs | 80 ++---- Justice/Interactions/Patents.cs | 6 - Justice/Interactions/PatentsInteractions.cs | 147 +++++++++++ Justice/Interactions/VerificateInteraction.cs | 2 +- Justice/Modals/BiznessModals.cs | 49 ++++ Justice/Modals/PassportModals.cs | 46 ++++ Justice/Modals/PatentModals.cs | 54 ++++ .../20231029124001_InitMigrate.Designer.cs | 81 ++++++ Migrations/20231029124001_InitMigrate.cs | 22 ++ .../20231029140047_InitMigrate29.Designer.cs | 183 +++++++++++++ Migrations/20231029140047_InitMigrate29.cs | 93 +++++++ ...231029160409_InitMigrate291903.Designer.cs | 248 ++++++++++++++++++ .../20231029160409_InitMigrate291903.cs | 106 ++++++++ ...231029164526_InitMigrate291945.Designer.cs | 234 +++++++++++++++++ .../20231029164526_InitMigrate291945.cs | 65 +++++ Migrations/AppDbContextModelSnapshot.cs | 153 +++++++++++ Startup.cs | 4 +- Types/ReportTypes.cs | 14 + 28 files changed, 1814 insertions(+), 71 deletions(-) rename Database/Tables/{Patents.cs => ArtsPatents.cs} (51%) create mode 100644 Database/Tables/Bizness.cs create mode 100644 Database/Tables/BooksPatents.cs create mode 100644 Database/Tables/Reports.cs create mode 100644 Justice/Commands/Bizness.cs create mode 100644 Justice/Commands/Patents.cs create mode 100644 Justice/Interactions/BiznessInteractions.cs delete mode 100644 Justice/Interactions/Patents.cs create mode 100644 Justice/Interactions/PatentsInteractions.cs create mode 100644 Justice/Modals/BiznessModals.cs create mode 100644 Justice/Modals/PassportModals.cs create mode 100644 Justice/Modals/PatentModals.cs create mode 100644 Migrations/20231029124001_InitMigrate.Designer.cs create mode 100644 Migrations/20231029124001_InitMigrate.cs create mode 100644 Migrations/20231029140047_InitMigrate29.Designer.cs create mode 100644 Migrations/20231029140047_InitMigrate29.cs create mode 100644 Migrations/20231029160409_InitMigrate291903.Designer.cs create mode 100644 Migrations/20231029160409_InitMigrate291903.cs create mode 100644 Migrations/20231029164526_InitMigrate291945.Designer.cs create mode 100644 Migrations/20231029164526_InitMigrate291945.cs create mode 100644 Types/ReportTypes.cs diff --git a/Database/AppDbContext.cs b/Database/AppDbContext.cs index 9d6b048..b436da8 100644 --- a/Database/AppDbContext.cs +++ b/Database/AppDbContext.cs @@ -1,4 +1,5 @@ using DiscordApp.Database.Tables; +using Microsoft.AspNetCore.DataProtection.Repositories; using Microsoft.EntityFrameworkCore; namespace DiscordApp.Database @@ -9,6 +10,10 @@ namespace DiscordApp.Database public DbSet Passport { get; set; } public DbSet Autobranches { get; set; } + public DbSet ArtPatents { get; set; } + public DbSet BookPatents { get; set; } + public DbSet Bizness { get; set; } + public DbSet Reports { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); diff --git a/Database/Tables/Patents.cs b/Database/Tables/ArtsPatents.cs similarity index 51% rename from Database/Tables/Patents.cs rename to Database/Tables/ArtsPatents.cs index fda7d5b..0defbe6 100644 --- a/Database/Tables/Patents.cs +++ b/Database/Tables/ArtsPatents.cs @@ -4,17 +4,19 @@ using System.ComponentModel.DataAnnotations.Schema; namespace DiscordApp.Database.Tables { - [Table("Patents", Schema = "public")] - public class Patents + [Table("ArtsPatent", Schema = "public")] + public class ArtsPatents { - public string Employee { get; set; } - public string Applicant { get; set; } - public int Date { get; set; } [Key] + public int Id { get; set; } + public string Employee { get; set; } + public Passport passport { get; set; } + public long Date { get; set; } public int[] Number { get; set; } - public Supporter Support { get; set; } - public string Gender { get; set; } public string Name { get; set; } + public string Size { get; set; } + public bool isAllowedToResell { get; set; } + } } \ No newline at end of file diff --git a/Database/Tables/Bizness.cs b/Database/Tables/Bizness.cs new file mode 100644 index 0000000..7dee0b8 --- /dev/null +++ b/Database/Tables/Bizness.cs @@ -0,0 +1,21 @@ +using DiscordApp.Types; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace DiscordApp.Database.Tables +{ + [Table("Bizness", Schema = "public")] + public class Bizness + { + [Key] + public int Id { get; set; } + public Passport Applicant { get; set; } + public string Employee { get; set; } + public string BiznessName { get; set; } + public int[] BiznessEmployes { get; set; } + public long Date { get; set; } + public string BiznessType { get; set; } + public int CardNumber { get; set; } + } +} diff --git a/Database/Tables/BooksPatents.cs b/Database/Tables/BooksPatents.cs new file mode 100644 index 0000000..cef8eb6 --- /dev/null +++ b/Database/Tables/BooksPatents.cs @@ -0,0 +1,22 @@ +using DiscordApp.Enums; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace DiscordApp.Database.Tables +{ + [Table("BooksPatent", Schema = "public")] + public class BooksPatents + { + [Key] + public int Id { get; set; } + public string Employee { get; set; } + public Passport passport { get; set; } + public long Date { get; set; } + public string Name { get; set; } + public string Annotation { get; set; } + public string Janre { get; set; } + public bool isAllowedToResell { get; set; } + + + } +} \ No newline at end of file diff --git a/Database/Tables/Reports.cs b/Database/Tables/Reports.cs new file mode 100644 index 0000000..258982e --- /dev/null +++ b/Database/Tables/Reports.cs @@ -0,0 +1,16 @@ +using DiscordApp.Types; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace DiscordApp.Database.Tables +{ + [Table("Reports", Schema = "public")] + public class Reports + { + [Key] + public int Id { get; set; } + public string Employee { get; set; } + public ReportTypes type { get; set; } + + } +} diff --git a/Justice/Commands/Bizness.cs b/Justice/Commands/Bizness.cs new file mode 100644 index 0000000..6091096 --- /dev/null +++ b/Justice/Commands/Bizness.cs @@ -0,0 +1,27 @@ +using Discord; +using Discord.Interactions; + +namespace DiscordApp.Justice.Commands +{ + public class Bizness : InteractionModuleBase + { + [SlashCommand("bizness-embed", "Отправляет сообщение с кнопками для регистрации")] + [DefaultMemberPermissions(GuildPermission.Administrator)] + public async Task sendBiznessEmbed() + { + await DeferAsync(true); + var Embed = new EmbedBuilder() + .WithTitle("**Регистрация бизнеса!**") + .WithDescription("Ниже вы можете нажать на кнопку для создания ИП или ООО!") + .WithColor(Color.Blue) + .Build(); + var Components = new ComponentBuilder() + .WithButton(new ButtonBuilder() { CustomId = "NewIndividualEntrepreneur", Label = "ИП", Style = ButtonStyle.Primary }) + .WithButton(new ButtonBuilder() { CustomId = "NewBizness", Label = "ООО", Style = ButtonStyle.Primary }) + .Build(); + await Context.Channel.SendMessageAsync(embed: Embed, components: Components); + await FollowupAsync("OK!");//, ephemeral: true); + } + + } +} diff --git a/Justice/Commands/Passports.cs b/Justice/Commands/Passports.cs index 46d7ac6..f0a436e 100644 --- a/Justice/Commands/Passports.cs +++ b/Justice/Commands/Passports.cs @@ -7,6 +7,7 @@ namespace DiscordApp.Justice.Commands { public InteractionService Commands { get; set; } [SlashCommand("send_passport_embed", description: "Отправляет сообщение для регистрации паспортов")] + [DefaultMemberPermissions(GuildPermission.Administrator)] public async Task sendPassportBuilerEmbed() { await DeferAsync(true); diff --git a/Justice/Commands/Patents.cs b/Justice/Commands/Patents.cs new file mode 100644 index 0000000..46e8ca4 --- /dev/null +++ b/Justice/Commands/Patents.cs @@ -0,0 +1,29 @@ +using Discord.Interactions; +using Discord; + +namespace DiscordApp.Justice.Commands +{ + public class Patents : InteractionModuleBase + { + public InteractionService Commands { get; set; } + + [SlashCommand("send_patent_embed", description: "Отправляет сообщение для регистрации паспортов")] + [DefaultMemberPermissions(GuildPermission.Administrator)] + public async Task sendPatentBuilerEmbed() + { + await DeferAsync(true); + var Embed = new EmbedBuilder() + .WithTitle("**Регистрация патента!**") + .WithDescription("Ниже вы можете нажать на кнопку для создания патентов!") + .WithColor(Color.Blue) + .Build(); + var Components = new ComponentBuilder() + .WithButton(new ButtonBuilder() { CustomId = "artPatent", Label = "Патент на арт", Style = ButtonStyle.Primary }) + .WithButton(new ButtonBuilder() { CustomId = "bookPatent", Label = "Патент на книгу", Style = ButtonStyle.Primary }) + .Build(); + await Context.Channel.SendMessageAsync(embed: Embed, components: Components); + await FollowupAsync("OK!"); + } + + } +} diff --git a/Justice/Commands/Settings.cs b/Justice/Commands/Settings.cs index 88f63d7..e49c063 100644 --- a/Justice/Commands/Settings.cs +++ b/Justice/Commands/Settings.cs @@ -59,7 +59,7 @@ namespace DiscordApp.Discord.Commands await DeferAsync(true); var embed = new EmbedBuilder() .WithTitle("**Верификация игроков**") - .WithDescription($"Если что-то случилось, и вам не выдается роль <@&1165687128366268511>, то нажмите на кнопку ниже!") + .WithDescription($"Если что-то случилось, и вам не выдается роль <@&1136564585420304444>, то нажмите на кнопку ниже!") .WithImageUrl("") .WithColor(Color.Blue) .Build(); @@ -74,8 +74,25 @@ namespace DiscordApp.Discord.Commands await Context.Channel.SendMessageAsync(embed: embed, components: components); await FollowupAsync("Ok", ephemeral: true); } + [SlashCommand("раздача-зарплаты", "Берет данные из баз данных и раздает кому надо")] + [DefaultMemberPermissions(GuildPermission.Administrator)] + public async Task giveAvanse() + { + await DeferAsync(true); + int allCount = 0; + var allReports = Startup.appDbContext.Reports.ToArray(); + var allEmployee = new Dictionary(); + foreach (var report in allReports) + { + allEmployee[report.Employee] += (int)report.type; - - // ReplyAsync is a method on ModuleBase + } + foreach (var employee in allEmployee) + { + await Startup.sp.CreateTransaction(employee.Key, employee.Value, "АвтоЗарплата Юстиций"); + allCount += employee.Value; + } + await FollowupAsync($"Готово! Раздал {allCount} АР", ephemeral: true); + } } } diff --git a/Justice/Interactions/BiznessInteractions.cs b/Justice/Interactions/BiznessInteractions.cs new file mode 100644 index 0000000..63d9c31 --- /dev/null +++ b/Justice/Interactions/BiznessInteractions.cs @@ -0,0 +1,138 @@ +using Discord; +using Discord.Interactions; +using DiscordApp.Database.Tables; +using DiscordApp.Justice.Modals; +using spworlds.Types; + +namespace DiscordApp.Justice.Interactions +{ + public class BiznessInteraction : InteractionModuleBase + { + [ComponentInteraction("NewIndividualEntrepreneur")] + public async Task AplyWork() + => await Context.Interaction.RespondWithModalAsync("newIndividualEterpreneur"); + [ComponentInteraction("NewBizness")] + public async Task reCreatePassport() + => await Context.Interaction.RespondWithModalAsync("NewBizness"); + + [ModalInteraction("newIndividualEterpreneur")] + public async Task newIndividualEterpreneur(INewIndividualEntrepreneur modal) + { + await DeferAsync(true); + Passport? applicant = await Startup.appDbContext.Passport.FindAsync(int.Parse(modal.passportId)); + if (applicant == null) + { + await FollowupAsync("Ошибка! Такого паспорта не существует. Попробуйте старого бота.", ephemeral: true); + return; + } + User spApplicant = await User.CreateUser(applicant.Applicant); + var employees = new List(); + employees.Add(applicant.Id); + + Bizness biznessDB = new() + { + Applicant = applicant, + Employee = ((IGuildUser)Context.User).DisplayName, + BiznessEmployes = employees.ToArray(), + BiznessName = modal.Name, + BiznessType = modal.BiznessType, + CardNumber = modal.CardNumber, + Date = DateTimeOffset.Now.ToUnixTimeSeconds() + }; + Reports report = new() + { + Employee = ((IGuildUser)Context.User).DisplayName, + type = Types.ReportTypes.Bizness + }; + await Startup.appDbContext.Reports.AddAsync(report); + await Startup.appDbContext.Bizness.AddAsync(biznessDB); + + if (!modal.Name.StartsWith("test")) { await Startup.appDbContext.SaveChangesAsync(); } + + var fieldBuilder = new EmbedFieldBuilder() + .WithName("Данные:") + .WithValue($"```Аппликант: {applicant.Applicant}\nНазвание: {modal.Name}\nТип деятельности: {modal.BiznessType}\nНомер карты:{modal.CardNumber}```"); + var author = new EmbedAuthorBuilder() + .WithIconUrl(Context.User.GetAvatarUrl()) + .WithName(((IGuildUser)Context.User).DisplayName); + var embed = new EmbedBuilder() + .WithTitle("Новый ИП зарегестрирован!") + .WithAuthor(author) + .WithFields(fieldBuilder) + .WithThumbnailUrl(spApplicant.GetSkinPart(SkinPart.face)) + .WithColor(Color.Blue) + .Build(); + await FollowupAsync("Готово!", ephemeral: true); + var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel; + + await channel.SendMessageAsync(embed: embed); + } + + [ModalInteraction("NewBizness")] + public async Task newBizness(INewBizness modal) + { + await DeferAsync(true); + Passport? applicant = await Startup.appDbContext.Passport.FindAsync(int.Parse(modal.passportId)); + + if (applicant == null) + { + await FollowupAsync("Ошибка! Такого паспорта не существует. Попробуйте старого бота.", ephemeral: true); + return; + } + User spApplicant = await User.CreateUser(applicant.Applicant); + var employees = new List + { + applicant.Id + }; + string employeesNames = ""; + foreach (var passportId in modal.BiznessEmployee.Split(",")) + { + Passport? employee = await Startup.appDbContext.Passport.FindAsync(int.Parse(passportId)); + if (employee != null) { employees.Add(employee.Id); employeesNames += $" {employee.Applicant}"; } + else + { + await FollowupAsync($"У {passportId} указан неправильный номер паспорта.", ephemeral: true); + } + } + + Bizness biznessDB = new() + { + Applicant = applicant, + Employee = ((IGuildUser)Context.User).DisplayName, + BiznessEmployes = employees.ToArray(), + BiznessName = modal.Name, + BiznessType = modal.BiznessType, + CardNumber = modal.CardNumber, + Date = DateTimeOffset.Now.ToUnixTimeSeconds() + }; + Reports report = new() + { + Employee = ((IGuildUser)Context.User).DisplayName, + type = Types.ReportTypes.Bizness + }; + await Startup.appDbContext.Reports.AddAsync(report); + await Startup.appDbContext.Bizness.AddAsync(biznessDB); + + if (!modal.Name.StartsWith("test")) { await Startup.appDbContext.SaveChangesAsync(); } + + var fieldBuilder = new EmbedFieldBuilder() + .WithName("Данные:") + .WithValue($"```Аппликант: {applicant.Applicant}\nНазвание: {modal.Name}\nТип деятельности: {modal.BiznessType}\nНомер карты:{modal.CardNumber}\nСотрудники:{employeesNames}```"); + var author = new EmbedAuthorBuilder() + .WithIconUrl(Context.User.GetAvatarUrl()) + .WithName(((IGuildUser)Context.User).DisplayName); + var embed = new EmbedBuilder() + .WithTitle("Новый ООО зарегестрирован!") + .WithAuthor(author) + .WithFields(fieldBuilder) + .WithThumbnailUrl(spApplicant.GetSkinPart(SkinPart.face)) + .WithColor(Color.Blue) + .Build(); + await FollowupAsync("Готово!", ephemeral: true); + var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel; + + await channel.SendMessageAsync(embed: embed); + } + + } +} diff --git a/Justice/Interactions/PassportInteraction.cs b/Justice/Interactions/PassportInteraction.cs index ab8b382..460a8fb 100644 --- a/Justice/Interactions/PassportInteraction.cs +++ b/Justice/Interactions/PassportInteraction.cs @@ -4,7 +4,7 @@ using Discord.WebSocket; using DiscordApp.Database.Tables; using DiscordApp.Enums; using spworlds.Types; - +using DiscordApp.Justice.Modals; namespace DiscordApp.Justice.Interactions { public class PassportInteraction : InteractionModuleBase @@ -15,16 +15,16 @@ namespace DiscordApp.Justice.Interactions [ComponentInteraction("newPassport")] public async Task AplyWork() - => await Context.Interaction.RespondWithModalAsync("passportModal"); + => await Context.Interaction.RespondWithModalAsync("passportModal"); [ComponentInteraction("reworkPassport")] public async Task reCreatePassport() - => await Context.Interaction.RespondWithModalAsync("reworkpassportModal"); + => await Context.Interaction.RespondWithModalAsync("reworkpassportModal"); [ComponentInteraction("reNewPassportButton")] - public async Task reNewPassportModal() => await Context.Interaction.RespondWithModalAsync("ReNewPassportModal"); + public async Task reNewPassportModal() => await Context.Interaction.RespondWithModalAsync("ReNewPassportModal"); [ModalInteraction("reworkpassportModal")] - public async Task reCreatePassportInteraction(ReWorkPassportModal modal) + public async Task reCreatePassportInteraction(IReWorkPassportModal modal) { await DeferAsync(true); double passportId = modal.Id; @@ -109,7 +109,7 @@ namespace DiscordApp.Justice.Interactions } } [ModalInteraction("ReNewPassportModal")] - public async Task renewPassportInteraction(NewPassportModal modal) + public async Task renewPassportInteraction(INewPassportModal modal) { await DeferAsync(true); string name = modal.NickName; @@ -170,6 +170,12 @@ namespace DiscordApp.Justice.Interactions Id = id, Support = supporter }; + Reports report = new() + { + Employee = ((IGuildUser)Context.User).DisplayName, + type = Types.ReportTypes.editPassport + }; + await Startup.appDbContext.Reports.AddAsync(report); if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result != null) { @@ -219,7 +225,7 @@ namespace DiscordApp.Justice.Interactions } [ModalInteraction("passportModal")] - public async Task createPassportInteraction(NewPassportModal modal) + public async Task createPassportInteraction(INewPassportModal modal) { await DeferAsync(true); string name = modal.NickName; @@ -233,7 +239,7 @@ namespace DiscordApp.Justice.Interactions Random random = new(); User spUser = await User.CreateUser(name); - DateTimeOffset toTime = DateTime.Now.AddDays(14); + DateTimeOffset toTime; DateTime birthDate; int id = random.Next(00001, 99999); long unixTime; @@ -244,8 +250,12 @@ namespace DiscordApp.Justice.Interactions unixTime = ((DateTimeOffset)birthDate).ToUnixTimeSeconds(); if (birthDate.AddDays(14) < DateTime.Now) { - await FollowupAsync($"Возможно, игрок {name} больше не новичек, и бесплатный паспорт ему не положен! Оформляю паспорт на месяц...0", ephemeral: true); - toTime = DateTimeOffset.Now.AddDays(60); + await FollowupAsync($"Возможно, игрок {name} больше не новичек, и бесплатный паспорт ему не положен! Оформляю паспорт на месяц...", ephemeral: true); + toTime = DateTimeOffset.Now.AddMonths(2); + } + else + { + toTime = DateTime.Now.AddDays(14); } } catch (Exception ex) @@ -324,54 +334,20 @@ namespace DiscordApp.Justice.Interactions .WithTimestamp(toTime) .Build(); - + Reports report = new() + { + Employee = ((IGuildUser)Context.User).DisplayName, + type = Types.ReportTypes.NewPassport + }; + await Startup.appDbContext.Reports.AddAsync(report); await Startup.appDbContext.Passport.AddAsync(passport); await Startup.appDbContext.SaveChangesAsync(); await FollowupAsync($"ID для паспорта: {id}", embed: embed, ephemeral: true); var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel; - var message = await channel.SendMessageAsync(embed: embed); + await channel.SendMessageAsync(embed: embed); } } - - public class NewPassportModal : IModal - { - public string Title => "Создание паспорта"; - - [InputLabel("Ник игрока")] - [ModalTextInput("nickname", TextInputStyle.Short, placeholder: "YaFlay", maxLength: 90)] - public string NickName { get; set; } - - [InputLabel("Благотворитель")] - [ModalTextInput("Supporter", TextInputStyle.Short, placeholder: "1", maxLength: 5)] - public int Supporter { get; set; } - - [InputLabel("РП Имя")] - [ModalTextInput("rolePlayName", TextInputStyle.Short, placeholder: "Олег Бебров", maxLength: 200)] - public string RPName { get; set; } - - [InputLabel("Пол")] - [ModalTextInput("gender", TextInputStyle.Short, maxLength: 200)] - public string Gender { get; set; } - [InputLabel("Дата рождения")] - [ModalTextInput("BirthDay", TextInputStyle.Short, placeholder: "16.02.2023", maxLength: 100)] - public string Birthday { get; set; } - - } - - public class ReWorkPassportModal : IModal - { - public string Title => "Создание паспорта"; - - [InputLabel("ID паспорта")] - [ModalTextInput("id", TextInputStyle.Short, placeholder: "82-777", maxLength: 7)] - public double Id { get; set; } - - [InputLabel("Новые данные(0/1)")] - [ModalTextInput("isNewPassportData", TextInputStyle.Short, placeholder: "1 - да, 0 - нет", maxLength: 1, initValue: "0")] - public int IsNewPassport { get; set; } - - } - } + diff --git a/Justice/Interactions/Patents.cs b/Justice/Interactions/Patents.cs deleted file mode 100644 index 1d4b2af..0000000 --- a/Justice/Interactions/Patents.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DiscordApp.Justice.Interactions -{ - public class Patents - { - } -} diff --git a/Justice/Interactions/PatentsInteractions.cs b/Justice/Interactions/PatentsInteractions.cs new file mode 100644 index 0000000..e212bc5 --- /dev/null +++ b/Justice/Interactions/PatentsInteractions.cs @@ -0,0 +1,147 @@ +using Discord.Interactions; +using DiscordApp.Justice.Modals; +using DiscordApp.Database.Tables; +using Discord.WebSocket; +using Discord; +using spworlds.Types; + +namespace DiscordApp.Justice.Interactions +{ + public class PatentInteraction : InteractionModuleBase + { + [ComponentInteraction("artPatent")] + public async Task artPatentInteractions() => await RespondWithModalAsync("newArtCallback"); + + [ComponentInteraction("bookPatent")] + public async Task bookPatentInteractions() => await RespondWithModalAsync("newBookCallback"); + + [ModalInteraction("newArtCallback")] + public async Task newArtModalInteraction(INewArtModal modal) + { + await DeferAsync(true); + string name = modal.Name; + string maps = modal.MapNumbers; + string size = modal.Size; + int passportId = modal.PassportId; + bool isAllowedToReSell = modal.IsAllowedToResell == 1; + + Passport? passport = await Startup.appDbContext.Passport.FindAsync(passportId); + if (passport == null) + { + await FollowupAsync("ID паспорта не найден в базе данных. Попробуйте использовать старого бота."); + return; + } + + var mapDictionary = new List(); + User spUser = await User.CreateUser(passport.Applicant); + try + { + foreach (var map in maps.Split(',')) + { + mapDictionary.Add(int.Parse(map)); + } + } + catch (Exception ex) + { + await Console.Out.WriteLineAsync($"new error in patentInteractions 32-37 {ex.Message}"); + await FollowupAsync("Возникла ошибка при парсинге ID карт. Вы точно указали через запятую данные?"); + return; + } + ArtsPatents artsPatent = new() + { + Name = name, + Employee = ((IGuildUser)Context.User).DisplayName, + Size = size, + Date = DateTimeOffset.Now.ToUnixTimeSeconds(), + Number = mapDictionary.ToArray(), + isAllowedToResell = isAllowedToReSell, + passport = passport + }; + Reports report = new() + { + Employee = ((IGuildUser)Context.User).DisplayName, + type = Types.ReportTypes.Patent + }; + await Startup.appDbContext.Reports.AddAsync(report); + await Startup.appDbContext.ArtPatents.AddAsync(artsPatent); + + if (!name.StartsWith("test")) { await Startup.appDbContext.SaveChangesAsync(); } + + var field = new EmbedFieldBuilder() + .WithName("Данные патента") + .WithValue($"```Название арта: {name} \nРазмер: {size} \nНомера: {maps} \nРазрешена перепродажа?: {isAllowedToReSell} \nАппликант: {passport.Applicant}```") + .WithIsInline(false); + var author = new EmbedAuthorBuilder() + .WithIconUrl(Context.User.GetAvatarUrl()) + .WithName(((IGuildUser)Context.User).DisplayName); + var Embed = new EmbedBuilder() + .WithTitle("Новый патент!") + .WithFields(field) + .WithAuthor(author) + .WithColor(Color.Blue) + .WithCurrentTimestamp() + .WithThumbnailUrl(spUser.GetSkinPart(SkinPart.face)) + .Build(); + await FollowupAsync("Готово!", ephemeral: true); + var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel; + await channel.SendMessageAsync(embed: Embed); + } + [ModalInteraction("newBookCallback")] + public async Task newBookModalInteraction(INewBookModal modal) + { + await DeferAsync(true); + string name = modal.Name; + string janre = modal.Janre; + string annotation = modal.Annotation; + int passportId = modal.PassportId; + bool isAllowedToReSell = modal.IsAllowedToResell == 1; + + Passport? passport = await Startup.appDbContext.Passport.FindAsync(passportId); + if (passport == null) + { + await FollowupAsync("ID паспорта не найден в базе данных. Попробуйте использовать старого бота."); + return; + } + + User spUser = await User.CreateUser(passport.Applicant); + BooksPatents bookPatent = new() + { + Name = name, + Employee = ((IGuildUser)Context.User).DisplayName, + Janre = janre, + Date = DateTimeOffset.Now.ToUnixTimeSeconds(), + Annotation = annotation, + isAllowedToResell = isAllowedToReSell, + passport = passport + }; + Reports report = new() + { + Employee = ((IGuildUser)Context.User).DisplayName, + type = Types.ReportTypes.Patent + }; + await Startup.appDbContext.Reports.AddAsync(report); + await Startup.appDbContext.BookPatents.AddAsync(bookPatent); + + if (!name.StartsWith("test")) { await Startup.appDbContext.SaveChangesAsync(); } + + var field = new EmbedFieldBuilder() + .WithName("Данные патента") + .WithValue($"```Название книги: {name} \nАннотация: {annotation} \nЖанр: {janre} \nРазрешена перепродажа?:{isAllowedToReSell} \nАппликант:{passport.Applicant}```") + .WithIsInline(false); + var author = new EmbedAuthorBuilder() + .WithIconUrl(Context.User.GetAvatarUrl()) + .WithName(((IGuildUser)Context.User).DisplayName); + var Embed = new EmbedBuilder() + .WithTitle("Новый патент!") + .WithFields(field) + .WithAuthor(author) + .WithColor(Color.Blue) + .WithCurrentTimestamp() + .WithThumbnailUrl(spUser.GetSkinPart(SkinPart.face)) + .Build(); + await FollowupAsync("Готово!", ephemeral: true); + var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel; + await channel.SendMessageAsync(embed: Embed); + } + } +} diff --git a/Justice/Interactions/VerificateInteraction.cs b/Justice/Interactions/VerificateInteraction.cs index fb194c4..ae01435 100644 --- a/Justice/Interactions/VerificateInteraction.cs +++ b/Justice/Interactions/VerificateInteraction.cs @@ -15,7 +15,7 @@ namespace DiscordApp.Justice.Interactions { await FollowupAsync("Готово!", ephemeral: true); var guildUser = Context.Guild.GetUser(Context.User.Id); - await guildUser.AddRoleAsync(1165687128366268511); + await guildUser.AddRoleAsync(1136564585420304444); await guildUser.ModifyAsync(func => { func.Nickname = user.Name; diff --git a/Justice/Modals/BiznessModals.cs b/Justice/Modals/BiznessModals.cs new file mode 100644 index 0000000..8d6e236 --- /dev/null +++ b/Justice/Modals/BiznessModals.cs @@ -0,0 +1,49 @@ +using Discord; +using Discord.Interactions; + +namespace DiscordApp.Justice.Modals +{ + public class INewIndividualEntrepreneur : IModal + { + public string Title => "Регистрация ИП"; + [InputLabel("ID паспорта")] + [ModalTextInput("nickname", TextInputStyle.Short, placeholder: "96534", maxLength: 10)] + public string passportId { get; set; } + + [InputLabel("Название")] + [ModalTextInput("Name", TextInputStyle.Short, placeholder: "ИП Оганесян", maxLength: 100)] + public string Name { get; set; } + + [InputLabel("Тип деятельности")] + [ModalTextInput("Type", TextInputStyle.Short, placeholder: "Продажа", maxLength: 200)] + public string BiznessType { get; set; } + + [InputLabel("Номер карты")] + [ModalTextInput("cardNumber", TextInputStyle.Short, placeholder: "70835", maxLength: 100)] + public int CardNumber { get; set; } + + } + public class INewBizness : IModal + { + public string Title => "Регистрация ИП"; + [InputLabel("ID паспорта")] + [ModalTextInput("nickname", TextInputStyle.Short, placeholder: "96534", maxLength: 10)] + public string passportId { get; set; } + + [InputLabel("Название")] + [ModalTextInput("Name", TextInputStyle.Short, placeholder: "ИП Оганесян", maxLength: 100)] + public string Name { get; set; } + + [InputLabel("Тип деятельности")] + [ModalTextInput("Type", TextInputStyle.Short, placeholder: "Продажа", maxLength: 200)] + public string BiznessType { get; set; } + + [InputLabel("Участники(через запятую)")] + [ModalTextInput("Employee", TextInputStyle.Short, placeholder: "96534, 12742", maxLength: 200)] + public string BiznessEmployee { get; set; } + + [InputLabel("Номер карты")] + [ModalTextInput("cardNumber", TextInputStyle.Short, placeholder: "70835", maxLength: 100)] + public int CardNumber { get; set; } + } +} diff --git a/Justice/Modals/PassportModals.cs b/Justice/Modals/PassportModals.cs new file mode 100644 index 0000000..c0af5dd --- /dev/null +++ b/Justice/Modals/PassportModals.cs @@ -0,0 +1,46 @@ +using Discord.Interactions; +using Discord; + +namespace DiscordApp.Justice.Modals +{ + public class INewPassportModal : IModal + { + public string Title => "Создание паспорта"; + + [InputLabel("Ник игрока")] + [ModalTextInput("nickname", TextInputStyle.Short, placeholder: "YaFlay", maxLength: 90)] + public string NickName { get; set; } + + [InputLabel("Благотворитель")] + [ModalTextInput("Supporter", TextInputStyle.Short, placeholder: "1", maxLength: 5)] + public int Supporter { get; set; } + + [InputLabel("РП Имя")] + [ModalTextInput("rolePlayName", TextInputStyle.Short, placeholder: "Олег Бебров", maxLength: 200)] + public string RPName { get; set; } + + [InputLabel("Пол")] + [ModalTextInput("gender", TextInputStyle.Short, maxLength: 200)] + public string Gender { get; set; } + [InputLabel("Дата рождения")] + [ModalTextInput("BirthDay", TextInputStyle.Short, placeholder: "16.02.2023", maxLength: 100)] + public string Birthday { get; set; } + + } + + public class IReWorkPassportModal : IModal + { + public string Title => "Создание паспорта"; + + [InputLabel("ID паспорта")] + [ModalTextInput("id", TextInputStyle.Short, placeholder: "82-777", maxLength: 7)] + public double Id { get; set; } + + [InputLabel("Новые данные(0/1)")] + [ModalTextInput("isNewPassportData", TextInputStyle.Short, placeholder: "1 - да, 0 - нет", maxLength: 1, initValue: "0")] + public int IsNewPassport { get; set; } + + } + +} + diff --git a/Justice/Modals/PatentModals.cs b/Justice/Modals/PatentModals.cs new file mode 100644 index 0000000..8cc348b --- /dev/null +++ b/Justice/Modals/PatentModals.cs @@ -0,0 +1,54 @@ +using Discord; +using Discord.Interactions; + +namespace DiscordApp.Justice.Modals +{ + public class INewArtModal : IModal + { + public string Title => "Новый патент на арт"; + + [InputLabel("ID паспорта")] + [ModalTextInput("passportId", TextInputStyle.Short, placeholder: "97664", maxLength: 10)] + public int PassportId { get; set; } + + [InputLabel("Название арта")] + [ModalTextInput("artName", TextInputStyle.Short, placeholder: "Пикачу", maxLength: 100)] + public string Name { get; set; } + + [InputLabel("Номера карт арта(Через запятую)")] + [ModalTextInput("mapNumbers", TextInputStyle.Short, placeholder: "14322, 14323")] + public string MapNumbers { get; set; } + + [InputLabel("Размер арта")] + [ModalTextInput("artSize", TextInputStyle.Short, placeholder: "3х1")] + public string Size { get; set; } + [InputLabel("Разрешено ли перепродавать(0/1)")] + [ModalTextInput("artResell", TextInputStyle.Short, placeholder: "0 - нет, 1 - да")] + public int IsAllowedToResell { get; set; } + } + + public class INewBookModal : IModal + { + public string Title => "Новый патент на книгу"; + + [InputLabel("ID паспорта")] + [ModalTextInput("passportId", TextInputStyle.Short, placeholder: "97664", maxLength: 10)] + public int PassportId { get; set; } + + [InputLabel("Название книги")] + [ModalTextInput("bookName", TextInputStyle.Short, placeholder: "Пикачу", maxLength: 100)] + public string Name { get; set; } + + [InputLabel("Аннотация")] + [ModalTextInput("bookAnnotation", TextInputStyle.Short, placeholder: "14322, 14323")] + public string Annotation { get; set; } + + [InputLabel("Жанр")] + [ModalTextInput("bookJanre", TextInputStyle.Short, placeholder: "3х1")] + public string Janre { get; set; } + + [InputLabel("Разрешено ли перепродавать(0/1)")] + [ModalTextInput("bookResell", TextInputStyle.Short, placeholder: "0 - нет, 1 - да")] + public int IsAllowedToResell { get; set; } + } +} diff --git a/Migrations/20231029124001_InitMigrate.Designer.cs b/Migrations/20231029124001_InitMigrate.Designer.cs new file mode 100644 index 0000000..ec39e71 --- /dev/null +++ b/Migrations/20231029124001_InitMigrate.Designer.cs @@ -0,0 +1,81 @@ +// +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("20231029124001_InitMigrate")] + partial class InitMigrate + { + /// + 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.Autobranches", b => + { + b.Property("ChannelId") + .ValueGeneratedOnAdd() + .HasColumnType("numeric(20,0)"); + + b.Property("BranchName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ChannelId"); + + b.ToTable("Autobranches", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Applicant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .HasColumnType("numeric(20,0)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("RpName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Support") + .HasColumnType("integer"); + + b.Property("birthDate") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("Passport", "public"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20231029124001_InitMigrate.cs b/Migrations/20231029124001_InitMigrate.cs new file mode 100644 index 0000000..9b66a2b --- /dev/null +++ b/Migrations/20231029124001_InitMigrate.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiscordApp.Migrations +{ + /// + public partial class InitMigrate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Migrations/20231029140047_InitMigrate29.Designer.cs b/Migrations/20231029140047_InitMigrate29.Designer.cs new file mode 100644 index 0000000..27350e7 --- /dev/null +++ b/Migrations/20231029140047_InitMigrate29.Designer.cs @@ -0,0 +1,183 @@ +// +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("20231029140047_InitMigrate29")] + partial class InitMigrate29 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("Size") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("ArtsPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Autobranches", b => + { + b.Property("ChannelId") + .ValueGeneratedOnAdd() + .HasColumnType("numeric(20,0)"); + + b.Property("BranchName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ChannelId"); + + b.ToTable("Autobranches", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Annotation") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("integer"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Janre") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("BooksPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Applicant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .HasColumnType("numeric(20,0)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("RpName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Support") + .HasColumnType("integer"); + + b.Property("birthDate") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("Passport", "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.BooksPatents", b => + { + b.HasOne("DiscordApp.Database.Tables.Passport", "passport") + .WithMany() + .HasForeignKey("passportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("passport"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20231029140047_InitMigrate29.cs b/Migrations/20231029140047_InitMigrate29.cs new file mode 100644 index 0000000..ac232a1 --- /dev/null +++ b/Migrations/20231029140047_InitMigrate29.cs @@ -0,0 +1,93 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DiscordApp.Migrations +{ + /// + public partial class InitMigrate29 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ArtsPatent", + schema: "public", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Employee = table.Column(type: "text", nullable: false), + passportId = table.Column(type: "integer", nullable: false), + Date = table.Column(type: "bigint", nullable: false), + Number = table.Column(type: "integer[]", nullable: false), + Name = table.Column(type: "text", nullable: false), + Size = table.Column(type: "text", nullable: false), + isAllowedToResell = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ArtsPatent", x => x.Id); + table.ForeignKey( + name: "FK_ArtsPatent_Passport_passportId", + column: x => x.passportId, + principalSchema: "public", + principalTable: "Passport", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "BooksPatent", + schema: "public", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Employee = table.Column(type: "text", nullable: false), + passportId = table.Column(type: "integer", nullable: false), + Date = table.Column(type: "integer", nullable: false), + Name = table.Column(type: "text", nullable: false), + Annotation = table.Column(type: "text", nullable: false), + Janre = table.Column(type: "text", nullable: false), + isAllowedToResell = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BooksPatent", x => x.Id); + table.ForeignKey( + name: "FK_BooksPatent_Passport_passportId", + column: x => x.passportId, + principalSchema: "public", + principalTable: "Passport", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ArtsPatent_passportId", + schema: "public", + table: "ArtsPatent", + column: "passportId"); + + migrationBuilder.CreateIndex( + name: "IX_BooksPatent_passportId", + schema: "public", + table: "BooksPatent", + column: "passportId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ArtsPatent", + schema: "public"); + + migrationBuilder.DropTable( + name: "BooksPatent", + schema: "public"); + } + } +} diff --git a/Migrations/20231029160409_InitMigrate291903.Designer.cs b/Migrations/20231029160409_InitMigrate291903.Designer.cs new file mode 100644 index 0000000..b99d8b6 --- /dev/null +++ b/Migrations/20231029160409_InitMigrate291903.Designer.cs @@ -0,0 +1,248 @@ +// +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("20231029160409_InitMigrate291903")] + partial class InitMigrate291903 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("Size") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("ArtsPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Autobranches", b => + { + b.Property("ChannelId") + .ValueGeneratedOnAdd() + .HasColumnType("numeric(20,0)"); + + b.Property("BranchName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ChannelId"); + + b.ToTable("Autobranches", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApplicantId") + .HasColumnType("integer"); + + b.Property("BiznessName") + .IsRequired() + .HasColumnType("text"); + + b.Property("BiznessType") + .IsRequired() + .HasColumnType("text"); + + b.Property("CardNumber") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ApplicantId"); + + b.ToTable("Bizness"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Annotation") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Janre") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("BooksPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Applicant") + .IsRequired() + .HasColumnType("text"); + + b.Property("BiznessId") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .HasColumnType("numeric(20,0)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("RpName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Support") + .HasColumnType("integer"); + + b.Property("birthDate") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("BiznessId"); + + b.ToTable("Passport", "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.Passport", b => + { + b.HasOne("DiscordApp.Database.Tables.Bizness", null) + .WithMany("BiznessEmployes") + .HasForeignKey("BiznessId"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b => + { + b.Navigation("BiznessEmployes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20231029160409_InitMigrate291903.cs b/Migrations/20231029160409_InitMigrate291903.cs new file mode 100644 index 0000000..e1de75b --- /dev/null +++ b/Migrations/20231029160409_InitMigrate291903.cs @@ -0,0 +1,106 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DiscordApp.Migrations +{ + /// + public partial class InitMigrate291903 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "BiznessId", + schema: "public", + table: "Passport", + type: "integer", + nullable: true); + + migrationBuilder.AlterColumn( + name: "Date", + schema: "public", + table: "BooksPatent", + type: "bigint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.CreateTable( + name: "Bizness", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ApplicantId = table.Column(type: "integer", nullable: false), + Employee = table.Column(type: "text", nullable: false), + BiznessName = table.Column(type: "text", nullable: false), + Date = table.Column(type: "bigint", nullable: false), + BiznessType = table.Column(type: "text", nullable: false), + CardNumber = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Bizness", x => x.Id); + table.ForeignKey( + name: "FK_Bizness_Passport_ApplicantId", + column: x => x.ApplicantId, + principalSchema: "public", + principalTable: "Passport", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Passport_BiznessId", + schema: "public", + table: "Passport", + column: "BiznessId"); + + migrationBuilder.CreateIndex( + name: "IX_Bizness_ApplicantId", + table: "Bizness", + column: "ApplicantId"); + + migrationBuilder.AddForeignKey( + name: "FK_Passport_Bizness_BiznessId", + schema: "public", + table: "Passport", + column: "BiznessId", + principalTable: "Bizness", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Passport_Bizness_BiznessId", + schema: "public", + table: "Passport"); + + migrationBuilder.DropTable( + name: "Bizness"); + + migrationBuilder.DropIndex( + name: "IX_Passport_BiznessId", + schema: "public", + table: "Passport"); + + migrationBuilder.DropColumn( + name: "BiznessId", + schema: "public", + table: "Passport"); + + migrationBuilder.AlterColumn( + name: "Date", + schema: "public", + table: "BooksPatent", + type: "integer", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + } + } +} diff --git a/Migrations/20231029164526_InitMigrate291945.Designer.cs b/Migrations/20231029164526_InitMigrate291945.Designer.cs new file mode 100644 index 0000000..c900ab2 --- /dev/null +++ b/Migrations/20231029164526_InitMigrate291945.Designer.cs @@ -0,0 +1,234 @@ +// +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("20231029164526_InitMigrate291945")] + partial class InitMigrate291945 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("Size") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("ArtsPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Autobranches", b => + { + b.Property("ChannelId") + .ValueGeneratedOnAdd() + .HasColumnType("numeric(20,0)"); + + b.Property("BranchName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ChannelId"); + + b.ToTable("Autobranches", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApplicantId") + .HasColumnType("integer"); + + b.Property("BiznessEmployes") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("BiznessName") + .IsRequired() + .HasColumnType("text"); + + b.Property("BiznessType") + .IsRequired() + .HasColumnType("text"); + + b.Property("CardNumber") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ApplicantId"); + + b.ToTable("Bizness"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Annotation") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Janre") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("BooksPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Applicant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .HasColumnType("numeric(20,0)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("RpName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Support") + .HasColumnType("integer"); + + b.Property("birthDate") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("Passport", "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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20231029164526_InitMigrate291945.cs b/Migrations/20231029164526_InitMigrate291945.cs new file mode 100644 index 0000000..98fb9fe --- /dev/null +++ b/Migrations/20231029164526_InitMigrate291945.cs @@ -0,0 +1,65 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiscordApp.Migrations +{ + /// + public partial class InitMigrate291945 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Passport_Bizness_BiznessId", + schema: "public", + table: "Passport"); + + migrationBuilder.DropIndex( + name: "IX_Passport_BiznessId", + schema: "public", + table: "Passport"); + + migrationBuilder.DropColumn( + name: "BiznessId", + schema: "public", + table: "Passport"); + + migrationBuilder.AddColumn( + name: "BiznessEmployes", + table: "Bizness", + type: "integer[]", + nullable: false, + defaultValue: new int[0]); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "BiznessEmployes", + table: "Bizness"); + + migrationBuilder.AddColumn( + name: "BiznessId", + schema: "public", + table: "Passport", + type: "integer", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Passport_BiznessId", + schema: "public", + table: "Passport", + column: "BiznessId"); + + migrationBuilder.AddForeignKey( + name: "FK_Passport_Bizness_BiznessId", + schema: "public", + table: "Passport", + column: "BiznessId", + principalTable: "Bizness", + principalColumn: "Id"); + } + } +} diff --git a/Migrations/AppDbContextModelSnapshot.cs b/Migrations/AppDbContextModelSnapshot.cs index f29f0f0..c93b0c6 100644 --- a/Migrations/AppDbContextModelSnapshot.cs +++ b/Migrations/AppDbContextModelSnapshot.cs @@ -21,6 +21,46 @@ namespace DiscordApp.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("DiscordApp.Database.Tables.ArtsPatents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("Size") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("ArtsPatent", "public"); + }); + modelBuilder.Entity("DiscordApp.Database.Tables.Autobranches", b => { b.Property("ChannelId") @@ -36,6 +76,86 @@ namespace DiscordApp.Migrations b.ToTable("Autobranches", "public"); }); + modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApplicantId") + .HasColumnType("integer"); + + b.Property("BiznessEmployes") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("BiznessName") + .IsRequired() + .HasColumnType("text"); + + b.Property("BiznessType") + .IsRequired() + .HasColumnType("text"); + + b.Property("CardNumber") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ApplicantId"); + + b.ToTable("Bizness"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Annotation") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Janre") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("BooksPatent", "public"); + }); + modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b => { b.Property("Id") @@ -72,6 +192,39 @@ namespace DiscordApp.Migrations b.ToTable("Passport", "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"); + }); #pragma warning restore 612, 618 } } diff --git a/Startup.cs b/Startup.cs index d059fa7..9335e3e 100644 --- a/Startup.cs +++ b/Startup.cs @@ -31,8 +31,8 @@ namespace DiscordApp .AddEnvironmentVariables(prefix: "m.") .AddJsonFile("appsettings.json", optional: true) .Build(); - string CardId = "9bfb91d2-8e14-4c6d-b91d-8a55ab4c6559"; - string CardToken = "L3NsEQsW69sM3Gm0v/+hHDaU4TFocp7F"; + string CardId = "28fd1597-05a9-4ee0-8845-16ca37135081"; + string CardToken = "m+ziDmuTdFElD0vcKYnO3DS1h/9HuRGk"; sp = new SPWorlds(CardId, CardToken); } diff --git a/Types/ReportTypes.cs b/Types/ReportTypes.cs new file mode 100644 index 0000000..2427027 --- /dev/null +++ b/Types/ReportTypes.cs @@ -0,0 +1,14 @@ +namespace DiscordApp.Types +{ + public enum ReportTypes + { + NewPassport = 3, + editPassport = 2, + Bizness = 4, + ChangePassportId = 64, + PetPassport = 2, + Marry = 4, + BirthDocument = 4, + Patent = 2 + } +}