aboutsummaryrefslogtreecommitdiffstats
path: root/src/server/Models/Database/Transaction.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2020-08-01 20:14:34 +0200
committerivarlovlie <git@ivarlovlie.no>2020-08-01 20:14:34 +0200
commita800b3b9f18ae3e8ab030c30c5d7b6504f2a5ebb (patch)
tree68ffcdb7a2b42418ff1c4818d0b2cd5af41d5fa2 /src/server/Models/Database/Transaction.cs
downloaddough-a800b3b9f18ae3e8ab030c30c5d7b6504f2a5ebb.tar.xz
dough-a800b3b9f18ae3e8ab030c30c5d7b6504f2a5ebb.zip
Initial commit
Diffstat (limited to 'src/server/Models/Database/Transaction.cs')
-rw-r--r--src/server/Models/Database/Transaction.cs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/server/Models/Database/Transaction.cs b/src/server/Models/Database/Transaction.cs
new file mode 100644
index 0000000..a81626b
--- /dev/null
+++ b/src/server/Models/Database/Transaction.cs
@@ -0,0 +1,43 @@
+using System;
+using Dough.Models.Exceptions;
+
+namespace Dough.Models.Database
+{
+ public class Transaction : BaseModel
+ {
+ public string Tags { get; set; }
+ public string Note { get; set; }
+ public DateTime Date { get; set; }
+ public double Amount { get; set; }
+ public Guid PayeeId { get; set; }
+ public Guid CategoryId { get; set; }
+
+ public void Validate()
+ {
+ if (PayeeId == default)
+ {
+ var validationException = new ModelValidationException("PayeeId is invalid");
+ validationException.ErrorResult.Title = "Mottaker er ugyldig";
+ throw validationException;
+ }
+
+ if (CategoryId == default)
+ {
+ var validationException = new ModelValidationException("CategoryId is invalid");
+ validationException.ErrorResult.Title = "Kategori er ugyldig";
+ throw validationException;
+ }
+ }
+
+ public void Update(Transaction data)
+ {
+ Amount = data.Amount;
+ Date = data.Date;
+ Note = data.Note;
+ Tags = data.Tags;
+ CategoryId = data.CategoryId;
+ PayeeId = data.PayeeId;
+ base.Update(data);
+ }
+ }
+}