From f9a5dc5e34186d0e134db700873740c850cbdcda Mon Sep 17 00:00:00 2001 From: Chris Chen Date: Sun, 2 Oct 2022 09:50:42 -0700 Subject: [PATCH] Update Happiness Task --- Church.Net.DAL.EFCoreDBF/ChurchNetContext.cs | 5 +- .../20221001111411_AddLineId.Designer.cs | 884 +++++++++++++++++ .../Migrations/20221001111411_AddLineId.cs | 105 ++ ...20221001120825_RemoveAutoReply.Designer.cs | 882 +++++++++++++++++ .../20221001120825_RemoveAutoReply.cs | 79 ++ ...1002060819_MergeHappinessGroup.Designer.cs | 910 ++++++++++++++++++ .../20221002060819_MergeHappinessGroup.cs | 141 +++ ...002114621_RemoveHappinessGroup.Designer.cs | 843 ++++++++++++++++ .../20221002114621_RemoveHappinessGroup.cs | 107 ++ .../ChurchNetContextModelSnapshot.cs | 86 +- Church.Net.Entity2/AddressInfo.cs | 18 +- Church.Net.Entity2/HappinessBEST.cs | 2 +- Church.Net.Entity2/HappinessGroup.cs | 35 - Church.Net.Entity2/HappinessWeek.cs | 11 +- Church.Net.Entity2/LineBotInfo.cs | 24 - Church.Net.Entity2/PastoralDomain.cs | 18 +- WebAPI/Controllers/BestController.cs | 20 +- .../CellGroupRoutineEventsController.cs | 4 +- .../Controllers/HappinessGroupController.cs | 44 - .../HappinessWeekTaskController.cs | 23 + WebAPI/Controllers/LineMessageController.cs | 31 +- .../LineMessagingAccountController.cs | 13 + .../Controllers/PastoralDomainController.cs | 2 +- WebAPI/Controllers/PingController.cs | 49 +- ...sicAuthorizationMiddlewareResultHandler.cs | 17 + WebAPI/Logics/CellGroupLogic.cs | 65 -- WebAPI/Logics/Core/LogicBase.cs | 55 +- WebAPI/Logics/Core/LogicService.cs | 11 +- WebAPI/Logics/HappinessGroupLogic.cs | 85 -- WebAPI/Logics/Interface/ICrudLogic.cs | 6 +- WebAPI/Logics/LineMessagingAccountLogic.cs | 15 +- WebAPI/Logics/PastoralDomainLogic.cs | 240 +++++ .../AutoReplyCommands/ArArkCellGroupDinner.cs | 29 +- .../AutoReplyCommands/ArArkCellGroupInfo.cs | 39 +- .../AutoReplyCommands/ArArkCellGroupPrayer.cs | 78 +- .../AutoReplyCommands/ArChurchInfo.cs | 31 +- .../AutoReplyCommands/ArHappinessGroupTask.cs | 199 ++++ WebAPI/Services/IdentityService.cs | 44 +- .../Services/Interfaces/IAutoReplyCommand.cs | 10 +- WebAPI/Services/LineAutoBotService.cs | 169 ++-- .../Services/ScheduledTask/MorningPrayer.cs | 18 +- WebAPI/Services/WorkerService.cs | 35 +- WebAPI/Startup.cs | 45 +- 43 files changed, 4904 insertions(+), 623 deletions(-) create mode 100644 Church.Net.DAL.EFCoreDBF/Migrations/20221001111411_AddLineId.Designer.cs create mode 100644 Church.Net.DAL.EFCoreDBF/Migrations/20221001111411_AddLineId.cs create mode 100644 Church.Net.DAL.EFCoreDBF/Migrations/20221001120825_RemoveAutoReply.Designer.cs create mode 100644 Church.Net.DAL.EFCoreDBF/Migrations/20221001120825_RemoveAutoReply.cs create mode 100644 Church.Net.DAL.EFCoreDBF/Migrations/20221002060819_MergeHappinessGroup.Designer.cs create mode 100644 Church.Net.DAL.EFCoreDBF/Migrations/20221002060819_MergeHappinessGroup.cs create mode 100644 Church.Net.DAL.EFCoreDBF/Migrations/20221002114621_RemoveHappinessGroup.Designer.cs create mode 100644 Church.Net.DAL.EFCoreDBF/Migrations/20221002114621_RemoveHappinessGroup.cs delete mode 100644 Church.Net.Entity2/HappinessGroup.cs delete mode 100644 Church.Net.Entity2/LineBotInfo.cs delete mode 100644 WebAPI/Controllers/HappinessGroupController.cs create mode 100644 WebAPI/Controllers/HappinessWeekTaskController.cs delete mode 100644 WebAPI/Logics/CellGroupLogic.cs delete mode 100644 WebAPI/Logics/HappinessGroupLogic.cs create mode 100644 WebAPI/Logics/PastoralDomainLogic.cs create mode 100644 WebAPI/Services/AutoReplyCommands/ArHappinessGroupTask.cs diff --git a/Church.Net.DAL.EFCoreDBF/ChurchNetContext.cs b/Church.Net.DAL.EFCoreDBF/ChurchNetContext.cs index 1477ba8..1e2cc07 100644 --- a/Church.Net.DAL.EFCoreDBF/ChurchNetContext.cs +++ b/Church.Net.DAL.EFCoreDBF/ChurchNetContext.cs @@ -97,8 +97,8 @@ namespace Church.Net.DAL.EF modelBuilder.Entity() .HasOne(tt => tt.PastoralDomain) .WithMany(t => t.AutoReplyItemRelations) - .HasForeignKey(tt => tt.PastoralDomainCommunityAppId) - .HasPrincipalKey(tt => tt.CommunityAppId); + .HasForeignKey(tt => tt.PastoralDomainCommunityAppId); + //.HasPrincipalKey(tt => tt.L); //modelBuilder.Entity() // .HasOne(t => t.PastoralDomain) @@ -126,7 +126,6 @@ namespace Church.Net.DAL.EF public DbSet PastoralDomains { get; set; } public DbSet WhoIsSpy { get; set; } public DbSet Vocabulary { get; set; } - public DbSet HappinessGroups { get; set; } public DbSet HappinessBESTs { get; set; } public DbSet HappinessWeeks { get; set; } public DbSet CellGroupRoutineEvents { get; set; } diff --git a/Church.Net.DAL.EFCoreDBF/Migrations/20221001111411_AddLineId.Designer.cs b/Church.Net.DAL.EFCoreDBF/Migrations/20221001111411_AddLineId.Designer.cs new file mode 100644 index 0000000..17fb030 --- /dev/null +++ b/Church.Net.DAL.EFCoreDBF/Migrations/20221001111411_AddLineId.Designer.cs @@ -0,0 +1,884 @@ +// +using System; +using Church.Net.DAL.EF; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Church.Net.DAL.EFCoreDBF.Migrations +{ + [DbContext(typeof(ChurchNetContext))] + [Migration("20221001111411_AddLineId")] + partial class AddLineId + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Church.Net.Entity.AddressInfo", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("City") + .HasColumnType("text"); + + b.Property("State") + .HasColumnType("text"); + + b.Property("Zip") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AddressInfos"); + }); + + modelBuilder.Entity("Church.Net.Entity.AutoReplyItem", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Command") + .HasColumnType("text"); + + b.Property("Content") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AutoReplyItems"); + }); + + modelBuilder.Entity("Church.Net.Entity.Career", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.ToTable("Careers"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("PastoralDomainId") + .HasColumnType("text"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("PastoralDomainId"); + + b.ToTable("CellGroupRoutineEvents"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventAttendee", b => + { + b.Property("EventId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("Id") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("JoinPotluck") + .HasColumnType("boolean"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("PotluckItem") + .HasColumnType("text"); + + b.HasKey("EventId", "Id"); + + b.ToTable("CellGroupRoutineEventAttendees"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventPrayer", b => + { + b.Property("EventId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("MemberId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Prayer") + .HasColumnType("text"); + + b.HasKey("EventId", "MemberId"); + + b.ToTable("CellGroupRoutineEventPrayers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("AvatarImage") + .HasColumnType("text"); + + b.Property("Baptized") + .HasColumnType("boolean"); + + b.Property("Birthday") + .HasColumnType("timestamp with time zone"); + + b.Property("CareerId") + .HasColumnType("text"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("ComunityAppId") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("DateOfBaptized") + .HasColumnType("timestamp with time zone"); + + b.Property("DateOfWalkIn") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("FirstName") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Gender") + .HasColumnType("integer"); + + b.Property("LastName") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Married") + .HasColumnType("boolean"); + + b.Property("Password") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CareerId"); + + b.ToTable("FamilyMembers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMemberOAuth", b => + { + b.Property("FamilyMemberId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("OAuthType") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("OAuthAccessToken") + .HasColumnType("text"); + + b.HasKey("FamilyMemberId", "OAuthType"); + + b.ToTable("FamilyMemberOAuths"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessBEST", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.ToTable("HappinessBESTs"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("BeginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("CityAndZipCode") + .HasColumnType("text"); + + b.Property("CommunityAppId") + .HasColumnType("text"); + + b.Property("InvitationText") + .HasColumnType("text"); + + b.Property("LineAccountId") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("LineAccountId"); + + b.ToTable("HappinessGroups"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessTask", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Content") + .HasColumnType("text"); + + b.Property("Tasker") + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("WeekId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("WeekId"); + + b.ToTable("HappinessTask"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("CityAndZipCode") + .HasColumnType("text"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("GroupId") + .HasColumnType("text"); + + b.Property("InvitationText") + .HasColumnType("text"); + + b.Property("SEQ") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.ToTable("HappinessWeeks"); + }); + + modelBuilder.Entity("Church.Net.Entity.LineMessagingAccount", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ChatToken") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Seq") + .HasColumnType("integer"); + + b.Property("TotalUsage") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("LineMessagingAccounts"); + }); + + modelBuilder.Entity("Church.Net.Entity.LogInfo", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DetailMessage") + .HasColumnType("text"); + + b.Property("Level") + .HasColumnType("integer"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("Source") + .HasColumnType("text"); + + b.Property("StackTrace") + .HasColumnType("text"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.Property("TrackNo") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TrackNo")); + + b.Property("Url") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("LogInfos"); + }); + + modelBuilder.Entity("Church.Net.Entity.Messenger.LineMessageClient", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ClientId") + .HasColumnType("text"); + + b.Property("IsGroup") + .HasColumnType("boolean"); + + b.Property("IsManager") + .HasColumnType("boolean"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("LineMessageClients"); + }); + + modelBuilder.Entity("Church.Net.Entity.NewVisitor", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("ComunityAppId") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Email") + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Gender") + .HasColumnType("integer"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Note") + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("ReligionId") + .HasColumnType("integer"); + + b.Property("VisitingDate") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ReligionId"); + + b.ToTable("NewVisitors"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("CommunityAppId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Image1") + .HasColumnType("text"); + + b.Property("Image2") + .HasColumnType("text"); + + b.Property("Image3") + .HasColumnType("text"); + + b.Property("Image4") + .HasColumnType("text"); + + b.Property("Image5") + .HasColumnType("text"); + + b.Property("LeaderMemberId") + .HasColumnType("text"); + + b.Property("LineAccountId") + .HasColumnType("text"); + + b.Property("LogoImage") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ServiceAddressId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("LeaderMemberId"); + + b.HasIndex("LineAccountId"); + + b.HasIndex("ServiceAddressId"); + + b.ToTable("PastoralDomains"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainAutoReplys", b => + { + b.Property("PastoralDomainCommunityAppId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("AutoReplyItemId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.HasKey("PastoralDomainCommunityAppId", "AutoReplyItemId"); + + b.HasIndex("AutoReplyItemId"); + + b.ToTable("PastoralDomainAutoReplys"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainMembers", b => + { + b.Property("PastoralDomainId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("FamilyMemberId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.HasKey("PastoralDomainId", "FamilyMemberId"); + + b.HasIndex("FamilyMemberId"); + + b.ToTable("PastoralDomainMembers"); + }); + + modelBuilder.Entity("Church.Net.Entity.Religion", b => + { + b.Property("ReligionId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ReligionId")); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("ReligionId"); + + b.ToTable("Religions"); + }); + + modelBuilder.Entity("Church.Net.Entity.Vocabulary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DefinitionCh") + .IsRequired() + .HasColumnType("text"); + + b.Property("DefinitionEn") + .IsRequired() + .HasColumnType("text"); + + b.Property("FlashCardTimes") + .HasColumnType("integer"); + + b.Property("ImagesUrl") + .HasColumnType("text"); + + b.Property("InsertDate") + .HasColumnType("timestamp with time zone"); + + b.Property("NounPlural") + .HasColumnType("text"); + + b.Property("PartOfSpeech") + .HasColumnType("integer"); + + b.Property("PracticeApply") + .HasColumnType("boolean"); + + b.Property("PracticeDate") + .HasColumnType("timestamp with time zone"); + + b.Property("PracticeMemorized") + .HasColumnType("boolean"); + + b.Property("PracticeReview") + .HasColumnType("boolean"); + + b.Property("PracticeSelect") + .HasColumnType("boolean"); + + b.Property("PracticeSentence") + .HasColumnType("text"); + + b.Property("PracticeStage") + .HasColumnType("integer"); + + b.Property("PracticeVisualize") + .HasColumnType("boolean"); + + b.Property("VerbParticiple") + .HasColumnType("text"); + + b.Property("VerbPast") + .HasColumnType("text"); + + b.Property("Word") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Vocabulary"); + }); + + modelBuilder.Entity("Church.Net.Entity.WhoIsSpy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Answer1Chs") + .HasColumnType("text"); + + b.Property("Answer1Cht") + .HasColumnType("text"); + + b.Property("Answer1En") + .HasColumnType("text"); + + b.Property("Answer2Chs") + .HasColumnType("text"); + + b.Property("Answer2Cht") + .HasColumnType("text"); + + b.Property("Answer2En") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("WhoIsSpy"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.HasOne("Church.Net.Entity.PastoralDomain", "CellGroupInfo") + .WithMany() + .HasForeignKey("PastoralDomainId"); + + b.Navigation("CellGroupInfo"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventAttendee", b => + { + b.HasOne("Church.Net.Entity.CellGroupRoutineEvent", "CellGroupRoutineEvent") + .WithMany("Attendees") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CellGroupRoutineEvent"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventPrayer", b => + { + b.HasOne("Church.Net.Entity.CellGroupRoutineEvent", "CellGroupRoutineEvent") + .WithMany("Prayers") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CellGroupRoutineEvent"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.HasOne("Church.Net.Entity.Career", "Career") + .WithMany() + .HasForeignKey("CareerId"); + + b.Navigation("Career"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMemberOAuth", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", null) + .WithMany("OAuthInfos") + .HasForeignKey("FamilyMemberId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessBEST", b => + { + b.HasOne("Church.Net.Entity.HappinessGroup", "HappinessGroup") + .WithMany("BestList") + .HasForeignKey("GroupId"); + + b.Navigation("HappinessGroup"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => + { + b.HasOne("Church.Net.Entity.LineMessagingAccount", "LineMessagingAccount") + .WithMany() + .HasForeignKey("LineAccountId"); + + b.Navigation("LineMessagingAccount"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessTask", b => + { + b.HasOne("Church.Net.Entity.HappinessWeek", "HappinessWeek") + .WithMany("Tasks") + .HasForeignKey("WeekId"); + + b.Navigation("HappinessWeek"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.HasOne("Church.Net.Entity.HappinessGroup", "HappinessGroup") + .WithMany("Weeks") + .HasForeignKey("GroupId"); + + b.Navigation("HappinessGroup"); + }); + + modelBuilder.Entity("Church.Net.Entity.NewVisitor", b => + { + b.HasOne("Church.Net.Entity.Religion", "Religion") + .WithMany() + .HasForeignKey("ReligionId"); + + b.Navigation("Religion"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", "Leader") + .WithMany() + .HasForeignKey("LeaderMemberId"); + + b.HasOne("Church.Net.Entity.LineMessagingAccount", "LineMessagingAccount") + .WithMany() + .HasForeignKey("LineAccountId"); + + b.HasOne("Church.Net.Entity.AddressInfo", "ServiceAddress") + .WithMany() + .HasForeignKey("ServiceAddressId"); + + b.Navigation("Leader"); + + b.Navigation("LineMessagingAccount"); + + b.Navigation("ServiceAddress"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainAutoReplys", b => + { + b.HasOne("Church.Net.Entity.AutoReplyItem", "FamilyMember") + .WithMany("AutoReplyItemRelations") + .HasForeignKey("AutoReplyItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Church.Net.Entity.PastoralDomain", "PastoralDomain") + .WithMany("AutoReplyItemRelations") + .HasForeignKey("PastoralDomainCommunityAppId") + .HasPrincipalKey("CommunityAppId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FamilyMember"); + + b.Navigation("PastoralDomain"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainMembers", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", "FamilyMember") + .WithMany("PastoralDomains") + .HasForeignKey("FamilyMemberId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Church.Net.Entity.PastoralDomain", "PastoralDomain") + .WithMany("Members") + .HasForeignKey("PastoralDomainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FamilyMember"); + + b.Navigation("PastoralDomain"); + }); + + modelBuilder.Entity("Church.Net.Entity.AutoReplyItem", b => + { + b.Navigation("AutoReplyItemRelations"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.Navigation("Attendees"); + + b.Navigation("Prayers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.Navigation("OAuthInfos"); + + b.Navigation("PastoralDomains"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => + { + b.Navigation("BestList"); + + b.Navigation("Weeks"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.Navigation("Tasks"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.Navigation("AutoReplyItemRelations"); + + b.Navigation("Members"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Church.Net.DAL.EFCoreDBF/Migrations/20221001111411_AddLineId.cs b/Church.Net.DAL.EFCoreDBF/Migrations/20221001111411_AddLineId.cs new file mode 100644 index 0000000..dfc0b10 --- /dev/null +++ b/Church.Net.DAL.EFCoreDBF/Migrations/20221001111411_AddLineId.cs @@ -0,0 +1,105 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Church.Net.DAL.EFCoreDBF.Migrations +{ + public partial class AddLineId : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "LineAccountId", + table: "PastoralDomains", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "LineAccountId", + table: "HappinessGroups", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "PastoralDomainId", + table: "CellGroupRoutineEvents", + type: "text", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_PastoralDomains_LineAccountId", + table: "PastoralDomains", + column: "LineAccountId"); + + migrationBuilder.CreateIndex( + name: "IX_HappinessGroups_LineAccountId", + table: "HappinessGroups", + column: "LineAccountId"); + + migrationBuilder.CreateIndex( + name: "IX_CellGroupRoutineEvents_PastoralDomainId", + table: "CellGroupRoutineEvents", + column: "PastoralDomainId"); + + migrationBuilder.AddForeignKey( + name: "FK_CellGroupRoutineEvents_PastoralDomains_PastoralDomainId", + table: "CellGroupRoutineEvents", + column: "PastoralDomainId", + principalTable: "PastoralDomains", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_HappinessGroups_LineMessagingAccounts_LineAccountId", + table: "HappinessGroups", + column: "LineAccountId", + principalTable: "LineMessagingAccounts", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_PastoralDomains_LineMessagingAccounts_LineAccountId", + table: "PastoralDomains", + column: "LineAccountId", + principalTable: "LineMessagingAccounts", + principalColumn: "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_CellGroupRoutineEvents_PastoralDomains_PastoralDomainId", + table: "CellGroupRoutineEvents"); + + migrationBuilder.DropForeignKey( + name: "FK_HappinessGroups_LineMessagingAccounts_LineAccountId", + table: "HappinessGroups"); + + migrationBuilder.DropForeignKey( + name: "FK_PastoralDomains_LineMessagingAccounts_LineAccountId", + table: "PastoralDomains"); + + migrationBuilder.DropIndex( + name: "IX_PastoralDomains_LineAccountId", + table: "PastoralDomains"); + + migrationBuilder.DropIndex( + name: "IX_HappinessGroups_LineAccountId", + table: "HappinessGroups"); + + migrationBuilder.DropIndex( + name: "IX_CellGroupRoutineEvents_PastoralDomainId", + table: "CellGroupRoutineEvents"); + + migrationBuilder.DropColumn( + name: "LineAccountId", + table: "PastoralDomains"); + + migrationBuilder.DropColumn( + name: "LineAccountId", + table: "HappinessGroups"); + + migrationBuilder.DropColumn( + name: "PastoralDomainId", + table: "CellGroupRoutineEvents"); + } + } +} diff --git a/Church.Net.DAL.EFCoreDBF/Migrations/20221001120825_RemoveAutoReply.Designer.cs b/Church.Net.DAL.EFCoreDBF/Migrations/20221001120825_RemoveAutoReply.Designer.cs new file mode 100644 index 0000000..61c09a0 --- /dev/null +++ b/Church.Net.DAL.EFCoreDBF/Migrations/20221001120825_RemoveAutoReply.Designer.cs @@ -0,0 +1,882 @@ +// +using System; +using Church.Net.DAL.EF; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Church.Net.DAL.EFCoreDBF.Migrations +{ + [DbContext(typeof(ChurchNetContext))] + [Migration("20221001120825_RemoveAutoReply")] + partial class RemoveAutoReply + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Church.Net.Entity.AddressInfo", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("City") + .HasColumnType("text"); + + b.Property("State") + .HasColumnType("text"); + + b.Property("Zip") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AddressInfos"); + }); + + modelBuilder.Entity("Church.Net.Entity.AutoReplyItem", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Command") + .HasColumnType("text"); + + b.Property("Content") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AutoReplyItems"); + }); + + modelBuilder.Entity("Church.Net.Entity.Career", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.ToTable("Careers"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("PastoralDomainId") + .HasColumnType("text"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("PastoralDomainId"); + + b.ToTable("CellGroupRoutineEvents"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventAttendee", b => + { + b.Property("EventId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("Id") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("JoinPotluck") + .HasColumnType("boolean"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("PotluckItem") + .HasColumnType("text"); + + b.HasKey("EventId", "Id"); + + b.ToTable("CellGroupRoutineEventAttendees"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventPrayer", b => + { + b.Property("EventId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("MemberId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Prayer") + .HasColumnType("text"); + + b.HasKey("EventId", "MemberId"); + + b.ToTable("CellGroupRoutineEventPrayers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("AvatarImage") + .HasColumnType("text"); + + b.Property("Baptized") + .HasColumnType("boolean"); + + b.Property("Birthday") + .HasColumnType("timestamp with time zone"); + + b.Property("CareerId") + .HasColumnType("text"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("ComunityAppId") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("DateOfBaptized") + .HasColumnType("timestamp with time zone"); + + b.Property("DateOfWalkIn") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("FirstName") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Gender") + .HasColumnType("integer"); + + b.Property("LastName") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Married") + .HasColumnType("boolean"); + + b.Property("Password") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CareerId"); + + b.ToTable("FamilyMembers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMemberOAuth", b => + { + b.Property("FamilyMemberId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("OAuthType") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("OAuthAccessToken") + .HasColumnType("text"); + + b.HasKey("FamilyMemberId", "OAuthType"); + + b.ToTable("FamilyMemberOAuths"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessBEST", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.ToTable("HappinessBESTs"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("BeginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("CityAndZipCode") + .HasColumnType("text"); + + b.Property("InvitationText") + .HasColumnType("text"); + + b.Property("LineAccountId") + .HasColumnType("text"); + + b.Property("LineGroupId") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("LineAccountId"); + + b.ToTable("HappinessGroups"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessTask", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Content") + .HasColumnType("text"); + + b.Property("Tasker") + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("WeekId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("WeekId"); + + b.ToTable("HappinessTask"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("CityAndZipCode") + .HasColumnType("text"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("GroupId") + .HasColumnType("text"); + + b.Property("InvitationText") + .HasColumnType("text"); + + b.Property("SEQ") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.ToTable("HappinessWeeks"); + }); + + modelBuilder.Entity("Church.Net.Entity.LineMessagingAccount", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ChatToken") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Seq") + .HasColumnType("integer"); + + b.Property("TotalUsage") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("LineMessagingAccounts"); + }); + + modelBuilder.Entity("Church.Net.Entity.LogInfo", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DetailMessage") + .HasColumnType("text"); + + b.Property("Level") + .HasColumnType("integer"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("Source") + .HasColumnType("text"); + + b.Property("StackTrace") + .HasColumnType("text"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.Property("TrackNo") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TrackNo")); + + b.Property("Url") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("LogInfos"); + }); + + modelBuilder.Entity("Church.Net.Entity.Messenger.LineMessageClient", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ClientId") + .HasColumnType("text"); + + b.Property("IsGroup") + .HasColumnType("boolean"); + + b.Property("IsManager") + .HasColumnType("boolean"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("LineMessageClients"); + }); + + modelBuilder.Entity("Church.Net.Entity.NewVisitor", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("ComunityAppId") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Email") + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Gender") + .HasColumnType("integer"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Note") + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("ReligionId") + .HasColumnType("integer"); + + b.Property("VisitingDate") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ReligionId"); + + b.ToTable("NewVisitors"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Image1") + .HasColumnType("text"); + + b.Property("Image2") + .HasColumnType("text"); + + b.Property("Image3") + .HasColumnType("text"); + + b.Property("Image4") + .HasColumnType("text"); + + b.Property("Image5") + .HasColumnType("text"); + + b.Property("LeaderMemberId") + .HasColumnType("text"); + + b.Property("LineAccountId") + .HasColumnType("text"); + + b.Property("LineGroupId") + .HasColumnType("text"); + + b.Property("LogoImage") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ServiceAddressId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("LeaderMemberId"); + + b.HasIndex("LineAccountId"); + + b.HasIndex("ServiceAddressId"); + + b.ToTable("PastoralDomains"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainAutoReplys", b => + { + b.Property("PastoralDomainCommunityAppId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("AutoReplyItemId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.HasKey("PastoralDomainCommunityAppId", "AutoReplyItemId"); + + b.HasIndex("AutoReplyItemId"); + + b.ToTable("PastoralDomainAutoReplys"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainMembers", b => + { + b.Property("PastoralDomainId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("FamilyMemberId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.HasKey("PastoralDomainId", "FamilyMemberId"); + + b.HasIndex("FamilyMemberId"); + + b.ToTable("PastoralDomainMembers"); + }); + + modelBuilder.Entity("Church.Net.Entity.Religion", b => + { + b.Property("ReligionId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ReligionId")); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("ReligionId"); + + b.ToTable("Religions"); + }); + + modelBuilder.Entity("Church.Net.Entity.Vocabulary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DefinitionCh") + .IsRequired() + .HasColumnType("text"); + + b.Property("DefinitionEn") + .IsRequired() + .HasColumnType("text"); + + b.Property("FlashCardTimes") + .HasColumnType("integer"); + + b.Property("ImagesUrl") + .HasColumnType("text"); + + b.Property("InsertDate") + .HasColumnType("timestamp with time zone"); + + b.Property("NounPlural") + .HasColumnType("text"); + + b.Property("PartOfSpeech") + .HasColumnType("integer"); + + b.Property("PracticeApply") + .HasColumnType("boolean"); + + b.Property("PracticeDate") + .HasColumnType("timestamp with time zone"); + + b.Property("PracticeMemorized") + .HasColumnType("boolean"); + + b.Property("PracticeReview") + .HasColumnType("boolean"); + + b.Property("PracticeSelect") + .HasColumnType("boolean"); + + b.Property("PracticeSentence") + .HasColumnType("text"); + + b.Property("PracticeStage") + .HasColumnType("integer"); + + b.Property("PracticeVisualize") + .HasColumnType("boolean"); + + b.Property("VerbParticiple") + .HasColumnType("text"); + + b.Property("VerbPast") + .HasColumnType("text"); + + b.Property("Word") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Vocabulary"); + }); + + modelBuilder.Entity("Church.Net.Entity.WhoIsSpy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Answer1Chs") + .HasColumnType("text"); + + b.Property("Answer1Cht") + .HasColumnType("text"); + + b.Property("Answer1En") + .HasColumnType("text"); + + b.Property("Answer2Chs") + .HasColumnType("text"); + + b.Property("Answer2Cht") + .HasColumnType("text"); + + b.Property("Answer2En") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("WhoIsSpy"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.HasOne("Church.Net.Entity.PastoralDomain", "CellGroupInfo") + .WithMany() + .HasForeignKey("PastoralDomainId"); + + b.Navigation("CellGroupInfo"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventAttendee", b => + { + b.HasOne("Church.Net.Entity.CellGroupRoutineEvent", "CellGroupRoutineEvent") + .WithMany("Attendees") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CellGroupRoutineEvent"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventPrayer", b => + { + b.HasOne("Church.Net.Entity.CellGroupRoutineEvent", "CellGroupRoutineEvent") + .WithMany("Prayers") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CellGroupRoutineEvent"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.HasOne("Church.Net.Entity.Career", "Career") + .WithMany() + .HasForeignKey("CareerId"); + + b.Navigation("Career"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMemberOAuth", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", null) + .WithMany("OAuthInfos") + .HasForeignKey("FamilyMemberId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessBEST", b => + { + b.HasOne("Church.Net.Entity.HappinessGroup", "HappinessGroup") + .WithMany("BestList") + .HasForeignKey("GroupId"); + + b.Navigation("HappinessGroup"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => + { + b.HasOne("Church.Net.Entity.LineMessagingAccount", "LineMessagingAccount") + .WithMany() + .HasForeignKey("LineAccountId"); + + b.Navigation("LineMessagingAccount"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessTask", b => + { + b.HasOne("Church.Net.Entity.HappinessWeek", "HappinessWeek") + .WithMany("Tasks") + .HasForeignKey("WeekId"); + + b.Navigation("HappinessWeek"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.HasOne("Church.Net.Entity.HappinessGroup", "HappinessGroup") + .WithMany("Weeks") + .HasForeignKey("GroupId"); + + b.Navigation("HappinessGroup"); + }); + + modelBuilder.Entity("Church.Net.Entity.NewVisitor", b => + { + b.HasOne("Church.Net.Entity.Religion", "Religion") + .WithMany() + .HasForeignKey("ReligionId"); + + b.Navigation("Religion"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", "Leader") + .WithMany() + .HasForeignKey("LeaderMemberId"); + + b.HasOne("Church.Net.Entity.LineMessagingAccount", "LineMessagingAccount") + .WithMany() + .HasForeignKey("LineAccountId"); + + b.HasOne("Church.Net.Entity.AddressInfo", "ServiceAddress") + .WithMany() + .HasForeignKey("ServiceAddressId"); + + b.Navigation("Leader"); + + b.Navigation("LineMessagingAccount"); + + b.Navigation("ServiceAddress"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainAutoReplys", b => + { + b.HasOne("Church.Net.Entity.AutoReplyItem", "FamilyMember") + .WithMany("AutoReplyItemRelations") + .HasForeignKey("AutoReplyItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Church.Net.Entity.PastoralDomain", "PastoralDomain") + .WithMany("AutoReplyItemRelations") + .HasForeignKey("PastoralDomainCommunityAppId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FamilyMember"); + + b.Navigation("PastoralDomain"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainMembers", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", "FamilyMember") + .WithMany("PastoralDomains") + .HasForeignKey("FamilyMemberId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Church.Net.Entity.PastoralDomain", "PastoralDomain") + .WithMany("Members") + .HasForeignKey("PastoralDomainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FamilyMember"); + + b.Navigation("PastoralDomain"); + }); + + modelBuilder.Entity("Church.Net.Entity.AutoReplyItem", b => + { + b.Navigation("AutoReplyItemRelations"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.Navigation("Attendees"); + + b.Navigation("Prayers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.Navigation("OAuthInfos"); + + b.Navigation("PastoralDomains"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => + { + b.Navigation("BestList"); + + b.Navigation("Weeks"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.Navigation("Tasks"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.Navigation("AutoReplyItemRelations"); + + b.Navigation("Members"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Church.Net.DAL.EFCoreDBF/Migrations/20221001120825_RemoveAutoReply.cs b/Church.Net.DAL.EFCoreDBF/Migrations/20221001120825_RemoveAutoReply.cs new file mode 100644 index 0000000..1cd797f --- /dev/null +++ b/Church.Net.DAL.EFCoreDBF/Migrations/20221001120825_RemoveAutoReply.cs @@ -0,0 +1,79 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Church.Net.DAL.EFCoreDBF.Migrations +{ + public partial class RemoveAutoReply : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_PastoralDomainAutoReplys_PastoralDomains_PastoralDomainComm~", + table: "PastoralDomainAutoReplys"); + + migrationBuilder.DropUniqueConstraint( + name: "AK_PastoralDomains_CommunityAppId", + table: "PastoralDomains"); + + migrationBuilder.DropColumn( + name: "CommunityAppId", + table: "PastoralDomains"); + + migrationBuilder.RenameColumn( + name: "CommunityAppId", + table: "HappinessGroups", + newName: "LineGroupId"); + + migrationBuilder.AddColumn( + name: "LineGroupId", + table: "PastoralDomains", + type: "text", + nullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_PastoralDomainAutoReplys_PastoralDomains_PastoralDomainComm~", + table: "PastoralDomainAutoReplys", + column: "PastoralDomainCommunityAppId", + principalTable: "PastoralDomains", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_PastoralDomainAutoReplys_PastoralDomains_PastoralDomainComm~", + table: "PastoralDomainAutoReplys"); + + migrationBuilder.DropColumn( + name: "LineGroupId", + table: "PastoralDomains"); + + migrationBuilder.RenameColumn( + name: "LineGroupId", + table: "HappinessGroups", + newName: "CommunityAppId"); + + migrationBuilder.AddColumn( + name: "CommunityAppId", + table: "PastoralDomains", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddUniqueConstraint( + name: "AK_PastoralDomains_CommunityAppId", + table: "PastoralDomains", + column: "CommunityAppId"); + + migrationBuilder.AddForeignKey( + name: "FK_PastoralDomainAutoReplys_PastoralDomains_PastoralDomainComm~", + table: "PastoralDomainAutoReplys", + column: "PastoralDomainCommunityAppId", + principalTable: "PastoralDomains", + principalColumn: "CommunityAppId", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/Church.Net.DAL.EFCoreDBF/Migrations/20221002060819_MergeHappinessGroup.Designer.cs b/Church.Net.DAL.EFCoreDBF/Migrations/20221002060819_MergeHappinessGroup.Designer.cs new file mode 100644 index 0000000..431e230 --- /dev/null +++ b/Church.Net.DAL.EFCoreDBF/Migrations/20221002060819_MergeHappinessGroup.Designer.cs @@ -0,0 +1,910 @@ +// +using System; +using Church.Net.DAL.EF; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Church.Net.DAL.EFCoreDBF.Migrations +{ + [DbContext(typeof(ChurchNetContext))] + [Migration("20221002060819_MergeHappinessGroup")] + partial class MergeHappinessGroup + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Church.Net.Entity.AddressInfo", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("City") + .HasColumnType("text"); + + b.Property("State") + .HasColumnType("text"); + + b.Property("Zip") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AddressInfos"); + }); + + modelBuilder.Entity("Church.Net.Entity.AutoReplyItem", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Command") + .HasColumnType("text"); + + b.Property("Content") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AutoReplyItems"); + }); + + modelBuilder.Entity("Church.Net.Entity.Career", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.ToTable("Careers"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("PastoralDomainId") + .HasColumnType("text"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("PastoralDomainId"); + + b.ToTable("CellGroupRoutineEvents"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventAttendee", b => + { + b.Property("EventId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("Id") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("JoinPotluck") + .HasColumnType("boolean"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("PotluckItem") + .HasColumnType("text"); + + b.HasKey("EventId", "Id"); + + b.ToTable("CellGroupRoutineEventAttendees"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventPrayer", b => + { + b.Property("EventId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("MemberId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Prayer") + .HasColumnType("text"); + + b.HasKey("EventId", "MemberId"); + + b.ToTable("CellGroupRoutineEventPrayers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("AvatarImage") + .HasColumnType("text"); + + b.Property("Baptized") + .HasColumnType("boolean"); + + b.Property("Birthday") + .HasColumnType("timestamp with time zone"); + + b.Property("CareerId") + .HasColumnType("text"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("ComunityAppId") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("DateOfBaptized") + .HasColumnType("timestamp with time zone"); + + b.Property("DateOfWalkIn") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("FirstName") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Gender") + .HasColumnType("integer"); + + b.Property("LastName") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Married") + .HasColumnType("boolean"); + + b.Property("Password") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CareerId"); + + b.ToTable("FamilyMembers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMemberOAuth", b => + { + b.Property("FamilyMemberId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("OAuthType") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("OAuthAccessToken") + .HasColumnType("text"); + + b.HasKey("FamilyMemberId", "OAuthType"); + + b.ToTable("FamilyMemberOAuths"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessBEST", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("text"); + + b.Property("HappinessGroupId") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.HasIndex("HappinessGroupId"); + + b.ToTable("HappinessBESTs"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("BeginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("CityAndZipCode") + .HasColumnType("text"); + + b.Property("InvitationText") + .HasColumnType("text"); + + b.Property("LineAccountId") + .HasColumnType("text"); + + b.Property("LineGroupId") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("LineAccountId"); + + b.ToTable("HappinessGroups"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessTask", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Content") + .HasColumnType("text"); + + b.Property("Tasker") + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("WeekId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("WeekId"); + + b.ToTable("HappinessTask"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("CityAndZipCode") + .HasColumnType("text"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("GroupId") + .HasColumnType("text"); + + b.Property("HappinessGroupId") + .HasColumnType("text"); + + b.Property("InvitationText") + .HasColumnType("text"); + + b.Property("SEQ") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.HasIndex("HappinessGroupId"); + + b.ToTable("HappinessWeeks"); + }); + + modelBuilder.Entity("Church.Net.Entity.LineMessagingAccount", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ChatToken") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Seq") + .HasColumnType("integer"); + + b.Property("TotalUsage") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("LineMessagingAccounts"); + }); + + modelBuilder.Entity("Church.Net.Entity.LogInfo", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DetailMessage") + .HasColumnType("text"); + + b.Property("Level") + .HasColumnType("integer"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("Source") + .HasColumnType("text"); + + b.Property("StackTrace") + .HasColumnType("text"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.Property("TrackNo") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TrackNo")); + + b.Property("Url") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("LogInfos"); + }); + + modelBuilder.Entity("Church.Net.Entity.Messenger.LineMessageClient", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ClientId") + .HasColumnType("text"); + + b.Property("IsGroup") + .HasColumnType("boolean"); + + b.Property("IsManager") + .HasColumnType("boolean"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("LineMessageClients"); + }); + + modelBuilder.Entity("Church.Net.Entity.NewVisitor", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("ComunityAppId") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Email") + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Gender") + .HasColumnType("integer"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Note") + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("ReligionId") + .HasColumnType("integer"); + + b.Property("VisitingDate") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ReligionId"); + + b.ToTable("NewVisitors"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Image1") + .HasColumnType("text"); + + b.Property("Image2") + .HasColumnType("text"); + + b.Property("Image3") + .HasColumnType("text"); + + b.Property("Image4") + .HasColumnType("text"); + + b.Property("Image5") + .HasColumnType("text"); + + b.Property("LeaderMemberId") + .HasColumnType("text"); + + b.Property("LineAccountId") + .HasColumnType("text"); + + b.Property("LineGroupId") + .HasColumnType("text"); + + b.Property("LogoImage") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ServiceAddressId") + .HasColumnType("text"); + + b.Property("ServiceTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("LeaderMemberId"); + + b.HasIndex("LineAccountId"); + + b.HasIndex("ServiceAddressId"); + + b.ToTable("PastoralDomains"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainAutoReplys", b => + { + b.Property("PastoralDomainCommunityAppId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("AutoReplyItemId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.HasKey("PastoralDomainCommunityAppId", "AutoReplyItemId"); + + b.HasIndex("AutoReplyItemId"); + + b.ToTable("PastoralDomainAutoReplys"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainMembers", b => + { + b.Property("PastoralDomainId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("FamilyMemberId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.HasKey("PastoralDomainId", "FamilyMemberId"); + + b.HasIndex("FamilyMemberId"); + + b.ToTable("PastoralDomainMembers"); + }); + + modelBuilder.Entity("Church.Net.Entity.Religion", b => + { + b.Property("ReligionId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ReligionId")); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("ReligionId"); + + b.ToTable("Religions"); + }); + + modelBuilder.Entity("Church.Net.Entity.Vocabulary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DefinitionCh") + .IsRequired() + .HasColumnType("text"); + + b.Property("DefinitionEn") + .IsRequired() + .HasColumnType("text"); + + b.Property("FlashCardTimes") + .HasColumnType("integer"); + + b.Property("ImagesUrl") + .HasColumnType("text"); + + b.Property("InsertDate") + .HasColumnType("timestamp with time zone"); + + b.Property("NounPlural") + .HasColumnType("text"); + + b.Property("PartOfSpeech") + .HasColumnType("integer"); + + b.Property("PracticeApply") + .HasColumnType("boolean"); + + b.Property("PracticeDate") + .HasColumnType("timestamp with time zone"); + + b.Property("PracticeMemorized") + .HasColumnType("boolean"); + + b.Property("PracticeReview") + .HasColumnType("boolean"); + + b.Property("PracticeSelect") + .HasColumnType("boolean"); + + b.Property("PracticeSentence") + .HasColumnType("text"); + + b.Property("PracticeStage") + .HasColumnType("integer"); + + b.Property("PracticeVisualize") + .HasColumnType("boolean"); + + b.Property("VerbParticiple") + .HasColumnType("text"); + + b.Property("VerbPast") + .HasColumnType("text"); + + b.Property("Word") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Vocabulary"); + }); + + modelBuilder.Entity("Church.Net.Entity.WhoIsSpy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Answer1Chs") + .HasColumnType("text"); + + b.Property("Answer1Cht") + .HasColumnType("text"); + + b.Property("Answer1En") + .HasColumnType("text"); + + b.Property("Answer2Chs") + .HasColumnType("text"); + + b.Property("Answer2Cht") + .HasColumnType("text"); + + b.Property("Answer2En") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("WhoIsSpy"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.HasOne("Church.Net.Entity.PastoralDomain", "CellGroupInfo") + .WithMany() + .HasForeignKey("PastoralDomainId"); + + b.Navigation("CellGroupInfo"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventAttendee", b => + { + b.HasOne("Church.Net.Entity.CellGroupRoutineEvent", "CellGroupRoutineEvent") + .WithMany("Attendees") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CellGroupRoutineEvent"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventPrayer", b => + { + b.HasOne("Church.Net.Entity.CellGroupRoutineEvent", "CellGroupRoutineEvent") + .WithMany("Prayers") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CellGroupRoutineEvent"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.HasOne("Church.Net.Entity.Career", "Career") + .WithMany() + .HasForeignKey("CareerId"); + + b.Navigation("Career"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMemberOAuth", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", null) + .WithMany("OAuthInfos") + .HasForeignKey("FamilyMemberId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessBEST", b => + { + b.HasOne("Church.Net.Entity.PastoralDomain", "HappinessGroup") + .WithMany("Bests") + .HasForeignKey("GroupId"); + + b.HasOne("Church.Net.Entity.HappinessGroup", null) + .WithMany("BestList") + .HasForeignKey("HappinessGroupId"); + + b.Navigation("HappinessGroup"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => + { + b.HasOne("Church.Net.Entity.LineMessagingAccount", "LineMessagingAccount") + .WithMany() + .HasForeignKey("LineAccountId"); + + b.Navigation("LineMessagingAccount"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessTask", b => + { + b.HasOne("Church.Net.Entity.HappinessWeek", "HappinessWeek") + .WithMany("Tasks") + .HasForeignKey("WeekId"); + + b.Navigation("HappinessWeek"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.HasOne("Church.Net.Entity.PastoralDomain", "HappinessGroup") + .WithMany("HappinessWeeks") + .HasForeignKey("GroupId"); + + b.HasOne("Church.Net.Entity.HappinessGroup", null) + .WithMany("Weeks") + .HasForeignKey("HappinessGroupId"); + + b.Navigation("HappinessGroup"); + }); + + modelBuilder.Entity("Church.Net.Entity.NewVisitor", b => + { + b.HasOne("Church.Net.Entity.Religion", "Religion") + .WithMany() + .HasForeignKey("ReligionId"); + + b.Navigation("Religion"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", "Leader") + .WithMany() + .HasForeignKey("LeaderMemberId"); + + b.HasOne("Church.Net.Entity.LineMessagingAccount", "LineMessagingAccount") + .WithMany() + .HasForeignKey("LineAccountId"); + + b.HasOne("Church.Net.Entity.AddressInfo", "ServiceAddress") + .WithMany() + .HasForeignKey("ServiceAddressId"); + + b.Navigation("Leader"); + + b.Navigation("LineMessagingAccount"); + + b.Navigation("ServiceAddress"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainAutoReplys", b => + { + b.HasOne("Church.Net.Entity.AutoReplyItem", "FamilyMember") + .WithMany("AutoReplyItemRelations") + .HasForeignKey("AutoReplyItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Church.Net.Entity.PastoralDomain", "PastoralDomain") + .WithMany("AutoReplyItemRelations") + .HasForeignKey("PastoralDomainCommunityAppId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FamilyMember"); + + b.Navigation("PastoralDomain"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainMembers", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", "FamilyMember") + .WithMany("PastoralDomains") + .HasForeignKey("FamilyMemberId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Church.Net.Entity.PastoralDomain", "PastoralDomain") + .WithMany("Members") + .HasForeignKey("PastoralDomainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FamilyMember"); + + b.Navigation("PastoralDomain"); + }); + + modelBuilder.Entity("Church.Net.Entity.AutoReplyItem", b => + { + b.Navigation("AutoReplyItemRelations"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.Navigation("Attendees"); + + b.Navigation("Prayers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.Navigation("OAuthInfos"); + + b.Navigation("PastoralDomains"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => + { + b.Navigation("BestList"); + + b.Navigation("Weeks"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.Navigation("Tasks"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.Navigation("AutoReplyItemRelations"); + + b.Navigation("Bests"); + + b.Navigation("HappinessWeeks"); + + b.Navigation("Members"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Church.Net.DAL.EFCoreDBF/Migrations/20221002060819_MergeHappinessGroup.cs b/Church.Net.DAL.EFCoreDBF/Migrations/20221002060819_MergeHappinessGroup.cs new file mode 100644 index 0000000..a9a723c --- /dev/null +++ b/Church.Net.DAL.EFCoreDBF/Migrations/20221002060819_MergeHappinessGroup.cs @@ -0,0 +1,141 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Church.Net.DAL.EFCoreDBF.Migrations +{ + public partial class MergeHappinessGroup : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_HappinessBESTs_HappinessGroups_GroupId", + table: "HappinessBESTs"); + + migrationBuilder.DropForeignKey( + name: "FK_HappinessWeeks_HappinessGroups_GroupId", + table: "HappinessWeeks"); + + migrationBuilder.AddColumn( + name: "ServiceTime", + table: "PastoralDomains", + type: "timestamp with time zone", + nullable: true); + + migrationBuilder.AddColumn( + name: "Type", + table: "PastoralDomains", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "HappinessGroupId", + table: "HappinessWeeks", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "HappinessGroupId", + table: "HappinessBESTs", + type: "text", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_HappinessWeeks_HappinessGroupId", + table: "HappinessWeeks", + column: "HappinessGroupId"); + + migrationBuilder.CreateIndex( + name: "IX_HappinessBESTs_HappinessGroupId", + table: "HappinessBESTs", + column: "HappinessGroupId"); + + migrationBuilder.AddForeignKey( + name: "FK_HappinessBESTs_HappinessGroups_HappinessGroupId", + table: "HappinessBESTs", + column: "HappinessGroupId", + principalTable: "HappinessGroups", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_HappinessBESTs_PastoralDomains_GroupId", + table: "HappinessBESTs", + column: "GroupId", + principalTable: "PastoralDomains", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_HappinessWeeks_HappinessGroups_HappinessGroupId", + table: "HappinessWeeks", + column: "HappinessGroupId", + principalTable: "HappinessGroups", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_HappinessWeeks_PastoralDomains_GroupId", + table: "HappinessWeeks", + column: "GroupId", + principalTable: "PastoralDomains", + principalColumn: "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_HappinessBESTs_HappinessGroups_HappinessGroupId", + table: "HappinessBESTs"); + + migrationBuilder.DropForeignKey( + name: "FK_HappinessBESTs_PastoralDomains_GroupId", + table: "HappinessBESTs"); + + migrationBuilder.DropForeignKey( + name: "FK_HappinessWeeks_HappinessGroups_HappinessGroupId", + table: "HappinessWeeks"); + + migrationBuilder.DropForeignKey( + name: "FK_HappinessWeeks_PastoralDomains_GroupId", + table: "HappinessWeeks"); + + migrationBuilder.DropIndex( + name: "IX_HappinessWeeks_HappinessGroupId", + table: "HappinessWeeks"); + + migrationBuilder.DropIndex( + name: "IX_HappinessBESTs_HappinessGroupId", + table: "HappinessBESTs"); + + migrationBuilder.DropColumn( + name: "ServiceTime", + table: "PastoralDomains"); + + migrationBuilder.DropColumn( + name: "Type", + table: "PastoralDomains"); + + migrationBuilder.DropColumn( + name: "HappinessGroupId", + table: "HappinessWeeks"); + + migrationBuilder.DropColumn( + name: "HappinessGroupId", + table: "HappinessBESTs"); + + migrationBuilder.AddForeignKey( + name: "FK_HappinessBESTs_HappinessGroups_GroupId", + table: "HappinessBESTs", + column: "GroupId", + principalTable: "HappinessGroups", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_HappinessWeeks_HappinessGroups_GroupId", + table: "HappinessWeeks", + column: "GroupId", + principalTable: "HappinessGroups", + principalColumn: "Id"); + } + } +} diff --git a/Church.Net.DAL.EFCoreDBF/Migrations/20221002114621_RemoveHappinessGroup.Designer.cs b/Church.Net.DAL.EFCoreDBF/Migrations/20221002114621_RemoveHappinessGroup.Designer.cs new file mode 100644 index 0000000..6580319 --- /dev/null +++ b/Church.Net.DAL.EFCoreDBF/Migrations/20221002114621_RemoveHappinessGroup.Designer.cs @@ -0,0 +1,843 @@ +// +using System; +using Church.Net.DAL.EF; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Church.Net.DAL.EFCoreDBF.Migrations +{ + [DbContext(typeof(ChurchNetContext))] + [Migration("20221002114621_RemoveHappinessGroup")] + partial class RemoveHappinessGroup + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Church.Net.Entity.AddressInfo", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("City") + .HasColumnType("text"); + + b.Property("State") + .HasColumnType("text"); + + b.Property("Zip") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AddressInfos"); + }); + + modelBuilder.Entity("Church.Net.Entity.AutoReplyItem", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Command") + .HasColumnType("text"); + + b.Property("Content") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AutoReplyItems"); + }); + + modelBuilder.Entity("Church.Net.Entity.Career", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.ToTable("Careers"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("PastoralDomainId") + .HasColumnType("text"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("PastoralDomainId"); + + b.ToTable("CellGroupRoutineEvents"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventAttendee", b => + { + b.Property("EventId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("Id") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("JoinPotluck") + .HasColumnType("boolean"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("PotluckItem") + .HasColumnType("text"); + + b.HasKey("EventId", "Id"); + + b.ToTable("CellGroupRoutineEventAttendees"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventPrayer", b => + { + b.Property("EventId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("MemberId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Prayer") + .HasColumnType("text"); + + b.HasKey("EventId", "MemberId"); + + b.ToTable("CellGroupRoutineEventPrayers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("AvatarImage") + .HasColumnType("text"); + + b.Property("Baptized") + .HasColumnType("boolean"); + + b.Property("Birthday") + .HasColumnType("timestamp with time zone"); + + b.Property("CareerId") + .HasColumnType("text"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("ComunityAppId") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("DateOfBaptized") + .HasColumnType("timestamp with time zone"); + + b.Property("DateOfWalkIn") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("FirstName") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Gender") + .HasColumnType("integer"); + + b.Property("LastName") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Married") + .HasColumnType("boolean"); + + b.Property("Password") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CareerId"); + + b.ToTable("FamilyMembers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMemberOAuth", b => + { + b.Property("FamilyMemberId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("OAuthType") + .HasColumnType("text") + .HasColumnOrder(1); + + b.Property("OAuthAccessToken") + .HasColumnType("text"); + + b.HasKey("FamilyMemberId", "OAuthType"); + + b.ToTable("FamilyMemberOAuths"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessBEST", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("GroupId") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.ToTable("HappinessBESTs"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessTask", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Content") + .HasColumnType("text"); + + b.Property("Tasker") + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("WeekId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("WeekId"); + + b.ToTable("HappinessTask"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("CityAndZipCode") + .HasColumnType("text"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("GroupId") + .HasColumnType("text"); + + b.Property("InvitationText") + .HasColumnType("text"); + + b.Property("SEQ") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.ToTable("HappinessWeeks"); + }); + + modelBuilder.Entity("Church.Net.Entity.LineMessagingAccount", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ChatToken") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Seq") + .HasColumnType("integer"); + + b.Property("TotalUsage") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("LineMessagingAccounts"); + }); + + modelBuilder.Entity("Church.Net.Entity.LogInfo", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DetailMessage") + .HasColumnType("text"); + + b.Property("Level") + .HasColumnType("integer"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("Source") + .HasColumnType("text"); + + b.Property("StackTrace") + .HasColumnType("text"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.Property("TrackNo") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TrackNo")); + + b.Property("Url") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("LogInfos"); + }); + + modelBuilder.Entity("Church.Net.Entity.Messenger.LineMessageClient", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ClientId") + .HasColumnType("text"); + + b.Property("IsGroup") + .HasColumnType("boolean"); + + b.Property("IsManager") + .HasColumnType("boolean"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("LineMessageClients"); + }); + + modelBuilder.Entity("Church.Net.Entity.NewVisitor", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Address") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("ComunityAppId") + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Email") + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Gender") + .HasColumnType("integer"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Note") + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.Property("ReligionId") + .HasColumnType("integer"); + + b.Property("VisitingDate") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ReligionId"); + + b.ToTable("NewVisitors"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Image1") + .HasColumnType("text"); + + b.Property("Image2") + .HasColumnType("text"); + + b.Property("Image3") + .HasColumnType("text"); + + b.Property("Image4") + .HasColumnType("text"); + + b.Property("Image5") + .HasColumnType("text"); + + b.Property("LeaderMemberId") + .HasColumnType("text"); + + b.Property("LineAccountId") + .HasColumnType("text"); + + b.Property("LineGroupId") + .HasColumnType("text"); + + b.Property("LogoImage") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("ServiceAddressId") + .HasColumnType("text"); + + b.Property("ServiceTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("LeaderMemberId"); + + b.HasIndex("LineAccountId"); + + b.HasIndex("ServiceAddressId"); + + b.ToTable("PastoralDomains"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainAutoReplys", b => + { + b.Property("PastoralDomainCommunityAppId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("AutoReplyItemId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.HasKey("PastoralDomainCommunityAppId", "AutoReplyItemId"); + + b.HasIndex("AutoReplyItemId"); + + b.ToTable("PastoralDomainAutoReplys"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainMembers", b => + { + b.Property("PastoralDomainId") + .HasColumnType("text") + .HasColumnOrder(0); + + b.Property("FamilyMemberId") + .HasColumnType("text") + .HasColumnOrder(1); + + b.HasKey("PastoralDomainId", "FamilyMemberId"); + + b.HasIndex("FamilyMemberId"); + + b.ToTable("PastoralDomainMembers"); + }); + + modelBuilder.Entity("Church.Net.Entity.Religion", b => + { + b.Property("ReligionId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ReligionId")); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("ReligionId"); + + b.ToTable("Religions"); + }); + + modelBuilder.Entity("Church.Net.Entity.Vocabulary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DefinitionCh") + .IsRequired() + .HasColumnType("text"); + + b.Property("DefinitionEn") + .IsRequired() + .HasColumnType("text"); + + b.Property("FlashCardTimes") + .HasColumnType("integer"); + + b.Property("ImagesUrl") + .HasColumnType("text"); + + b.Property("InsertDate") + .HasColumnType("timestamp with time zone"); + + b.Property("NounPlural") + .HasColumnType("text"); + + b.Property("PartOfSpeech") + .HasColumnType("integer"); + + b.Property("PracticeApply") + .HasColumnType("boolean"); + + b.Property("PracticeDate") + .HasColumnType("timestamp with time zone"); + + b.Property("PracticeMemorized") + .HasColumnType("boolean"); + + b.Property("PracticeReview") + .HasColumnType("boolean"); + + b.Property("PracticeSelect") + .HasColumnType("boolean"); + + b.Property("PracticeSentence") + .HasColumnType("text"); + + b.Property("PracticeStage") + .HasColumnType("integer"); + + b.Property("PracticeVisualize") + .HasColumnType("boolean"); + + b.Property("VerbParticiple") + .HasColumnType("text"); + + b.Property("VerbPast") + .HasColumnType("text"); + + b.Property("Word") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Vocabulary"); + }); + + modelBuilder.Entity("Church.Net.Entity.WhoIsSpy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Answer1Chs") + .HasColumnType("text"); + + b.Property("Answer1Cht") + .HasColumnType("text"); + + b.Property("Answer1En") + .HasColumnType("text"); + + b.Property("Answer2Chs") + .HasColumnType("text"); + + b.Property("Answer2Cht") + .HasColumnType("text"); + + b.Property("Answer2En") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("WhoIsSpy"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.HasOne("Church.Net.Entity.PastoralDomain", "CellGroupInfo") + .WithMany() + .HasForeignKey("PastoralDomainId"); + + b.Navigation("CellGroupInfo"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventAttendee", b => + { + b.HasOne("Church.Net.Entity.CellGroupRoutineEvent", "CellGroupRoutineEvent") + .WithMany("Attendees") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CellGroupRoutineEvent"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventPrayer", b => + { + b.HasOne("Church.Net.Entity.CellGroupRoutineEvent", "CellGroupRoutineEvent") + .WithMany("Prayers") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CellGroupRoutineEvent"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.HasOne("Church.Net.Entity.Career", "Career") + .WithMany() + .HasForeignKey("CareerId"); + + b.Navigation("Career"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMemberOAuth", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", null) + .WithMany("OAuthInfos") + .HasForeignKey("FamilyMemberId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessBEST", b => + { + b.HasOne("Church.Net.Entity.PastoralDomain", "HappinessGroup") + .WithMany("Bests") + .HasForeignKey("GroupId"); + + b.Navigation("HappinessGroup"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessTask", b => + { + b.HasOne("Church.Net.Entity.HappinessWeek", "HappinessWeek") + .WithMany("Tasks") + .HasForeignKey("WeekId"); + + b.Navigation("HappinessWeek"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.HasOne("Church.Net.Entity.PastoralDomain", "HappinessGroup") + .WithMany("HappinessWeeks") + .HasForeignKey("GroupId"); + + b.Navigation("HappinessGroup"); + }); + + modelBuilder.Entity("Church.Net.Entity.NewVisitor", b => + { + b.HasOne("Church.Net.Entity.Religion", "Religion") + .WithMany() + .HasForeignKey("ReligionId"); + + b.Navigation("Religion"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", "Leader") + .WithMany() + .HasForeignKey("LeaderMemberId"); + + b.HasOne("Church.Net.Entity.LineMessagingAccount", "LineMessagingAccount") + .WithMany() + .HasForeignKey("LineAccountId"); + + b.HasOne("Church.Net.Entity.AddressInfo", "ServiceAddress") + .WithMany() + .HasForeignKey("ServiceAddressId"); + + b.Navigation("Leader"); + + b.Navigation("LineMessagingAccount"); + + b.Navigation("ServiceAddress"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainAutoReplys", b => + { + b.HasOne("Church.Net.Entity.AutoReplyItem", "FamilyMember") + .WithMany("AutoReplyItemRelations") + .HasForeignKey("AutoReplyItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Church.Net.Entity.PastoralDomain", "PastoralDomain") + .WithMany("AutoReplyItemRelations") + .HasForeignKey("PastoralDomainCommunityAppId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FamilyMember"); + + b.Navigation("PastoralDomain"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomainMembers", b => + { + b.HasOne("Church.Net.Entity.FamilyMember", "FamilyMember") + .WithMany("PastoralDomains") + .HasForeignKey("FamilyMemberId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Church.Net.Entity.PastoralDomain", "PastoralDomain") + .WithMany("Members") + .HasForeignKey("PastoralDomainId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FamilyMember"); + + b.Navigation("PastoralDomain"); + }); + + modelBuilder.Entity("Church.Net.Entity.AutoReplyItem", b => + { + b.Navigation("AutoReplyItemRelations"); + }); + + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.Navigation("Attendees"); + + b.Navigation("Prayers"); + }); + + modelBuilder.Entity("Church.Net.Entity.FamilyMember", b => + { + b.Navigation("OAuthInfos"); + + b.Navigation("PastoralDomains"); + }); + + modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => + { + b.Navigation("Tasks"); + }); + + modelBuilder.Entity("Church.Net.Entity.PastoralDomain", b => + { + b.Navigation("AutoReplyItemRelations"); + + b.Navigation("Bests"); + + b.Navigation("HappinessWeeks"); + + b.Navigation("Members"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Church.Net.DAL.EFCoreDBF/Migrations/20221002114621_RemoveHappinessGroup.cs b/Church.Net.DAL.EFCoreDBF/Migrations/20221002114621_RemoveHappinessGroup.cs new file mode 100644 index 0000000..4ed38a6 --- /dev/null +++ b/Church.Net.DAL.EFCoreDBF/Migrations/20221002114621_RemoveHappinessGroup.cs @@ -0,0 +1,107 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Church.Net.DAL.EFCoreDBF.Migrations +{ + public partial class RemoveHappinessGroup : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_HappinessBESTs_HappinessGroups_HappinessGroupId", + table: "HappinessBESTs"); + + migrationBuilder.DropForeignKey( + name: "FK_HappinessWeeks_HappinessGroups_HappinessGroupId", + table: "HappinessWeeks"); + + migrationBuilder.DropTable( + name: "HappinessGroups"); + + migrationBuilder.DropIndex( + name: "IX_HappinessWeeks_HappinessGroupId", + table: "HappinessWeeks"); + + migrationBuilder.DropIndex( + name: "IX_HappinessBESTs_HappinessGroupId", + table: "HappinessBESTs"); + + migrationBuilder.DropColumn( + name: "HappinessGroupId", + table: "HappinessWeeks"); + + migrationBuilder.DropColumn( + name: "HappinessGroupId", + table: "HappinessBESTs"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "HappinessGroupId", + table: "HappinessWeeks", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "HappinessGroupId", + table: "HappinessBESTs", + type: "text", + nullable: true); + + migrationBuilder.CreateTable( + name: "HappinessGroups", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + LineAccountId = table.Column(type: "text", nullable: true), + Address = table.Column(type: "text", nullable: true), + BeginTime = table.Column(type: "timestamp with time zone", nullable: false), + CityAndZipCode = table.Column(type: "text", nullable: true), + InvitationText = table.Column(type: "text", nullable: true), + LineGroupId = table.Column(type: "text", nullable: true), + Name = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_HappinessGroups", x => x.Id); + table.ForeignKey( + name: "FK_HappinessGroups_LineMessagingAccounts_LineAccountId", + column: x => x.LineAccountId, + principalTable: "LineMessagingAccounts", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_HappinessWeeks_HappinessGroupId", + table: "HappinessWeeks", + column: "HappinessGroupId"); + + migrationBuilder.CreateIndex( + name: "IX_HappinessBESTs_HappinessGroupId", + table: "HappinessBESTs", + column: "HappinessGroupId"); + + migrationBuilder.CreateIndex( + name: "IX_HappinessGroups_LineAccountId", + table: "HappinessGroups", + column: "LineAccountId"); + + migrationBuilder.AddForeignKey( + name: "FK_HappinessBESTs_HappinessGroups_HappinessGroupId", + table: "HappinessBESTs", + column: "HappinessGroupId", + principalTable: "HappinessGroups", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_HappinessWeeks_HappinessGroups_HappinessGroupId", + table: "HappinessWeeks", + column: "HappinessGroupId", + principalTable: "HappinessGroups", + principalColumn: "Id"); + } + } +} diff --git a/Church.Net.DAL.EFCoreDBF/Migrations/ChurchNetContextModelSnapshot.cs b/Church.Net.DAL.EFCoreDBF/Migrations/ChurchNetContextModelSnapshot.cs index 8f34d1a..3aa6d0d 100644 --- a/Church.Net.DAL.EFCoreDBF/Migrations/ChurchNetContextModelSnapshot.cs +++ b/Church.Net.DAL.EFCoreDBF/Migrations/ChurchNetContextModelSnapshot.cs @@ -85,11 +85,16 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations b.Property("Address") .HasColumnType("text"); + b.Property("PastoralDomainId") + .HasColumnType("text"); + b.Property("Time") .HasColumnType("timestamp with time zone"); b.HasKey("Id"); + b.HasIndex("PastoralDomainId"); + b.ToTable("CellGroupRoutineEvents"); }); @@ -248,34 +253,6 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations b.ToTable("HappinessBESTs"); }); - modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("Address") - .HasColumnType("text"); - - b.Property("BeginTime") - .HasColumnType("timestamp with time zone"); - - b.Property("CityAndZipCode") - .HasColumnType("text"); - - b.Property("CommunityAppId") - .HasColumnType("text"); - - b.Property("InvitationText") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("HappinessGroups"); - }); - modelBuilder.Entity("Church.Net.Entity.HappinessTask", b => { b.Property("Id") @@ -476,10 +453,6 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations b.Property("Id") .HasColumnType("text"); - b.Property("CommunityAppId") - .IsRequired() - .HasColumnType("text"); - b.Property("Description") .HasColumnType("text"); @@ -501,6 +474,12 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations b.Property("LeaderMemberId") .HasColumnType("text"); + b.Property("LineAccountId") + .HasColumnType("text"); + + b.Property("LineGroupId") + .HasColumnType("text"); + b.Property("LogoImage") .HasColumnType("text"); @@ -510,10 +489,18 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations b.Property("ServiceAddressId") .HasColumnType("text"); + b.Property("ServiceTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Type") + .HasColumnType("integer"); + b.HasKey("Id"); b.HasIndex("LeaderMemberId"); + b.HasIndex("LineAccountId"); + b.HasIndex("ServiceAddressId"); b.ToTable("PastoralDomains"); @@ -670,6 +657,15 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations b.ToTable("WhoIsSpy"); }); + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEvent", b => + { + b.HasOne("Church.Net.Entity.PastoralDomain", "CellGroupInfo") + .WithMany() + .HasForeignKey("PastoralDomainId"); + + b.Navigation("CellGroupInfo"); + }); + modelBuilder.Entity("Church.Net.Entity.CellGroupRoutineEventAttendee", b => { b.HasOne("Church.Net.Entity.CellGroupRoutineEvent", "CellGroupRoutineEvent") @@ -712,8 +708,8 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations modelBuilder.Entity("Church.Net.Entity.HappinessBEST", b => { - b.HasOne("Church.Net.Entity.HappinessGroup", "HappinessGroup") - .WithMany("BestList") + b.HasOne("Church.Net.Entity.PastoralDomain", "HappinessGroup") + .WithMany("Bests") .HasForeignKey("GroupId"); b.Navigation("HappinessGroup"); @@ -730,8 +726,8 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => { - b.HasOne("Church.Net.Entity.HappinessGroup", "HappinessGroup") - .WithMany("Weeks") + b.HasOne("Church.Net.Entity.PastoralDomain", "HappinessGroup") + .WithMany("HappinessWeeks") .HasForeignKey("GroupId"); b.Navigation("HappinessGroup"); @@ -752,12 +748,18 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations .WithMany() .HasForeignKey("LeaderMemberId"); + b.HasOne("Church.Net.Entity.LineMessagingAccount", "LineMessagingAccount") + .WithMany() + .HasForeignKey("LineAccountId"); + b.HasOne("Church.Net.Entity.AddressInfo", "ServiceAddress") .WithMany() .HasForeignKey("ServiceAddressId"); b.Navigation("Leader"); + b.Navigation("LineMessagingAccount"); + b.Navigation("ServiceAddress"); }); @@ -772,7 +774,6 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations b.HasOne("Church.Net.Entity.PastoralDomain", "PastoralDomain") .WithMany("AutoReplyItemRelations") .HasForeignKey("PastoralDomainCommunityAppId") - .HasPrincipalKey("CommunityAppId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -819,13 +820,6 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations b.Navigation("PastoralDomains"); }); - modelBuilder.Entity("Church.Net.Entity.HappinessGroup", b => - { - b.Navigation("BestList"); - - b.Navigation("Weeks"); - }); - modelBuilder.Entity("Church.Net.Entity.HappinessWeek", b => { b.Navigation("Tasks"); @@ -835,6 +829,10 @@ namespace Church.Net.DAL.EFCoreDBF.Migrations { b.Navigation("AutoReplyItemRelations"); + b.Navigation("Bests"); + + b.Navigation("HappinessWeeks"); + b.Navigation("Members"); }); #pragma warning restore 612, 618 diff --git a/Church.Net.Entity2/AddressInfo.cs b/Church.Net.Entity2/AddressInfo.cs index 1bcf85b..6af1eb2 100644 --- a/Church.Net.Entity2/AddressInfo.cs +++ b/Church.Net.Entity2/AddressInfo.cs @@ -1,17 +1,31 @@ -using System; +using Church.Net.Entity.Interface; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text; namespace Church.Net.Entity { - public class AddressInfo + public class AddressInfo : IEntity { + public AddressInfo() + { + Id = "new"; + } [Key] public string Id { get; set; } public string Address { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } + + public string GetCSZ() + { + string result = City; + + string sz = $"{State} {Zip}".Trim(); + + return result + (string.IsNullOrWhiteSpace(sz) ? "" : $", {sz}"); + } } } diff --git a/Church.Net.Entity2/HappinessBEST.cs b/Church.Net.Entity2/HappinessBEST.cs index b50adbd..d9fe0fa 100644 --- a/Church.Net.Entity2/HappinessBEST.cs +++ b/Church.Net.Entity2/HappinessBEST.cs @@ -14,7 +14,7 @@ namespace Church.Net.Entity [ForeignKey("HappinessGroup")] public string GroupId { get; set; } - public HappinessGroup HappinessGroup { get; set; } + public PastoralDomain HappinessGroup { get; set; } [Key] public string Id { get; set; } diff --git a/Church.Net.Entity2/HappinessGroup.cs b/Church.Net.Entity2/HappinessGroup.cs deleted file mode 100644 index 35c73e7..0000000 --- a/Church.Net.Entity2/HappinessGroup.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Church.Net.Entity.Interface; -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 Church.Net.Entity -{ - public class HappinessGroup : IEntity, IMessengerClient - { - [Required, Key] - public string Id { get; set; } - - public string Name { get; set; } - - [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy/MM/dd HH:mm}")] - public DateTime BeginTime { get; set; } - public string Address { get; set; } - public string CityAndZipCode { get; set; } - - public string InvitationText { get; set; } - - public virtual ICollection BestList { get; set; } - public virtual ICollection Weeks { get; set; } - public string CommunityAppId { get; set; } - - [ForeignKey("LineMessagingAccount")] - public string LineAccountId { get; set; } - public virtual LineMessagingAccount LineMessagingAccount { get; set; } - - } -} diff --git a/Church.Net.Entity2/HappinessWeek.cs b/Church.Net.Entity2/HappinessWeek.cs index fcb73f7..dfcd781 100644 --- a/Church.Net.Entity2/HappinessWeek.cs +++ b/Church.Net.Entity2/HappinessWeek.cs @@ -1,6 +1,7 @@ using Church.Net.Entity.Interface; using System; using System.Collections.Generic; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; @@ -14,7 +15,7 @@ namespace Church.Net.Entity [ForeignKey("HappinessGroup")] public string GroupId { get; set; } - public HappinessGroup HappinessGroup { get; set; } + public PastoralDomain HappinessGroup { get; set; } [Required, Key] public string Id { get; set; } @@ -25,17 +26,25 @@ namespace Church.Net.Entity public int SEQ { get; set; } [NotMapped] public bool UpdateRestWeekDate { get; set; } + [NotMapped] + public string Topic { get; set; } public virtual ICollection Tasks { get; set; } public string Comment { get; set; } } public enum HappinessTaskType { + [Description("帶遊戲")] IceBreak, + [Description("唱歌")] Worship, + [Description("見證")] Testimony, + [Description("信息")] Message, + [Description("準備禮物")] Gift, + [Description("準備點心")] Dessert } public class HappinessTask : IEntity diff --git a/Church.Net.Entity2/LineBotInfo.cs b/Church.Net.Entity2/LineBotInfo.cs deleted file mode 100644 index 5c5ebcf..0000000 --- a/Church.Net.Entity2/LineBotInfo.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Text; - -namespace Church.Net.Entity -{ - public class LineBotInfo - { - - public string Id { get; set; } - public string GroupId { get; set; } - } - - public class LineClient - { - [Required, Key] - public string Id { get; set; } - public string LineId { get; set; } - public bool IsGroup { get; set; } - public bool IsManager { get; set; } - public string Name { get; set; } - } -} diff --git a/Church.Net.Entity2/PastoralDomain.cs b/Church.Net.Entity2/PastoralDomain.cs index c3fea77..b78b09e 100644 --- a/Church.Net.Entity2/PastoralDomain.cs +++ b/Church.Net.Entity2/PastoralDomain.cs @@ -10,6 +10,14 @@ using System.Threading.Tasks; namespace Church.Net.Entity { + public enum DomainType + { + CellGroup, + HappinessGroup, + CellGroupCoworker, + ChurchCoworker, + Person = 99 + } public class PastoralDomain : IEntity, IMessengerClient { public PastoralDomain() @@ -31,7 +39,8 @@ namespace Church.Net.Entity public string Image4 { get; set; } public string Image5 { get; set; } - public string CommunityAppId { get; set; } + + public string LineGroupId { get; set; } [ForeignKey("LineMessagingAccount")] public string LineAccountId { get; set; } @@ -46,7 +55,10 @@ namespace Church.Net.Entity public string ServiceAddressId { get; set; } public AddressInfo ServiceAddress { get; set; } - + public DomainType Type { get; set; } + public DateTime? ServiceTime { get; set; } + public virtual ICollection Bests { get; set; } + public virtual ICollection HappinessWeeks { get; set; } [JsonIgnore] public virtual ICollection Members { get; set; } @@ -54,6 +66,6 @@ namespace Church.Net.Entity public virtual IList AutoReplyItemRelations { get; set; } [NotMapped] public virtual ICollection FamilyMembers { get; set; } - + } } diff --git a/WebAPI/Controllers/BestController.cs b/WebAPI/Controllers/BestController.cs index 49443d1..b4ee822 100644 --- a/WebAPI/Controllers/BestController.cs +++ b/WebAPI/Controllers/BestController.cs @@ -13,6 +13,7 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Processing; +using WebAPI.Logics; using WebAPI.Logics.Interface; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -24,19 +25,19 @@ namespace WebAPI.Controllers public class BestController : ApiControllerBase { private readonly ICrudLogic logic; - private readonly ICrudLogic groupLogic; private readonly ICrudLogic weekLogic; + private readonly PastoralDomainLogic cellGroupLogic; public BestController( ICrudLogic logic, - ICrudLogic groupLogic, - ICrudLogic weekLogic + ICrudLogic weekLogic, + PastoralDomainLogic cellGroupLogic ) : base(logic) { this.logic = logic; - this.groupLogic = groupLogic; this.weekLogic = weekLogic; + this.cellGroupLogic = cellGroupLogic; } // GET api//5 @@ -49,8 +50,8 @@ namespace WebAPI.Controllers { return Task.Run(() => { var best = logic.GetById(id); - best.HappinessGroup = groupLogic.GetById(best.GroupId); - best.HappinessGroup.Weeks = weekLogic.GetAll(w => w.GroupId == best.GroupId).OrderBy(w=>w.SEQ).ToList(); + best.HappinessGroup = cellGroupLogic.GetById(best.GroupId); + best.HappinessGroup.HappinessWeeks = weekLogic.GetAll(w => w.GroupId == best.GroupId).OrderBy(w=>w.SEQ).ToList(); return best; }); } @@ -91,6 +92,13 @@ namespace WebAPI.Controllers return this.NotFound(); } + + [HttpPost] + public int UpdateBestWeek(HappinessWeek week) + { + return weekLogic.CreateOrUpdate(week,out string id); + } + private Font arialFont; [NonAction] public Image Superimpose(string bestName, Image largeBmp, Image smallBmp, int? x = null, int? y = null) diff --git a/WebAPI/Controllers/CellGroupRoutineEventsController.cs b/WebAPI/Controllers/CellGroupRoutineEventsController.cs index b918739..32a90c3 100644 --- a/WebAPI/Controllers/CellGroupRoutineEventsController.cs +++ b/WebAPI/Controllers/CellGroupRoutineEventsController.cs @@ -18,12 +18,12 @@ namespace WebAPI.Controllers [ApiController] public class CellGroupRoutineEventsController : ApiControllerBase { - private readonly CellGroupLogic logic; + private readonly PastoralDomainLogic logic; private readonly ICombinedKeyCrudLogic prayerLogic; private readonly ICombinedKeyCrudLogic dinnerLogic; public CellGroupRoutineEventsController( - CellGroupLogic logic, + PastoralDomainLogic logic, ICrudLogic crudLogic, ICombinedKeyCrudLogic prayerLogic, ICombinedKeyCrudLogic dinnerLogic diff --git a/WebAPI/Controllers/HappinessGroupController.cs b/WebAPI/Controllers/HappinessGroupController.cs deleted file mode 100644 index 40ebf7a..0000000 --- a/WebAPI/Controllers/HappinessGroupController.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Church.Net.DAL.EF; -using Church.Net.Entity; -using Church.Net.Utility; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; -using WebAPI.Logics; -using WebAPI.Logics.Interface; - -namespace WebAPI.Controllers -{ - [ApiController] - [Route("[controller]/[action]")] - public class HappinessGroupController : ApiControllerBase - { - - private readonly HappinessGroupLogic logic; - - public HappinessGroupController( - ICrudLogic crudLogic, - HappinessGroupLogic logic - ):base(crudLogic) - { - this.logic = logic; - } - - [HttpGet] - public override async Task> GetAll() - { - return await Task.Run(() => { return logic.GetAllGroups(); }); - } - [HttpPost] - public virtual async Task UpdateBestWeek(HappinessWeek entity) - { - return await Task.Run(() => { - return logic.UpdateWeekInfo(entity); - }); - } - } -} diff --git a/WebAPI/Controllers/HappinessWeekTaskController.cs b/WebAPI/Controllers/HappinessWeekTaskController.cs new file mode 100644 index 0000000..acf69dd --- /dev/null +++ b/WebAPI/Controllers/HappinessWeekTaskController.cs @@ -0,0 +1,23 @@ +using Church.Net.Entity; +using Church.Net.Entity.Messenger; +using LineMessaging; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Threading.Tasks; +using WebAPI.Logics; +using WebAPI.Logics.Interface; + +namespace WebAPI.Controllers +{ + [Route("[controller]/[action]")] + [ApiController] + public class HappinessWeekTaskController : ApiControllerBase + { + public HappinessWeekTaskController(ICrudLogic logic) : base(logic) + { + } + } + + +} diff --git a/WebAPI/Controllers/LineMessageController.cs b/WebAPI/Controllers/LineMessageController.cs index eb7f014..ef32299 100644 --- a/WebAPI/Controllers/LineMessageController.cs +++ b/WebAPI/Controllers/LineMessageController.cs @@ -22,6 +22,8 @@ using System.Text; using WebAPI.Services; using Jint.Native; using WebAPI.Services.Interfaces; +using Church.Net.DAL.EFCoreDBF.Migrations; +using Church.Net.DAL.EFCoreDBF; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace WebAPI.Controllers @@ -33,15 +35,17 @@ namespace WebAPI.Controllers { private readonly LineAutoBotService lineAutoBotService; private readonly ILoggingService loggingService; - + private readonly ICrudDAL crudDAL; public LineMessageController( LineAutoBotService lineAutoBotService, - ILoggingService loggingService + ILoggingService loggingService, + ICrudDAL crudDAL ) { this.lineAutoBotService = lineAutoBotService; this.loggingService = loggingService; + this.crudDAL = crudDAL; } //private ChurchNetContext dbContext = new ChurchNetContext(); //// GET: api/ @@ -65,20 +69,21 @@ namespace WebAPI.Controllers // POST api/ [HttpPost] - //[Route("[controller]/[action]")] - //[Route("[controller]/[action]/{id?}")] - public async Task PostFromLine(string id, [FromBody] object jsonData) + public async Task PostFromLine(int seq, [FromBody] object jsonData) { //string txtPath = ServerUtils.MapPath("App_Data/LinePostRawLog.txt"); //System.IO.File.AppendAllText(txtPath, JsonConvert.SerializeObject(jsonData.ToString(), Formatting.Indented)); try { + LineMessagingAccount lineAccount = crudDAL.GetAll(l => l.Seq == seq).FirstOrDefault(); + if (lineAccount != null) + { + LineWebhookContent content = JsonConvert.DeserializeObject(jsonData.ToString()); - LineWebhookContent content = JsonConvert.DeserializeObject(jsonData.ToString()); - + await lineAutoBotService.AutoReply(lineAccount,content); + } //this.loggingService.Log("PostFromLine"); - await lineAutoBotService.AutoReply(content); } catch (Exception ex) { @@ -104,11 +109,11 @@ namespace WebAPI.Controllers } - [HttpGet] - public Task PushCommandMessage(string groupToken, string command) - { - return lineAutoBotService.PushCommandMessage(EnumHelper.GetEnumValueFromDescription(groupToken), "#" + command); - } + //[HttpGet] + //public Task PushCommandMessage(string groupToken, string command) + //{ + // return lineAutoBotService.PushCommandMessage(EnumHelper.GetEnumValueFromDescription(groupToken), "#" + command); + //} } diff --git a/WebAPI/Controllers/LineMessagingAccountController.cs b/WebAPI/Controllers/LineMessagingAccountController.cs index 7a8764a..d2cfd62 100644 --- a/WebAPI/Controllers/LineMessagingAccountController.cs +++ b/WebAPI/Controllers/LineMessagingAccountController.cs @@ -1,4 +1,5 @@ using Church.Net.Entity; +using Church.Net.Entity.Messenger; using LineMessaging; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -32,4 +33,16 @@ namespace WebAPI.Controllers } } } + + + [Route("[controller]/[action]")] + [ApiController] + public class LineClientController : ApiControllerBase + { + public LineClientController(ICrudLogic logic) : base(logic) + { + } + } + + } diff --git a/WebAPI/Controllers/PastoralDomainController.cs b/WebAPI/Controllers/PastoralDomainController.cs index f5b12a6..80fe5aa 100644 --- a/WebAPI/Controllers/PastoralDomainController.cs +++ b/WebAPI/Controllers/PastoralDomainController.cs @@ -16,7 +16,7 @@ namespace WebAPI.Controllers [ApiController] public class PastoralDomainController : ApiControllerBase { - public PastoralDomainController(ICrudLogic logic) : base(logic) + public PastoralDomainController(PastoralDomainLogic logic) : base(logic) { } diff --git a/WebAPI/Controllers/PingController.cs b/WebAPI/Controllers/PingController.cs index 50e4ec1..b39d6a0 100644 --- a/WebAPI/Controllers/PingController.cs +++ b/WebAPI/Controllers/PingController.cs @@ -16,6 +16,7 @@ using WebAPI.Logics; using WebAPI.Services; using static System.Net.Mime.MediaTypeNames; using WebAPI.Services.Interfaces; +using WebAPI.Logics.Interface; namespace WebAPI.Controllers { @@ -24,9 +25,12 @@ namespace WebAPI.Controllers public class PingController : ControllerBase { private readonly IEnumerable autoReplyCommands; + private readonly PastoralDomainLogic pastoralDomainLogic; + private readonly LineAutoBotService lineAutoBotService; public PingController(VideoDownloadLogic videoDownloadLogic, - IEnumerable autoReplyCommands) + IEnumerable autoReplyCommands + ) { VideoDownloadLogic = videoDownloadLogic; this.autoReplyCommands = autoReplyCommands; @@ -129,41 +133,6 @@ namespace WebAPI.Controllers } - [HttpGet] - public async void TestAutoReply(string command) - { - //\\ArkNAS\Church\WorshipVideo - //this.VideoDownloadLogic.Download(@"https://www.youtube.com/watch?v=K2bdSYim7uI", @"\\ArkNAS\home\Test.mp4"); - - - if (!String.IsNullOrWhiteSpace(command)) - { - string text = command; - var group = LineGroup.Chris; - - var autoReply = autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group) && ar.Commands.Contains(text)).FirstOrDefault(); - if (autoReply != null) - { - - if (autoReply.LineMessage != null) - { - ReplyLineMessage(group.EnumToDescriptionString(), autoReply.LineMessage); - } - else - { - // ReplyTextMessage(replyToken, autoReply.ReplyMessage); - } - - return; - } - - - - }; - - } - - [HttpGet] public string[] GetFiles(string path) @@ -193,14 +162,6 @@ namespace WebAPI.Controllers } - private async void ReplyLineMessage(string replyToken, IEnumerable lineMessages) - { - var test = new LineMessagingClient(); - - var replyMessage = new LinePushMessage() { To = replyToken }; - replyMessage.Messages = lineMessages; - await test.PushMessage(replyMessage); - } } } diff --git a/WebAPI/Handlers/BasicAuthorizationMiddlewareResultHandler.cs b/WebAPI/Handlers/BasicAuthorizationMiddlewareResultHandler.cs index 1c1cfd8..5cdf2a8 100644 --- a/WebAPI/Handlers/BasicAuthorizationMiddlewareResultHandler.cs +++ b/WebAPI/Handlers/BasicAuthorizationMiddlewareResultHandler.cs @@ -3,12 +3,20 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization.Policy; using Microsoft.AspNetCore.Http; + using Microsoft.Extensions.DependencyInjection; using System.Linq; using System.Threading.Tasks; + using WebAPI.Services; public class BasicAuthorizationMiddlewareResultHandler : IAuthorizationMiddlewareResultHandler { private readonly AuthorizationMiddlewareResultHandler defaultHandler = new(); + private readonly IServiceScopeFactory serviceScopeFactory; + + public BasicAuthorizationMiddlewareResultHandler(IServiceScopeFactory serviceScopeFactory) + { + this.serviceScopeFactory = serviceScopeFactory; + } public async Task HandleAsync( RequestDelegate next, @@ -33,6 +41,15 @@ return; } + //else + //{ + // using (var scope = serviceScopeFactory.CreateScope()) + // { + // var service = scope.ServiceProvider.GetService(); + // service.UserAccessToken =; + // } + + //} // Fall back to the default implementation. //await defaultHandler.HandleAsync(next, context, policy, authorizeResult); await next(context); diff --git a/WebAPI/Logics/CellGroupLogic.cs b/WebAPI/Logics/CellGroupLogic.cs deleted file mode 100644 index 4464e9e..0000000 --- a/WebAPI/Logics/CellGroupLogic.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Church.Net.DAL.EFCoreDBF; -using Church.Net.Entity; -using Church.Net.Utility; -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; -using System; -using WebAPI.Logics.Core; -using WebAPI.Logics.Interface; -using System.Linq; -using Microsoft.Extensions.DependencyInjection; - -namespace WebAPI.Logics -{ - public class CellGroupLogic - { - private readonly IServiceScopeFactory serviceScopeFactory; - private readonly ICrudDAL eventCrudDAL; - private readonly ICombinedKeyCrudDAL attendeeCrudDAL; - private readonly ICrudDAL memberCrudDAL; - - public CellGroupLogic( - IServiceScopeFactory serviceScopeFactory, - ICrudDAL eventCrudDAL, - ICombinedKeyCrudDAL attendeeCrudDAL, - ICrudDAL memberCrudDAL - ) - { - this.serviceScopeFactory = serviceScopeFactory; - this.eventCrudDAL = eventCrudDAL; - this.attendeeCrudDAL = attendeeCrudDAL; - this.memberCrudDAL = memberCrudDAL; - } - - public CellGroupRoutineEvent GetComingEvent() - { - var _event = eventCrudDAL.GetDbSet().Where(e => e.Time >= DateTime.UtcNow) - .Include(e => e.Attendees).Include(e => e.Prayers).FirstOrDefault(); - if (_event == null) - { - _event = new CellGroupRoutineEvent() - { - Id = Format.Get33BaseGuid(), - Time = DateTimeHelper.GetNextWeekday(DateTime.Today, DayOfWeek.Friday).AddHours(19).AddMinutes(30), - Address = "1881 Forest Dr., Azusa, CA 91702", - Attendees = new List() - }; - eventCrudDAL.Create(_event); - } - - return _event; - } - public CellGroupRoutineEvent GetLastEvent() - { - var _event = eventCrudDAL.GetDbSet().OrderByDescending(e=>e.Time) - .Include(e => e.Attendees).Include(e => e.Prayers).FirstOrDefault(); - return _event; - } - - public string GetMemberFirstNameById(string memberId) - { - return memberCrudDAL.GetById(memberId)?.FirstName; - } - - } -} diff --git a/WebAPI/Logics/Core/LogicBase.cs b/WebAPI/Logics/Core/LogicBase.cs index a75653a..b934590 100644 --- a/WebAPI/Logics/Core/LogicBase.cs +++ b/WebAPI/Logics/Core/LogicBase.cs @@ -30,23 +30,37 @@ namespace WebAPI.Logics.Core return this.crudDAL.CheckExist(obj); } + public virtual void BeforeCreate(T entity) + { + } public virtual int Create(T entity) { - return this.crudDAL.Create(entity); + BeforeCreate(entity); + return this.crudDAL.Create(entity) + CreateDone(entity); } public virtual Task CreateAsync(T entity) { + BeforeCreate(entity); return this.crudDAL.CreateAsync(entity); } - public void CreateDone(T entity) + public virtual int CreateDone(T entity) { + return 0; } - public int CreateOrUpdate(T entity, out string id) + public virtual int CreateOrUpdate(T entity, out string id) { - var result= this.crudDAL.CreateOrUpdate(entity); + int result = 0; + if (this.crudDAL.CheckExist(entity)) + { + result = this.Update(entity); + } + else + { + result = this.Create(entity); + } id = entity.Id; return result; } @@ -56,7 +70,7 @@ namespace WebAPI.Logics.Core // return this.crudDAL.CreateReturnId(entity); //} - public int Delete(T obj) + public virtual int Delete(T obj) { return this.crudDAL.Delete(obj); } @@ -70,7 +84,7 @@ namespace WebAPI.Logics.Core return this.crudDAL.First(filter); } - public IEnumerable GetAll(Func filter = null) + public virtual IEnumerable GetAll(Func filter = null) { return this.crudDAL.GetAll(filter); } @@ -85,18 +99,39 @@ namespace WebAPI.Logics.Core return this.crudDAL.GetById(Id); } - public int Update(T entity) + public virtual void BeforeUpdate(T entity) { - return this.crudDAL.Update(entity); } - public void UpdateDone(T entity) + public virtual int Update(T entity) { + BeforeUpdate(entity); + return this.crudDAL.Update(entity)+ UpdateDone(entity); + } + + public virtual int UpdateDone(T entity) + { + return 0; } public int UpdateRange(IEnumerable entities) { - return this.crudDAL.UpdateRange(entities); + int result = 0; + foreach (var item in entities) + { + result += Update(item); + } + return result;// this.crudDAL.UpdateRange(entities); + } + + public int CreateOrUpdateAll(IEnumerable entities) + { + int result = 0; + foreach (var item in entities) + { + result += CreateOrUpdate(item,out string id); + } + return result;// this.crudDAL.UpdateRange(entities); } } } diff --git a/WebAPI/Logics/Core/LogicService.cs b/WebAPI/Logics/Core/LogicService.cs index 232a3db..3ce523d 100644 --- a/WebAPI/Logics/Core/LogicService.cs +++ b/WebAPI/Logics/Core/LogicService.cs @@ -7,13 +7,16 @@ namespace WebAPI.Logics.Core public class LogicService { private readonly IServiceScopeFactory serviceScopeFactory; + private readonly IdentityService identityService; public LogicService( //ChurchNetContext dbContext - IServiceScopeFactory serviceScopeFactory + IServiceScopeFactory serviceScopeFactory, + IdentityService identityService ) { this.serviceScopeFactory = serviceScopeFactory; + this.identityService = identityService; //DbContext = dbContext; } @@ -22,11 +25,7 @@ namespace WebAPI.Logics.Core { get { - using (var scope = serviceScopeFactory.CreateScope()) - { - var service = scope.ServiceProvider.GetService(); - return service.UserId; - } + return identityService.UserId; } } } diff --git a/WebAPI/Logics/HappinessGroupLogic.cs b/WebAPI/Logics/HappinessGroupLogic.cs deleted file mode 100644 index 42a6c4c..0000000 --- a/WebAPI/Logics/HappinessGroupLogic.cs +++ /dev/null @@ -1,85 +0,0 @@ -using Church.Net.DAL.EFCoreDBF; -using Church.Net.Entity; -using Church.Net.Utility; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Diagnostics.Metrics; -using System.Linq; - -namespace WebAPI.Logics -{ - public class HappinessGroupLogic - { - private readonly ICrudDAL groupCrudDAL; - private readonly ICrudDAL weekCrudDAL; - string[] weekTitles = new string[] { "真幸福", "真相大白", "萬世巨星", "幸福連線", "當上帝來敲門", "十字架的勝利", "釋放與自由", "幸福的教會" }; - - public HappinessGroupLogic( - ICrudDAL groupCrudDAL, - ICrudDAL weekCrudDAL - ) - { - this.groupCrudDAL = groupCrudDAL; - this.weekCrudDAL = weekCrudDAL; - } - - public List GetAllGroups() - { - var list = groupCrudDAL.GetDbSet().Include(g => g.BestList).Include(g => g.Weeks).ToList(); - - foreach (var group in list) - { - if (group.Weeks == null || group.Weeks.Count() == 0) - { - group.Weeks = new List(); - for (int i = 1; i <= 8; i++) - { - var week = GetHappinessWeek(group, i); - group.Weeks.Add(week); - weekCrudDAL.CreateOrUpdate(week); - } - } - group.Weeks = group.Weeks.OrderBy(w => w.SEQ).ToList(); - } - - - return list; - - - } - - public int UpdateWeekInfo(HappinessWeek value) - { - if (value.UpdateRestWeekDate) - { - var list = weekCrudDAL.GetAll(week => week.SEQ >= value.SEQ && week.GroupId == value.GroupId).OrderBy(w => w.SEQ).ToList(); - var tempDate = new DateTime(value.Date.Year, value.Date.Month, value.Date.Day, value.Date.Hour, value.Date.Minute, value.Date.Second); - int count = 0; - foreach (var week in list) - { - week.Date = tempDate.AddDays(count * 7); - week.Address = value.Address; - week.CityAndZipCode = value.CityAndZipCode; - week.InvitationText = value.InvitationText; - count++; - } - return weekCrudDAL.UpdateRange(list); - } - return weekCrudDAL.CreateOrUpdate(value); - - } - - private HappinessWeek GetHappinessWeek(HappinessGroup group, int weekNo) - { - return new HappinessWeek() - { - GroupId = group.Id, - Address = group.Address, - CityAndZipCode = group.CityAndZipCode, - Date = group.BeginTime.AddDays(7 * (weekNo - 1)), - SEQ = weekNo - }; - } - } -} diff --git a/WebAPI/Logics/Interface/ICrudLogic.cs b/WebAPI/Logics/Interface/ICrudLogic.cs index bbf1e91..2fca5da 100644 --- a/WebAPI/Logics/Interface/ICrudLogic.cs +++ b/WebAPI/Logics/Interface/ICrudLogic.cs @@ -17,11 +17,11 @@ namespace WebAPI.Logics.Interface int Create(T entity); Task CreateAsync(T entity); //string CreateReturnId(T entity); - int CreateOrUpdate(T entity, out string id); + int CreateOrUpdateAll(IEnumerable entities); int Update(T entity); - void CreateDone(T entity); - void UpdateDone(T entity); + int CreateDone(T entity); + int UpdateDone(T entity); int UpdateRange(IEnumerable entities); int Delete(T obj); int Delete(Func filter = null); diff --git a/WebAPI/Logics/LineMessagingAccountLogic.cs b/WebAPI/Logics/LineMessagingAccountLogic.cs index 3e429e0..07218af 100644 --- a/WebAPI/Logics/LineMessagingAccountLogic.cs +++ b/WebAPI/Logics/LineMessagingAccountLogic.cs @@ -11,36 +11,27 @@ namespace WebAPI.Logics { public class LineMessagingAccountLogic : LogicBase, ICrudLogic { - private readonly ICrudDAL happinessGroupDAL; private readonly ICrudDAL cellGroupDAL; public LineMessagingAccountLogic( LogicService logicService, ICrudDAL crudDAL, - ICrudDAL happinessGroupDAL, ICrudDAL cellGroupDAL ) : base(logicService, crudDAL) { - this.happinessGroupDAL = happinessGroupDAL; this.cellGroupDAL = cellGroupDAL; } - public HappinessGroup GetHappinessGroup(string lineGroupId) - { - var group= happinessGroupDAL.First(c => c.CommunityAppId == lineGroupId); - GetLineMessagingAccount(group); - return group; - } public PastoralDomain GetCellGroup(string lineGroupId) { - var group = cellGroupDAL.First(c => c.CommunityAppId == lineGroupId); + var group = cellGroupDAL.First(c => c.LineGroupId == lineGroupId); GetLineMessagingAccount(group); return group; } - private void GetLineMessagingAccount(IMessengerClient messengerClient) + public void GetLineMessagingAccount(IMessengerClient messengerClient) { - if (messengerClient != null) + if (messengerClient != null && messengerClient.LineAccountId != null) { messengerClient.LineMessagingAccount = crudDAL.GetById(messengerClient.LineAccountId); } diff --git a/WebAPI/Logics/PastoralDomainLogic.cs b/WebAPI/Logics/PastoralDomainLogic.cs new file mode 100644 index 0000000..a914a4c --- /dev/null +++ b/WebAPI/Logics/PastoralDomainLogic.cs @@ -0,0 +1,240 @@ +using Church.Net.DAL.EFCoreDBF; +using Church.Net.Entity; +using Church.Net.Utility; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System; +using WebAPI.Logics.Core; +using WebAPI.Logics.Interface; +using System.Linq; +using Microsoft.Extensions.DependencyInjection; +using System.Text.RegularExpressions; + +namespace WebAPI.Logics +{ + public class PastoralDomainLogic : LogicBase, ICrudLogic + { + string[] weekTopics = new string[] { "真幸福", "真相大白", "萬世巨星", "幸福連線", "當上帝來敲門", "十字架的勝利", "釋放與自由", "幸福的教會" }; + private readonly IServiceScopeFactory serviceScopeFactory; + private readonly ICrudDAL eventCrudDAL; + private readonly ICombinedKeyCrudDAL attendeeCrudDAL; + private readonly ICrudDAL memberCrudDAL; + private readonly ICrudDAL addressCrudDAL; + private readonly ICombinedKeyCrudDAL pastoralDomainMemberDAL; + private readonly ICrudDAL weekCrudDAL; + private readonly ICrudDAL bestCrudDAL; + private readonly ICrudDAL weekTaskCrudDAL; + + public PastoralDomainLogic( + IServiceScopeFactory serviceScopeFactory, + LogicService logicService, + ICrudDAL crudDAL, + ICrudDAL eventCrudDAL, + ICombinedKeyCrudDAL attendeeCrudDAL, + ICrudDAL memberCrudDAL, + ICrudDAL addressCrudDAL, + ICombinedKeyCrudDAL pastoralDomainMemberDAL, + ICrudDAL weekCrudDAL, + ICrudDAL bestCrudDAL, + ICrudDAL weekTaskCrudDAL + ) : base(logicService, crudDAL) + { + this.serviceScopeFactory = serviceScopeFactory; + this.eventCrudDAL = eventCrudDAL; + this.attendeeCrudDAL = attendeeCrudDAL; + this.memberCrudDAL = memberCrudDAL; + this.addressCrudDAL = addressCrudDAL; + this.pastoralDomainMemberDAL = pastoralDomainMemberDAL; + this.weekCrudDAL = weekCrudDAL; + this.bestCrudDAL = bestCrudDAL; + this.weekTaskCrudDAL = weekTaskCrudDAL; + } + + + #region override + + + public override IEnumerable GetAll(Func filter = null) + { + var list = base.GetAll(filter); + foreach (var item in list) + { + if (!string.IsNullOrEmpty(item.ServiceAddressId)) + { + item.ServiceAddress = addressCrudDAL.GetById(item.ServiceAddressId); + } + else + { + item.ServiceAddress = new AddressInfo(); + } + if (item.Type == DomainType.HappinessGroup) + { + GetHappinessGroupInfo(item); + } + } + return list; + } + + public override void BeforeCreate(PastoralDomain entity) + { + addressCrudDAL.CreateOrUpdate(entity.ServiceAddress); + entity.ServiceAddressId = entity.ServiceAddress.Id; + } + public override void BeforeUpdate(PastoralDomain entity) + { + addressCrudDAL.CreateOrUpdate(entity.ServiceAddress); + entity.ServiceAddressId = entity.ServiceAddress.Id; + } + + #endregion + + + public CellGroupRoutineEvent GetComingEvent(string domainId = null) + { + if (domainId == null) + { + var cellGroup = GetCurrentUserCellGroup(); + if (cellGroup != null) + { + domainId = cellGroup.Id; + + var _event = eventCrudDAL.GetDbSet().OrderByDescending(e => e.Time) + .Include(e => e.Attendees).Include(e => e.Prayers) + .Where(e => e.PastoralDomainId == domainId).FirstOrDefault(); + return _event; + + } + + } + if (domainId != null) + { + var _event = eventCrudDAL.GetDbSet().Where(e => e.PastoralDomainId == domainId && e.Time >= DateTime.UtcNow) + .Include(e => e.Attendees).Include(e => e.Prayers).FirstOrDefault(); + if (_event == null) + { + _event = new CellGroupRoutineEvent() + { + Id = Format.Get33BaseGuid(), + Time = DateTimeHelper.GetNextWeekday(DateTime.Today, DayOfWeek.Friday).AddHours(19).AddMinutes(30), + Address = "1881 Forest Dr., Azusa, CA 91702", + Attendees = new List(), + PastoralDomainId = domainId + }; + eventCrudDAL.Create(_event); + } + + return _event; + + } + + return null; + } + public CellGroupRoutineEvent GetLastEvent(string domainId = null) + { + if (domainId == null) + { + var cellGroup = GetCurrentUserCellGroup(); + if (cellGroup != null) + { + domainId = cellGroup.Id; + + var _event = eventCrudDAL.GetDbSet().OrderByDescending(e => e.Time) + .Include(e => e.Attendees).Include(e => e.Prayers) + .Where(e => e.PastoralDomainId == domainId).FirstOrDefault(); + return _event; + + } + + } + if (domainId != null) + { + var _event = eventCrudDAL.GetDbSet().OrderByDescending(e => e.Time) + .Include(e => e.Attendees).Include(e => e.Prayers) + .Where(e => e.PastoralDomainId == domainId).FirstOrDefault(); + return _event; + + } + return null; + } + + public string GetMemberFirstNameById(string memberId) + { + return memberCrudDAL.GetById(memberId)?.FirstName; + } + + public IEnumerable GetCurrentUserPastoralDomain() + { + if (!string.IsNullOrWhiteSpace(logicService.CurrentUserId)) + { + var ids = pastoralDomainMemberDAL.GetAll(p => p.FamilyMemberId == logicService.CurrentUserId).Select(p => p.PastoralDomainId); + return crudDAL.GetAll(p => ids.Contains(p.Id)); + } + return null; + } + public PastoralDomain GetCurrentUserCellGroup() + { + if (!string.IsNullOrWhiteSpace(logicService.CurrentUserId)) + { + var ids = pastoralDomainMemberDAL.GetAll(p => p.FamilyMemberId == logicService.CurrentUserId).Select(p => p.PastoralDomainId); + return crudDAL.GetAll(p => ids.Contains(p.Id) && p.Type == DomainType.CellGroup).FirstOrDefault(); + } + return null; + } + + + public int UpdateWeekInfo(HappinessWeek value) + { + if (value.UpdateRestWeekDate) + { + var list = weekCrudDAL.GetAll(week => week.SEQ >= value.SEQ && week.GroupId == value.GroupId).OrderBy(w => w.SEQ).ToList(); + var tempDate = new DateTime(value.Date.Year, value.Date.Month, value.Date.Day, value.Date.Hour, value.Date.Minute, value.Date.Second); + int count = 0; + foreach (var week in list) + { + week.Date = tempDate.AddDays(count * 7); + week.Address = value.Address; + week.CityAndZipCode = value.CityAndZipCode; + week.InvitationText = value.InvitationText; + count++; + } + return weekCrudDAL.UpdateRange(list); + } + return weekCrudDAL.CreateOrUpdate(value); + + } + + private HappinessWeek GetHappinessWeek(PastoralDomain group, int weekNo) + { + return new HappinessWeek() + { + GroupId = group.Id, + Address = group.ServiceAddress.Address, + CityAndZipCode = group.ServiceAddress.GetCSZ(), + Date = group.ServiceTime.Value.AddDays(7 * (weekNo - 1)), + SEQ = weekNo + }; + } + public void GetHappinessGroupInfo(PastoralDomain group) + { + group.HappinessWeeks = weekCrudDAL.GetAll(w => w.GroupId == group.Id).OrderBy(w => w.SEQ).ToList(); + if (group.HappinessWeeks == null || group.HappinessWeeks.Count() == 0) + { + group.HappinessWeeks = new List(); + for (int i = 1; i <= 8; i++) + { + var week = GetHappinessWeek(group, i); + group.HappinessWeeks.Add(week); + weekCrudDAL.CreateOrUpdate(week); + } + } + + foreach (var week in group.HappinessWeeks) + { + week.Topic = weekTopics[week.SEQ - 1]; + week.Tasks = weekTaskCrudDAL.GetAll(t => t.WeekId == week.Id).ToList(); + } + + group.Bests = bestCrudDAL.GetAll(b => b.GroupId == group.Id).ToList(); + } + } +} diff --git a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupDinner.cs b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupDinner.cs index 632bf2c..a2092a7 100644 --- a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupDinner.cs +++ b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupDinner.cs @@ -15,24 +15,23 @@ namespace WebAPI.Services.AutoReplyCommands { public class ArArkCellGroupDinner : IAutoReplyCommand { - + private PastoralDomain pastoralDomain; public ArArkCellGroupDinner( - CellGroupLogic logic) + PastoralDomainLogic logic) { this.logic = logic; } private static readonly string[] COMMANDS = { "晚餐", "dinner" }; - private static readonly LineGroup[] GROUPS = { - LineGroup.Ark, - LineGroup.Chris, + private static readonly DomainType[] GROUPS = { + DomainType.CellGroup, }; - private readonly CellGroupLogic logic; + private readonly PastoralDomainLogic logic; - public string Description => "顯示方舟小組聚會晚餐"; + public string Description => "顯示小組聚會晚餐"; public IEnumerable Commands => COMMANDS; - public IEnumerable SupportGroups => GROUPS; - public IEnumerable ReplyMessage => null; + public IEnumerable SupportGroups => GROUPS; + public string ReplyTextMessage => null; public IEnumerable LineMessage { @@ -41,7 +40,7 @@ namespace WebAPI.Services.AutoReplyCommands var random = new Random(); List list = new List(); - var _event = logic.GetComingEvent(); + var _event = logic.GetComingEvent(pastoralDomain.Id); string title = "小組晚宴,吃飯皇帝大"; string imageUrl = "https://happiness.tours/assets/images/dinner.jpg"; @@ -191,5 +190,15 @@ namespace WebAPI.Services.AutoReplyCommands return list; } } + + public void Initialize(PastoralDomain pastoralDomain = null) + { + this.pastoralDomain = pastoralDomain; + } + + public bool Enabled(PastoralDomain pastoralDomain = null, string command = null) + { + return COMMANDS.Any(c=>c.IndexOf(command)==0); + } } } diff --git a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupInfo.cs b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupInfo.cs index a10bd78..469750a 100644 --- a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupInfo.cs +++ b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupInfo.cs @@ -1,4 +1,5 @@ -using LineMessaging; +using Church.Net.Entity; +using LineMessaging; using System; using System.Collections.Generic; using System.Linq; @@ -9,25 +10,31 @@ namespace WebAPI.Services.AutoReplyCommands { public class ArArkCellGroupInfo : IAutoReplyCommand { + private PastoralDomain pastoralDomain; + private static readonly string[] COMMANDS = { "小組" }; + + private static readonly DomainType[] GROUPS = { + DomainType.CellGroup, + }; - private static readonly string[] COMMANDS = { "方舟", "方舟小組", "ark" }; - private static readonly string[] MESSAGES = { + public string Description => "顯示小組聚會資訊"; + public IEnumerable Commands => COMMANDS; + public string ReplyTextMessage => "新生命靈糧堂 Arcadia 牧區 - 方舟小組\n" + "聚會時間 & 流程 周五晚上\n" + "07:30 PM ~ 08:30 PM - PotLuck 時光\n" + - "08:30 PM ~ 10:00 PM - 小組分享", - "1881 Forest Dr, Azusa, CA 91702" - }; - private static readonly LineGroup[] GROUPS = { - LineGroup.Ark, - LineGroup.ArkCowoker, - LineGroup.Chris - }; - - public string Description => "顯示方舟小組聚會資訊"; - public IEnumerable Commands => COMMANDS; - public IEnumerable ReplyMessage => MESSAGES; - public IEnumerable SupportGroups => GROUPS; + "08:30 PM ~ 10:00 PM - 小組分享\n" + + "1881 Forest Dr, Azusa, CA 91702"; + public IEnumerable SupportGroups => GROUPS; public IEnumerable LineMessage => null; + + public void Initialize(PastoralDomain pastoralDomain = null) + { + this.pastoralDomain = pastoralDomain; + } + public bool Enabled(PastoralDomain pastoralDomain = null, string command = null) + { + return COMMANDS.Any(c => c.IndexOf(command) == 0); + } } } diff --git a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupPrayer.cs b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupPrayer.cs index c2a7b05..f9730a3 100644 --- a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupPrayer.cs +++ b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupPrayer.cs @@ -1,6 +1,7 @@ using Church.Net.DAL.EF; using Church.Net.Entity; using Church.Net.Utility; +using Esprima; using LineMessaging; using Microsoft.EntityFrameworkCore; using System; @@ -15,9 +16,9 @@ namespace WebAPI.Services.AutoReplyCommands { public class ArArkCellGroupPrayer : IAutoReplyCommand { - + PastoralDomain pastoralDomain; public ArArkCellGroupPrayer( - CellGroupLogic logic + PastoralDomainLogic logic ) { this.logic = logic; @@ -67,67 +68,15 @@ namespace WebAPI.Services.AutoReplyCommands } private static readonly string[] COMMANDS = { "禱告", "代禱", "letspray", "pray" }; - private static readonly LineGroup[] GROUPS = { - LineGroup.Ark, - LineGroup.Chris, - LineGroup.ArkCowoker, + private static readonly DomainType[] GROUPS = { + DomainType.CellGroup, }; - private readonly CellGroupLogic logic; + private readonly PastoralDomainLogic logic; public string Description => "顯示代禱事項"; public IEnumerable Commands => COMMANDS; - public IEnumerable SupportGroups => GROUPS; - public IEnumerable ReplyMessage - { - get - { - - StringBuilder sb = new StringBuilder(); - StringBuilder comments = new StringBuilder(); - sb.AppendLine("方舟小組-禱告中心"); - var _event = logic.GetLastEvent(); - if (_event == null || _event.Prayers.Count == 0) - { - sb.AppendLine($"目前暫無禱告事項唷!"); - sb.AppendLine($"請使用方舟禱告系統,新增代禱項目唷!"); - sb.AppendLine("https://happiness.tours/CellGroup/prayer?openExternalBrowser=1"); - } - var random = new Random(); - int index = random.Next(bibleReferrences.Count); - var bibleSentence = bibleReferrences[index]; - - sb.AppendLine("======= 代禱事項 ======="); - foreach (var a in _event.Prayers) - { - var name = logic.GetMemberFirstNameById(a.MemberId); - - sb.AppendLine($"{name} - {string.Join(", ", a.Prayer.Split('|'))}"); - //sb.AppendLine($"{logic.GetMemberFirstNameById (a.MemberId)} - "); - //int count = 0; - //foreach (var prayer in a.Prayer.Split('|')) - //{ - // count++; - // sb.AppendLine(prayer); - - //} - if (!string.IsNullOrWhiteSpace(a.Comment)) - { - comments.AppendLine($"{name}:{a.Comment}"); - } - } - - if (comments.Length > 0) - { - sb.AppendLine("========= 備註 ========="); - sb.Append(comments.ToString()); - } - - sb.AppendLine(""); - sb.AppendLine($"請使用方舟禱告系統,新增代禱項目唷!"); - sb.AppendLine("https://happiness.tours/CellGroup/prayer?openExternalBrowser=1"); - return new string[] { sb.ToString() }; - } - } + public IEnumerable SupportGroups => GROUPS; + public string ReplyTextMessage => null; public IEnumerable LineMessage { get @@ -137,7 +86,7 @@ namespace WebAPI.Services.AutoReplyCommands var bibleSentence = bibleReferrences[index]; List list = new List(); - var _event = logic.GetLastEvent(); + var _event = logic.GetLastEvent(this.pastoralDomain.Id); string title = "禱告中心 普壘森特"; string imageUrl = "https://dailyverses.net/images/tc/cuv/matthew-21-22-3.jpg"; @@ -280,6 +229,15 @@ namespace WebAPI.Services.AutoReplyCommands } private List bibleReferrences; + + public void Initialize(PastoralDomain pastoralDomain = null) + { + this.pastoralDomain = pastoralDomain; + } + public bool Enabled(PastoralDomain pastoralDomain = null, string command = null) + { + return COMMANDS.Any(c => c.IndexOf(command) == 0); + } } diff --git a/WebAPI/Services/AutoReplyCommands/ArChurchInfo.cs b/WebAPI/Services/AutoReplyCommands/ArChurchInfo.cs index 88fe9f6..d9a1561 100644 --- a/WebAPI/Services/AutoReplyCommands/ArChurchInfo.cs +++ b/WebAPI/Services/AutoReplyCommands/ArChurchInfo.cs @@ -1,4 +1,5 @@ -using LineMessaging; +using Church.Net.Entity; +using LineMessaging; using System; using System.Collections.Generic; using System.Linq; @@ -11,21 +12,29 @@ namespace WebAPI.Services.AutoReplyCommands { private static readonly string[] COMMANDS = { "教會", "church" }; - private static readonly string[] MESSAGES = { - "新生命靈糧堂 Arcadia 牧區\n聚會時間 周日 11:00 AM - 12:30PM\n聚會後有提供精緻午餐唷!", - "1881 S 1st Ave, Arcadia, CA 91006" - }; - private static readonly LineGroup[] GROUPS = { - LineGroup.Ark, - LineGroup.ArkCowoker, - LineGroup.Chris + private static readonly string MESSAGES = + "新生命靈糧堂 Arcadia 牧區\n聚會時間 周日 11:00 AM - 12:30PM\n聚會後有提供精緻午餐唷!\n"+ + "1881 S 1st Ave, Arcadia, CA 91006"; + private static readonly DomainType[] GROUPS = { + DomainType.HappinessGroup, + DomainType.CellGroup }; public string Description => "顯示教會主日聚會資訊"; public IEnumerable Commands => COMMANDS; - public IEnumerable ReplyMessage => MESSAGES; + public string ReplyTextMessage => MESSAGES; - public IEnumerable SupportGroups => GROUPS; public IEnumerable LineMessage => null; + + IEnumerable IAutoReplyCommand.SupportGroups => GROUPS; + + public bool Enabled(PastoralDomain pastoralDomain = null, string command = null) + { + return COMMANDS.Any(c => c.IndexOf(command) == 0); + } + + public void Initialize(PastoralDomain pastoralDomain = null) + { + } } } diff --git a/WebAPI/Services/AutoReplyCommands/ArHappinessGroupTask.cs b/WebAPI/Services/AutoReplyCommands/ArHappinessGroupTask.cs new file mode 100644 index 0000000..992859b --- /dev/null +++ b/WebAPI/Services/AutoReplyCommands/ArHappinessGroupTask.cs @@ -0,0 +1,199 @@ +using Church.Net.DAL.EF; +using Church.Net.Entity; +using Church.Net.Utility; +using LineMessaging; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WebAPI.Logics; +using WebAPI.Services.Interfaces; + +namespace WebAPI.Services.AutoReplyCommands +{ + public class ArHappinessGroupTask : IAutoReplyCommand + { + private PastoralDomain pastoralDomain; + public ArHappinessGroupTask( + PastoralDomainLogic logic) + { + this.logic = logic; + } + private static readonly string[] COMMANDS = { "分工", "分工#" }; + + private static readonly DomainType[] GROUPS = { + DomainType.HappinessGroup, + }; + private readonly PastoralDomainLogic logic; + + public string Description => "顯示幸福小組分工表 #代表周數"; + public IEnumerable Commands => COMMANDS; + public IEnumerable SupportGroups => GROUPS; + public string ReplyTextMessage => null; + + public IEnumerable LineMessage + { + get + { + var random = new Random(); + + List list = new List(); + string title = $"W{weekSeq} {week.Topic} 分工表"; + string imageUrl = $"https://happiness.tours/assets/images/HappinessGroup/week0{weekSeq}.jpg"; + var flexMessage = new LineFlexMessage(); + flexMessage.AltText = title; + + #region Header + var headerContent = flexMessage.Contents.InitHeader(); + headerContent.Add( + new LineFlexText(title) + { + Size = FlexObjectSize.lg, + Weight = FlexObjectTextWeidht.Bold, + Align = "center" + }); + #endregion + #region Hero + flexMessage.Contents.InitHero() + .Add( + new LineFlexImage(imageUrl) + { + Size = FlexObjectSize.full, + AspectRatio = "1.5:1" + } + ); + #endregion + #region Body + + var bodyContent = flexMessage.Contents.InitBody(); + + TimeSpan ts = week.Date - DateTime.Now; + Console.WriteLine("No. of Minutes (Difference) = {0}", ts.TotalMinutes); + bodyContent.Add( + new LineFlexText($"再過 {ts.TotalMinutes.ToString("N0")} 分鐘,就是萬眾期待的幸福小組啦!!!") + { + Size = FlexObjectSize.md, + Weight = FlexObjectTextWeidht.Regular, + OffsetBottom = FlexObjectSize.xxl, + Wrap = true + }); + //bodyContent.Add( + // new LineFlexText($"{_event.Time.ToString("MM/dd HH:mm tt")} 準時開飯唷!!") + // { + // Size = FlexObjectSize.md, + // Weight = FlexObjectTextWeidht.Regular, + // OffsetBottom = FlexObjectSize.xl, + // Wrap = true + // }); + + bodyContent.Add( + new LineFlexText("分工明細") + { + Size = FlexObjectSize.md, + Weight = FlexObjectTextWeidht.Bold, + OffsetBottom = FlexObjectSize.md + }); + //$"目前暫無禱告事項唷, 趕快來新增代禱事項吧!!" + List comments = new List(); + + foreach (var a in week.Tasks) + { + var name = string.IsNullOrEmpty(a.Tasker)?"N/A": a.Tasker;// logic.GetMemberFirstNameById(a.MemberId); + + var baseLineBox = new LineFlexBox() + { + Layout = FlexObjectBoxLayout.Baseline, + }; + baseLineBox.Contents.Add( + new LineFlexText(a.Type.EnumToDescriptionString()) + { + Size = FlexObjectSize.sm, + Color = "#aaaaaa", + Flex = 3 + }); + baseLineBox.Contents.Add( + new LineFlexText( + $"{name}" + + ) + { + Size = FlexObjectSize.sm, + Color = "#666666", + Flex = 3, + Wrap = true + }); + baseLineBox.Contents.Add( + new LineFlexText( + $"內容:{a.Content}" + + ) + { + Size = FlexObjectSize.sm, + Color = "#666666", + Flex = 7, + Wrap = true + }); + bodyContent.Add(baseLineBox); + + } + + bodyContent.Add(new LineFlexSeparator()); + #endregion + #region Footer + //flexMessage.Contents.InitFooter() + // .Add( + // new LineFlexButton() + // { + // Action = new UriAction() + // { + // Uri = "https://happiness.tours/CellGroup/dinner?openExternalBrowser=1", + // Label = "我的菜單" + // } + // } + // ); + + #endregion + + list.Insert(0, flexMessage); + return list; + } + } + + public void Initialize(PastoralDomain pastoralDomain = null) + { + this.pastoralDomain = pastoralDomain; + } + private int weekSeq = 0; + private HappinessWeek week = null; + public bool Enabled(PastoralDomain pastoralDomain = null, string command = null) + { + + if (pastoralDomain != null && COMMANDS.Any(c => c.IndexOf(command) == 0)) + { + + this.pastoralDomain = pastoralDomain; + command = command.Replace("分工", ""); + + if (command.Length > 0) + { + weekSeq = int.Parse(command); + } + logic.GetHappinessGroupInfo(pastoralDomain); + if (weekSeq > 0) + { + week = pastoralDomain.HappinessWeeks.Where(w => w.SEQ == weekSeq).FirstOrDefault(); + } + else + { + week = pastoralDomain.HappinessWeeks.Where(w => w.Date >= DateTime.UtcNow).FirstOrDefault(); + weekSeq = week.SEQ; + } + return true; + }; + return false; + + } + } +} diff --git a/WebAPI/Services/IdentityService.cs b/WebAPI/Services/IdentityService.cs index 2ab5802..9d3d097 100644 --- a/WebAPI/Services/IdentityService.cs +++ b/WebAPI/Services/IdentityService.cs @@ -1,26 +1,44 @@ -using Church.Net.Entity; +using Church.Net.DAL.EFCoreDBF; +using Church.Net.Entity; using Church.Net.Utility; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SignalR; +using System.Collections.Generic; +using WebAPI.Logics; namespace WebAPI.Services { public class IdentityService { - public string UserAccessToken { get; set; } - public string UserId { get; set; } + private readonly IHttpContextAccessor httpContextAccessor; - public PastoralDomain CellGroup + public IdentityService( + IHttpContextAccessor httpContextAccessor + ) + { + this.httpContextAccessor = httpContextAccessor; + } + public string UserAccessToken + { + get + { + return httpContextAccessor.HttpContext.Request.Headers["accessToken"]; + } + } + private string _UserId; + + public string UserId { get { - - TokenHelper.GetUserIdFromToken - return null; } + if (string.IsNullOrWhiteSpace(_UserId)) + { + _UserId = TokenHelper.GetUserIdFromToken(UserAccessToken); + } + return _UserId; + } + set { + _UserId = value; + } } - - - - - - } } diff --git a/WebAPI/Services/Interfaces/IAutoReplyCommand.cs b/WebAPI/Services/Interfaces/IAutoReplyCommand.cs index 6f8637a..4329f9d 100644 --- a/WebAPI/Services/Interfaces/IAutoReplyCommand.cs +++ b/WebAPI/Services/Interfaces/IAutoReplyCommand.cs @@ -1,4 +1,6 @@ -using LineMessaging; +using Church.Net.Entity; +using LineMessaging; +using NuGet.Protocol.Plugins; using System; using System.Collections.Generic; using System.Linq; @@ -10,8 +12,10 @@ namespace WebAPI.Services.Interfaces { string Description { get; } IEnumerable Commands { get; } - IEnumerable ReplyMessage { get; } - IEnumerable SupportGroups { get; } + string ReplyTextMessage { get; } + IEnumerable SupportGroups { get; } IEnumerable LineMessage { get; } + bool Enabled(PastoralDomain pastoralDomain = null, string command = null); + void Initialize(PastoralDomain pastoralDomain = null); } } diff --git a/WebAPI/Services/LineAutoBotService.cs b/WebAPI/Services/LineAutoBotService.cs index b140077..6ec51d0 100644 --- a/WebAPI/Services/LineAutoBotService.cs +++ b/WebAPI/Services/LineAutoBotService.cs @@ -1,4 +1,5 @@ -using Church.Net.Entity.Messenger; +using Church.Net.Entity; +using Church.Net.Entity.Messenger; using Church.Net.Utility; using LineMessaging; using Microsoft.Extensions.Logging.Abstractions; @@ -9,6 +10,7 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using WebAPI.Logics; using WebAPI.Logics.Interface; using WebAPI.Services.Interfaces; using static System.Net.Mime.MediaTypeNames; @@ -22,6 +24,8 @@ namespace WebAPI.Services Ark = 1 << 0, [Description("Ca20e3b65aa58e676815eb13c3222591a")] ArkCowoker = 1 << 1, + PastoralDomain = 1 << 2, + HappinessGroup = 1 << 3, [Description("U97e9e579a41a5222e33bf68a3bf479a0")] Chris = ~(~0 << 20), } @@ -30,20 +34,26 @@ namespace WebAPI.Services private readonly IEnumerable autoReplyCommands; private readonly ILoggingService loggingService; private readonly ICrudLogic clientLogic; + private readonly LineMessagingAccountLogic lineMessagingAccountLogic; + private string chatToken; + + private PastoralDomain cellGroup; public LineAutoBotService( IEnumerable autoReplyCommands, ILoggingService loggingService, - ICrudLogic clientLogic + ICrudLogic clientLogic, + LineMessagingAccountLogic lineMessagingAccountLogic ) { this.autoReplyCommands = autoReplyCommands; this.loggingService = loggingService; this.clientLogic = clientLogic; + this.lineMessagingAccountLogic = lineMessagingAccountLogic; } public void SendTextMessage(string text, LineGroup target) { - var test = new LineMessagingClient(); + var test = new LineMessagingClient(this.chatToken); try { @@ -57,27 +67,27 @@ namespace WebAPI.Services } } - public async Task ReplyTextMessage(string replyToken, IEnumerable textMessages) + public async Task ReplyTextMessage(string lineId, string textMessages) { - var test = new LineMessagingClient(); + var test = new LineMessagingClient(this.chatToken); - var replyMessage = new LineReplyMessage() { ReplyToken = replyToken }; - var messages = new List(); - foreach (var message in textMessages) - { - messages.Add(new LineTextMessage() { Text = message }); - } - replyMessage.Messages = messages; + //var replyMessage = new LineReplyMessage() { ReplyToken = replyToken }; + //var messages = new List(); + //foreach (var message in textMessages) + //{ + // messages.Add(new LineTextMessage() { Text = message }); + //} + //replyMessage.Messages = messages; //test.ReplyMessage(replyMessage); try { - await test.ReplyMessage(replyMessage); + await test.PushMessage(lineId, new LineTextMessage() { Text = textMessages }); return true; } catch (Exception ex) { - this.loggingService.Error(ex, "ReplyTextMessage:75", JsonConvert.SerializeObject(replyMessage, Formatting.Indented)); + this.loggingService.Error(ex, "ReplyTextMessage:75", textMessages); if (ex.Message == "You have reached your monthly limit.") { @@ -86,11 +96,11 @@ namespace WebAPI.Services return false; } } - public async Task ReplyLineMessage(string replyToken, IEnumerable lineMessages) + public async Task ReplyLineMessage(string lineId, IEnumerable lineMessages) { - var test = new LineMessagingClient(); + var test = new LineMessagingClient(this.chatToken); - var replyMessage = new LinePushMessage() { To = replyToken }; + var replyMessage = new LinePushMessage() { To = lineId }; replyMessage.Messages = lineMessages; try @@ -112,8 +122,9 @@ namespace WebAPI.Services } - public async Task AutoReply(LineWebhookContent content) + public async Task AutoReply(LineMessagingAccount lineAccount, LineWebhookContent content) { + chatToken = lineAccount.ChatToken; loggingService.Log("AutoReply", content); try { @@ -127,7 +138,7 @@ namespace WebAPI.Services string text = e.Message.Text; string target = ""; bool isGroup = true; - var client = new LineMessagingClient(); + var client = new LineMessagingClient(this.chatToken); switch (e.Source.Type) { case WebhookRequestSourceType.User: @@ -136,58 +147,74 @@ namespace WebAPI.Services break; case WebhookRequestSourceType.Group: target = e.Source.GroupId; - + cellGroup = lineMessagingAccountLogic.GetCellGroup(target); break; case WebhookRequestSourceType.Room: - target = e.Source.RoomId; - break; default: + target = e.Source.RoomId; + return false; break; } - if (isGroup) - { - if (clientLogic.First(c => c.ClientId == e.Source.GroupId) == null) - { - clientLogic.CreateOrUpdate(new LineMessageClient() - { - ClientId = target, - Name = client.GetGroupProfile(e.Source.GroupId).Result.GroupName, - IsGroup = true - }, out string id); - } - //TODO:Get user by user id under group - } - else - { - if (clientLogic.First(c => c.ClientId == e.Source.UserId) == null) - { - clientLogic.CreateOrUpdate(new LineMessageClient() + try + { + + if (isGroup) + { + if (clientLogic.First(c => c.ClientId == e.Source.GroupId) == null) { - ClientId = target, - Name = client.GetProfile(e.Source.UserId).Result.DisplayName, - IsGroup = false - }, out string id); + clientLogic.CreateOrUpdate(new LineMessageClient() + { + ClientId = target, + Name = client.GetGroupProfile(e.Source.GroupId).Result.GroupName, + IsGroup = true + }, out string id); + } + //TODO:Get user by user id under group } + else + { + if (clientLogic.First(c => c.ClientId == e.Source.UserId) == null) + { + + clientLogic.CreateOrUpdate(new LineMessageClient() + { + ClientId = target, + Name = client.GetProfile(e.Source.UserId).Result.DisplayName, + IsGroup = false + }, out string id); + } + } + } + catch (Exception) + { + } if (!String.IsNullOrWhiteSpace(replyToken) && text.IndexOf("#") == 0) { text = text.ToLower().Substring(1); - var group = EnumHelper.GetEnumValueFromDescription(target); + LineGroup group = LineGroup.Chris; - var autoReply = autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group) && ar.Commands.Contains(text)).FirstOrDefault(); + if (cellGroup == null) + { + return false; + } + + var autoReply = autoReplyCommands.Where(ar => + ar.SupportGroups.Contains(cellGroup.Type) && + ar.Enabled(cellGroup, text) + ).FirstOrDefault(); if (autoReply != null) { - if (autoReply.LineMessage != null) { await ReplyLineMessage(target, autoReply.LineMessage); } else { - await ReplyTextMessage(replyToken, autoReply.ReplyMessage); + await ReplyTextMessage(replyToken, autoReply.ReplyTextMessage); } return true; @@ -195,13 +222,13 @@ namespace WebAPI.Services else if (text == "help" || text == "?") { StringBuilder commandText = new StringBuilder(); - commandText.AppendLine("方舟資訊部 - 指令清單"); - foreach (var ar in autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group))) + commandText.AppendLine("NLCC資訊部 - 指令清單"); + foreach (var ar in autoReplyCommands.Where(ar => ar.SupportGroups.Contains(cellGroup.Type))) { commandText.AppendLine($"{string.Join(", ", ar.Commands.Select(s => $"#{s}"))} - {ar.Description}"); } commandText.Append($"#help, #? - 顯示指令清單"); - await ReplyTextMessage(replyToken, new string[] { commandText.ToString() }); + await ReplyTextMessage(replyToken, commandText.ToString()); } @@ -210,11 +237,11 @@ namespace WebAPI.Services } - else if (e.Message.Type == MessageType.Sticker && e.Source.GroupId == LineGroup.Ark.EnumToDescriptionString() && e.Message.PackageId == "1011092" && e.Message.StickerId == "510712") - { + //else if (e.Message.Type == MessageType.Sticker && e.Source.GroupId == LineGroup.Ark.EnumToDescriptionString() && e.Message.PackageId == "1011092" && e.Message.StickerId == "510712") + //{ - await ReplyLineMessage(e.Source.GroupId, autoReplyCommands.Where(ar => ar.Commands.Contains("pray")).FirstOrDefault().LineMessage); - } + // await ReplyLineMessage(e.Source.GroupId, autoReplyCommands.Where(ar => ar.Commands.Contains("pray")).FirstOrDefault().LineMessage); + //} } } @@ -229,7 +256,7 @@ namespace WebAPI.Services } - public async Task PushCommandMessage(LineGroup group, string command) + public async Task PushCommandMessage(PastoralDomain group, string command) { try { @@ -238,32 +265,34 @@ namespace WebAPI.Services { command = command.ToLower().Substring(1); - var autoReply = autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group) && ar.Commands.Contains(command)).FirstOrDefault(); + var autoReply = autoReplyCommands.Where(ar => + ar.SupportGroups.Contains(cellGroup.Type) && + ar.Enabled(cellGroup, command)).FirstOrDefault(); if (autoReply != null) { if (autoReply.LineMessage != null) { - await ReplyLineMessage(group.EnumToDescriptionString(), autoReply.LineMessage); + await ReplyLineMessage(cellGroup.LineGroupId, autoReply.LineMessage); } else { - await ReplyTextMessage(group.EnumToDescriptionString(), autoReply.ReplyMessage); + await ReplyTextMessage(cellGroup.LineGroupId, autoReply.ReplyTextMessage); } return true; } - else if (command == "help" || command == "?") - { - StringBuilder commandText = new StringBuilder(); - commandText.AppendLine("方舟資訊部 - 指令清單"); - foreach (var ar in autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group))) - { - commandText.AppendLine($"{string.Join(", ", ar.Commands.Select(s => $"#{s}"))} - {ar.Description}"); - } - commandText.Append($"#help, #? - 顯示指令清單"); - await ReplyTextMessage(group.EnumToDescriptionString(), new string[] { commandText.ToString() }); - } + //else if (command == "help" || command == "?") + //{ + // StringBuilder commandText = new StringBuilder(); + // commandText.AppendLine("方舟資訊部 - 指令清單"); + // foreach (var ar in autoReplyCommands.Where(ar => ar.SupportGroups.Contains(group))) + // { + // commandText.AppendLine($"{string.Join(", ", ar.Commands.Select(s => $"#{s}"))} - {ar.Description}"); + // } + // commandText.Append($"#help, #? - 顯示指令清單"); + // await ReplyTextMessage(group.EnumToDescriptionString(), new string[] { commandText.ToString() }); + //} diff --git a/WebAPI/Services/ScheduledTask/MorningPrayer.cs b/WebAPI/Services/ScheduledTask/MorningPrayer.cs index 849d648..6a43d8f 100644 --- a/WebAPI/Services/ScheduledTask/MorningPrayer.cs +++ b/WebAPI/Services/ScheduledTask/MorningPrayer.cs @@ -1,6 +1,7 @@ using Church.Net.Utility; using System; using System.Threading.Tasks; +using WebAPI.Logics; using WebAPI.Services.Interfaces; namespace WebAPI.Services.ScheduledTask @@ -9,14 +10,17 @@ namespace WebAPI.Services.ScheduledTask { private readonly LineAutoBotService lineAutoBotService; private readonly ILoggingService loggingService; + private readonly PastoralDomainLogic pastoralDomainLogic; private DateTime? nextRunningTime = null; public MorningPrayer( LineAutoBotService lineAutoBotService, - ILoggingService loggingService + ILoggingService loggingService, + PastoralDomainLogic pastoralDomainLogic ) { this.lineAutoBotService = lineAutoBotService; this.loggingService = loggingService; + this.pastoralDomainLogic = pastoralDomainLogic; this.SetNextRunningTime(); } public string Description => "Sent out Ark Morning Prayer"; @@ -35,7 +39,17 @@ namespace WebAPI.Services.ScheduledTask public Task RunTask() { SetNextRunningTime(); - return lineAutoBotService.PushCommandMessage(LineGroup.Ark, "#pray"); + + return Task.Run(async () => + { + var list = pastoralDomainLogic.GetAll(p => p.Type == Church.Net.Entity.DomainType.CellGroup); + foreach (var group in list) + { + await lineAutoBotService.PushCommandMessage(group, "#pray"); + } + return true; + }); + } private void SetNextRunningTime() { diff --git a/WebAPI/Services/WorkerService.cs b/WebAPI/Services/WorkerService.cs index 0333550..2879a3c 100644 --- a/WebAPI/Services/WorkerService.cs +++ b/WebAPI/Services/WorkerService.cs @@ -7,23 +7,21 @@ using System.Collections.Generic; using System.Linq; using Church.Net.Utility; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; namespace WebAPI.Services { public class WorkerService : BackgroundService { - private IEnumerable scheduledTasks; - private ILoggingService loggingService; + private readonly IServiceProvider serviceProvider; private readonly IWebHostEnvironment env; private static bool initialized = false; public WorkerService( - IEnumerable scheduledTasks, - ILoggingService loggingService + IServiceProvider serviceProvider ) { - this.scheduledTasks = scheduledTasks; - this.loggingService = loggingService; + this.serviceProvider = serviceProvider; } private const int generalDelay = 5 * 60 * 1000; // 10 seconds @@ -48,21 +46,28 @@ namespace WebAPI.Services //} var now = DateTimeHelper.Now(); - foreach (var worker in scheduledTasks) + + using (var scope = serviceProvider.CreateScope()) { - try + var scheduledTasks = scope.ServiceProvider.GetRequiredService>(); + var loggingService = scope.ServiceProvider.GetRequiredService(); + foreach (var worker in scheduledTasks) { - if (worker.CheckTime(now)) + try { - loggingService.Log($"Running {worker.Description}"); - await worker.RunTask(); + if (worker.CheckTime(now)) + { + loggingService.Log($"Running {worker.Description}"); + await worker.RunTask(); + } + } + catch (Exception ex) + { + loggingService.Error(ex, worker.Description); } } - catch (Exception ex) - { - loggingService.Error(ex, worker.Description); - } } + return "Done"; } diff --git a/WebAPI/Startup.cs b/WebAPI/Startup.cs index 9801a21..bc93d1c 100644 --- a/WebAPI/Startup.cs +++ b/WebAPI/Startup.cs @@ -45,6 +45,7 @@ namespace WebAPI public void ConfigureServices(IServiceCollection services) { + services.AddHttpContextAccessor(); services.AddControllers().AddNewtonsoftJson(options => { @@ -63,33 +64,34 @@ namespace WebAPI services.AddSignalR(); services.AddSingleton(); - services.AddSingleton(_ => new DatabaseOptions { ConnectionString = "Host=192.168.86.131;Port=49154;Database=Church;Username=chris;Password=1124" }); + //services.AddSingleton(_ => new DatabaseOptions { ConnectionString = "Host=192.168.86.131;Port=49154;Database=Church;Username=chris;Password=1124" }); + services.AddSingleton(_ => new DatabaseOptions { ConnectionString = "Host=192.168.86.131;Port=49154;Database=ChurchSandbox;Username=chris;Password=1124" }); //services.AddSingleton(new ChurchNetContext()); services.AddDbContext(options => options.UseNpgsql( //Configuration.GetConnectionString() - "Host=192.168.86.131;Port=49154;Database=Church;Username=chris;Password=1124" + "Host=192.168.86.131;Port=49154;Database=ChurchSandbox;Username=chris;Password=1124" )); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - - services.AddSingleton(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + services.AddScoped(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(typeof(ICrudLogic<>), typeof(LogicBase<>)); - services.AddSingleton(typeof(ICrudDAL<>), typeof(CrudDALCBase<>)); - services.AddSingleton(typeof(ICombinedKeyCrudLogic<>), typeof(CombinedKeyLogicBase<>)); - services.AddSingleton(typeof(ICombinedKeyCrudDAL<>), typeof(CombinedKeyCrudDALCBase<>)); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(typeof(ICrudLogic<>), typeof(LogicBase<>)); + services.AddScoped(typeof(ICrudDAL<>), typeof(CrudDALCBase<>)); + services.AddScoped(typeof(ICombinedKeyCrudLogic<>), typeof(CombinedKeyLogicBase<>)); + services.AddScoped(typeof(ICombinedKeyCrudDAL<>), typeof(CombinedKeyCrudDALCBase<>)); + services.AddScoped(); + services.AddScoped(); services.AddScoped(); @@ -98,6 +100,11 @@ namespace WebAPI //services.AddMvc(o => o.Filters.Add(new HandleExceptionFilter(services.BuildServiceProvider().GetService()))); //services.BuildServiceProvider().GetService(); services.AddSingleton(); + + //ObjectFactory.Initialize(x => + // x.For() + // .HybridHttpOrThreadLocalScoped() + // .Use(() => new HttpContextWrapper(HttpContext.Current)); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.