From e2e9a050e1881c60e053abe3efd0b1481fd07263 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Wed, 7 Mar 2018 11:04:18 +0100 Subject: [PATCH] Database 0071: Applicants --- Basic/Basic.csproj | 1 + Basic/Types/Swarm/BasicApplicant.cs | 25 +++++++++ Database/Configuration.cs | 2 +- Database/Schemata/revisions.txt | 3 +- Database/Schemata/upgrade-0071.sql | 86 +++++++++++++++++++++++++++++ Site/Pages/v5/Public/Signup.aspx.cs | 24 ++++++-- 6 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 Basic/Types/Swarm/BasicApplicant.cs create mode 100644 Database/Schemata/upgrade-0071.sql diff --git a/Basic/Basic.csproj b/Basic/Basic.csproj index ed6fa013..16f0fe44 100644 --- a/Basic/Basic.csproj +++ b/Basic/Basic.csproj @@ -64,6 +64,7 @@ + diff --git a/Basic/Types/Swarm/BasicApplicant.cs b/Basic/Types/Swarm/BasicApplicant.cs new file mode 100644 index 00000000..8044d9c3 --- /dev/null +++ b/Basic/Types/Swarm/BasicApplicant.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Swarmops.Common.Interfaces; + +namespace Swarmops.Basic.Types.Swarm +{ + public class BasicApplicant: IHasIdentity + { + + + + public int ApplicantId { get; private set; } + public int PersonId { get; private set; } + public int OrganizationId { get; private set; } + public DateTime CreatedDateTime { get; private set; } + public int Score1 { get; protected set; } + public int Score2 { get; protected set; } + public int Score3 { get; protected set; } + + public int Identity { get { return ApplicantId; } } + } +} diff --git a/Database/Configuration.cs b/Database/Configuration.cs index ec1694fd..cff59112 100644 --- a/Database/Configuration.cs +++ b/Database/Configuration.cs @@ -12,7 +12,7 @@ namespace Swarmops.Database /// /// This is the IN-CODE revision of the database. The version we expect to be running against. /// - public static int DbVersionExpected => 70; + public static int DbVersionExpected => 71; // This class is in horrible need of serious refactoring. For its simplicity in task, it's a horrible bowl of spaghetti. diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt index de46c168..e1240feb 100644 --- a/Database/Schemata/revisions.txt +++ b/Database/Schemata/revisions.txt @@ -67,4 +67,5 @@ 0067 - Bugfix for 0066 [RF] 0068 - Added SetSalaryOpen [RF] 0069 - Added table, procs for ExpenseClaimGroups [RF] -0070 - Added first Applications tables, procs [RF] \ No newline at end of file +0070 - Added first Applications tables, procs [RF] +0071 - Renamed Application to Applicant, to avoid a marsh and misery of name collisions [RF] \ No newline at end of file diff --git a/Database/Schemata/upgrade-0071.sql b/Database/Schemata/upgrade-0071.sql new file mode 100644 index 00000000..f35b0d87 --- /dev/null +++ b/Database/Schemata/upgrade-0071.sql @@ -0,0 +1,86 @@ +DROP TABLE `Applications` + +# + +CREATE TABLE `Applicants` ( + `ApplicantId` INT NOT NULL AUTO_INCREMENT, + `PersonId` INT NOT NULL, + `OrganizationId` INT NOT NULL, + `CreatedDateTime` DATETIME NOT NULL, + `GrantedDateTime` DATETIME NOT NULL DEFAULT '1800-01-01', + `GrantedByPersonId` INT NOT NULL DEFAULT 0, + `Open` TINYINT NOT NULL DEFAULT 1, + `Score1` BIGINT NOT NULL DEFAULT 0, + `Score2` BIGINT NOT NULL DEFAULT 0, + `Score3` BIGINT NOT NULL DEFAULT 0, + PRIMARY KEY (`ApplicantId`), + INDEX `Ix_Person` (`PersonId` ASC), + INDEX `Ix_Organization` (`OrganizationId` ASC), + INDEX `Ix_Scores` (`Score1` ASC, `Score2` ASC, `Score3` ASC), + INDEX `Ix_Open` (`Open` ASC), + INDEX `Ix_Created` (`CreatedDateTime` ASC)) + + +# + + +DROP PROCEDURE IF EXISTS `CreateApplication` + + +# + + +DROP PROCEDURE IF EXISTS `UpdateApplicationScore` + + +# + + + +DROP PROCEDURE IF EXISTS `CreateApplicant` + + +# + + +DROP PROCEDURE IF EXISTS `UpdateApplicantScore` + + +# + + + +CREATE PROCEDURE `CreateApplicant`( + IN personId INT, + IN organizationId INT, + IN dateTimeNow DATETIME +) +BEGIN + + INSERT INTO Applicants (PersonId, OrganizationId, CreatedDateTime) + VALUES (personId, organizationId, dateTimeNow); + + SELECT LAST_INSERT_ID() AS Identity; + +END + + +# + + +CREATE PROCEDURE `UpdateApplicantScore`( + IN applicantId INT, + IN deltaScore1 BIGINT, + IN deltaScore2 BIGINT, + IN deltaScore3 BIGINT +) + +BEGIN + + UPDATE Applicants + SET Applicants.Score1 = Applicants.Score1 + deltaScore1, + Applicants.Score2 = Applicants.Score2 + deltaScore2, + Applicants.Score3 = Applicants.Score3 + deltaScore3 + WHERE Applicants.ApplicantId = applicantId; + +END diff --git a/Site/Pages/v5/Public/Signup.aspx.cs b/Site/Pages/v5/Public/Signup.aspx.cs index c834efb9..0e39adbd 100644 --- a/Site/Pages/v5/Public/Signup.aspx.cs +++ b/Site/Pages/v5/Public/Signup.aspx.cs @@ -281,20 +281,32 @@ namespace Swarmops.Frontend.Pages.Public Person newPerson = Person.Create (name, mail, password, phone, street1 + "\n" + street2.Trim(), postalCode, city, countryCode, parsedDateOfBirth, gender); - Participation participation = newPerson.AddParticipation (organization, DateTime.UtcNow.AddYears (1)); // TODO: set duration from organization settings of Participantship + + + if (organization.Parameters.ParticipationEntry == "ApplicationApproval") + { + Applicant Applicant = + SwarmopsLog.CreateEntry(newPerson, new ApplicantAddedLogEntry(, newPerson))) + } + else + { + // "Application" or null, default + + Participation participation = newPerson.AddParticipation(organization, DateTime.UtcNow.AddYears(1)); // TODO: set duration from organization settings of Participantship + SwarmopsLog.CreateEntry(newPerson, new PersonAddedLogEntry(participation, newPerson)); + OutboundComm.CreateParticipantNotification(newPerson, newPerson, organization, + NotificationResource.Participant_Signup); + + } + // TODO: CREATE APPLICATION INSTEAD DEPENDING ON POLICY // TODO: SEND NOTIFICATIONS - // Log the signup - - SwarmopsLog.CreateEntry (newPerson, new PersonAddedLogEntry (participation, newPerson)); // Create notification - OutboundComm.CreateParticipantNotification (newPerson, newPerson, organization, - NotificationResource.Participant_Signup); // Add the bells and whistles