Initial Commit
This commit is contained in:
19
Model/Enums.cs
Normal file
19
Model/Enums.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DebtMgr.Model
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Values that represent transaction types. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 08.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public enum TransactionType
|
||||
{
|
||||
[Description("None")]
|
||||
None,
|
||||
[Description("Deposit")]
|
||||
Deposit,
|
||||
[Description("Charge")]
|
||||
Charge
|
||||
}
|
||||
}
|
||||
82
Model/Person.cs
Normal file
82
Model/Person.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SQLite.Net.Attributes;
|
||||
using SQLiteNetExtensions.Attributes;
|
||||
|
||||
namespace DebtMgr.Model
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> A person. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 10.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public class Person
|
||||
{
|
||||
#region Id
|
||||
|
||||
[PrimaryKey]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transaction Relation
|
||||
|
||||
[OneToMany(CascadeOperations = CascadeOperation.All)]
|
||||
public List<Transaction> Transactions { get; set; } = new List<Transaction>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Total
|
||||
|
||||
/// <summary> Transaction Total </summary>
|
||||
public double Total
|
||||
{
|
||||
get
|
||||
{
|
||||
var sum = 0.0;
|
||||
|
||||
foreach (var transaction in Transactions)
|
||||
{
|
||||
if (transaction.Type == TransactionType.Charge)
|
||||
sum -= transaction.Amount;
|
||||
else if (transaction.Type == TransactionType.Deposit)
|
||||
sum += transaction.Amount;
|
||||
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region FirstName
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region LastName
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ToString()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Convert this object into a string representation. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 09.09.2017. </remarks>
|
||||
///
|
||||
/// <returns> A string that represents this object. </returns>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0} {1}", FirstName, LastName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
93
Model/Transaction.cs
Normal file
93
Model/Transaction.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using SQLite.Net.Attributes;
|
||||
using SQLiteNetExtensions.Attributes;
|
||||
|
||||
namespace DebtMgr.Model
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> A transaction. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 10.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public class Transaction
|
||||
{
|
||||
#region Id
|
||||
|
||||
[PrimaryKey]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Person Relation
|
||||
|
||||
[ForeignKey(typeof(Person))]
|
||||
public Guid PersonId { get; set; }
|
||||
|
||||
[ManyToOne]
|
||||
public Person Person { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Description
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Gets or sets the description. </summary>
|
||||
///
|
||||
/// <value> The description. </value>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public string Description { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Type
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Gets or sets the type. </summary>
|
||||
///
|
||||
/// <value> The type. </value>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public TransactionType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(StringType))
|
||||
{
|
||||
return (TransactionType)Enum.Parse(typeof(TransactionType), StringType);
|
||||
}
|
||||
return TransactionType.None;
|
||||
|
||||
}
|
||||
set { StringType = value.ToString(); }
|
||||
}
|
||||
|
||||
public string StringType;
|
||||
#endregion
|
||||
|
||||
#region Time
|
||||
|
||||
public DateTime Time { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Amount
|
||||
|
||||
public double Amount { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region SignedAmount
|
||||
|
||||
[Ignore]
|
||||
public double SignedAmount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Type == TransactionType.Charge) return Amount * -1;
|
||||
return Amount;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user