diff --git a/Database/Database-SwarmopsLog.cs b/Database/Database-SwarmopsLog.cs index 591de528..d6c0c84f 100644 --- a/Database/Database-SwarmopsLog.cs +++ b/Database/Database-SwarmopsLog.cs @@ -109,7 +109,7 @@ namespace Swarmops.Database } } - public void CreateSwarmopsLogEntryAffectedObject (int swarmopsLogEntryId, string affectedObjectType, string affectedObjectId) + public void CreateSwarmopsLogEntryAffectedObject (int swarmopsLogEntryId, string affectedObjectType, int affectedObjectId) { using (DbConnection connection = GetMySqlDbConnection()) { diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index 71f1b670..cc12dc8f 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -193,6 +193,9 @@ + + + @@ -234,6 +237,7 @@ + diff --git a/Logic/Support/LogEntries/CashAdvanceAttestedLogEntry.cs b/Logic/Support/LogEntries/CashAdvanceAttestedLogEntry.cs new file mode 100644 index 00000000..cd087670 --- /dev/null +++ b/Logic/Support/LogEntries/CashAdvanceAttestedLogEntry.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Logic.Support.LogEntries +{ + class CashAdvanceAttestedLogEntry: CashAdvanceRequestedLogEntry + { + // Identical class + + CashAdvanceAttestedLogEntry(Person attestingPerson, double amount, FinancialAccount budget, string reason) + :base (attestingPerson, amount, budget, reason) + { + + } + } +} diff --git a/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs b/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs new file mode 100644 index 00000000..f7e26385 --- /dev/null +++ b/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Logic.Support.LogEntries +{ + [Serializable] + public class CashAdvanceRequestedLogEntry: FinancialActionBase + { + public CashAdvanceRequestedLogEntry() + { + // empty ctor needed for serialize + } + + public CashAdvanceRequestedLogEntry(Person requestingPerson, double amount, FinancialAccount budget, string reason) + { + this.Amount = amount; + this.Currency = budget.Organization.Currency.Code; + this.DateTime = DateTime.UtcNow; + this.Description = reason; + this.FinancialAccountId = budget.Identity; + this.FinancialAccountName = budget.Name; // redundancy in case of future name changes + this.OwnerPersonId = budget.OwnerPersonId; + this.OwnerPersonName = budget.Owner.Name; + this.PersonId = requestingPerson.Identity; // do not save name for data retention reasons + } + } +} diff --git a/Logic/Support/LogEntries/FinancialActionBase.cs b/Logic/Support/LogEntries/FinancialActionBase.cs new file mode 100644 index 00000000..979c0ac8 --- /dev/null +++ b/Logic/Support/LogEntries/FinancialActionBase.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Swarmops.Logic.Support.Log; + +namespace Swarmops.Logic.Support.LogEntries +{ + [Serializable] + public class FinancialActionBase: LogEntryBase + { + public FinancialActionBase() + { + // necessary for serialization + } + + public int FinancialAccountId { get; set; } + public string FinancialAccountName { get; set; } + public int PersonId { get; set; } + public double Amount { get; set; } + public string Currency { get; set; } + public string Description { get; set; } + public int OwnerPersonId { get; set; } + public string OwnerPersonName { get; set; } + public DateTime DateTime { get; set; } + } +} diff --git a/Logic/Support/SwarmopsLog.cs b/Logic/Support/SwarmopsLog.cs index 511e7adc..fe1fbbe9 100644 --- a/Logic/Support/SwarmopsLog.cs +++ b/Logic/Support/SwarmopsLog.cs @@ -2,10 +2,26 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Swarmops.Database; +using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Support { - class SwarmopsLog + public class SwarmopsLog { + public static SwarmopsLogEntry CreateEntry (Person person, IXmlPayload logEntry) + { + string logEntryClass = logEntry.GetType().ToString(); + + if (logEntryClass.StartsWith("Swarmops.Logic.Support.Logentries.")) + { + logEntryClass = logEntryClass.Substring("Swarmops.Logic.Support.Logentries.".Length); + } + + int logEntryId = SwarmDb.GetDatabaseForWriting().CreateSwarmopsLogEntry( + person != null ? person.Identity : 0, logEntryClass, logEntry.ToXml()); + + return SwarmopsLogEntry.FromIdentityAggressive(logEntryId); + } } } diff --git a/Logic/Support/SwarmopsLogEntry.cs b/Logic/Support/SwarmopsLogEntry.cs new file mode 100644 index 00000000..4232104b --- /dev/null +++ b/Logic/Support/SwarmopsLogEntry.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Swarmops.Basic.Interfaces; +using Swarmops.Basic.Types; +using Swarmops.Database; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Logic.Support +{ + public class SwarmopsLogEntry: BasicSwarmopsLogEntry + { + private SwarmopsLogEntry (BasicSwarmopsLogEntry basic): + base (basic) + { + // private ctor + } + + public static SwarmopsLogEntry FromBasic (BasicSwarmopsLogEntry basic) + { + return new SwarmopsLogEntry(basic); + } + + public static SwarmopsLogEntry FromIdentity (int swarmopsLogEntryId) + { + return FromBasic(SwarmDb.GetDatabaseForReading().GetSwarmopsLogEntry(swarmopsLogEntryId)); + } + + public static SwarmopsLogEntry FromIdentityAggressive (int swarmopsLogEntryId) + { + return FromBasic(SwarmDb.GetDatabaseForWriting().GetSwarmopsLogEntry(swarmopsLogEntryId)); // Writing intentional + } + + public static SwarmopsLogEntry Create (Person person, IXmlPayload logEntry) + { + return SwarmopsLog.CreateEntry(person, logEntry); + } + + public void CreateAffectedObject (IHasIdentity affectedObject) + { + string className = affectedObject.GetType().ToString(); + int dotIndex = className.LastIndexOf('.'); + + className = className.Substring(dotIndex); // assumes there's always at least one dot in a class name + + + SwarmDb.GetDatabaseForWriting().CreateSwarmopsLogEntryAffectedObject(this.Identity, className, affectedObject.Identity); + } + } +}