diff --git a/Core/.vs/Core/v15/.suo b/Core/.vs/Core/v15/.suo index b48de948e6804f2ff1c2cc99e1cf0459b781b02e..d2cce2fd66ff4751856be6503a8cc1071266f307 100644 Binary files a/Core/.vs/Core/v15/.suo and b/Core/.vs/Core/v15/.suo differ diff --git a/Core/.vs/Core/v15/Server/sqlite3/storage.ide b/Core/.vs/Core/v15/Server/sqlite3/storage.ide index 8323fdc2121ee1bc2ee66d20e3c489661c3782c7..ff95c145ac249a2f013545ff9cb05d83cccc7857 100644 Binary files a/Core/.vs/Core/v15/Server/sqlite3/storage.ide and b/Core/.vs/Core/v15/Server/sqlite3/storage.ide differ diff --git a/Core/.vs/Core/v15/Server/sqlite3/storage.ide-shm b/Core/.vs/Core/v15/Server/sqlite3/storage.ide-shm index d629686cfc2eac9729edae61e2aa1fc14673db39..8b15c6bede17d8947b06e3384bc29a4a8e0a3bed 100644 Binary files a/Core/.vs/Core/v15/Server/sqlite3/storage.ide-shm and b/Core/.vs/Core/v15/Server/sqlite3/storage.ide-shm differ diff --git a/Core/.vs/Core/v15/Server/sqlite3/storage.ide-wal b/Core/.vs/Core/v15/Server/sqlite3/storage.ide-wal index 1a3e89b4fd574ed0f5f8498d465f8febd1faeda7..e6a5b8ca7916993b1379c27803e76ee2d1b79e10 100644 Binary files a/Core/.vs/Core/v15/Server/sqlite3/storage.ide-wal and b/Core/.vs/Core/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Core/Core/Data/DbInitializer.cs b/Core/Core/Data/DbInitializer.cs index 9d56b8779b4b38a6fd06859aa1890c089d7e63fe..24030bc76b671e73c3c9080777be8e05b50db5d9 100644 --- a/Core/Core/Data/DbInitializer.cs +++ b/Core/Core/Data/DbInitializer.cs @@ -20,7 +20,7 @@ namespace Core.Data logger.Fatal(ex, "Could not read/write Database: " + ex.Message); throw; } - + // zjisti jestli už existujà nějaké záznamy if (model.Expenses.Any()) diff --git a/Core/Core/Data/Model.cs b/Core/Core/Data/Model.cs index 96e62e4fd554ee84c3192197ce2bed22ee8e4730..4891cc2ad681896150c8eeb422b6944a026cfe7a 100644 --- a/Core/Core/Data/Model.cs +++ b/Core/Core/Data/Model.cs @@ -1,4 +1,5 @@ using Core.Models; +using Core.Models.Codebooks; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -9,15 +10,48 @@ namespace Core.Data { public class Model : DbContext { - public Model(DbContextOptions<Model> options): base(options) + public Model(DbContextOptions<Model> options) : base(options) { } public DbSet<Expense> Expenses { get; set; } + //Basic tables + public DbSet<Account> Accounts { get; set; } + public DbSet<ConstantSymbol> ConstantSymbols { get; set; } + public DbSet<Person> People { get; set; } + public DbSet<Transaction> Transactions { get; set; } + + //Codebooks definying type of constant smybol + public DbSet<AccountType> AccountTypes { get; set; } + public DbSet<Kind> Kinds { get; set; } + public DbSet<LastNumber> LastNumber { get; set; } + public DbSet<MinistryPredefined> MinistryPredefined { get; set; } + public DbSet<ReservedSymbol> ReservedSymbol { get; set; } + public DbSet<ForeignPayment> ForeignPayment { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Expense>().ToTable("Expense"); + modelBuilder.Entity<Account>().ToTable("Account"); + modelBuilder.Entity<ConstantSymbol>().ToTable("ConstantSymbol"); + modelBuilder.Entity<Person>().ToTable("Person"); + //modelBuilder.Entity<Transaction>().ToTable("Transaction"); + modelBuilder.Entity<Transaction>() + .HasOne(t => t.RecipientAccount) + .WithMany(a => a.RecipientTransactions); + modelBuilder.Entity<Transaction>() + .HasOne(t => t.SenderAccount) + .WithMany(a => a.SenderTransactions); + + modelBuilder.Entity<AccountType>().ToTable("AccountType"); + modelBuilder.Entity<Kind>().ToTable("Kind"); + modelBuilder.Entity<LastNumber>().ToTable("LastNumber"); + modelBuilder.Entity<MinistryPredefined>().ToTable("MinistryPredefined"); + modelBuilder.Entity<ReservedSymbol>().ToTable("ReservedSymbol"); + modelBuilder.Entity<ForeignPayment>().ToTable("ForeignPayment"); + base.OnModelCreating(modelBuilder); } } diff --git a/Core/Core/Models/Account.cs b/Core/Core/Models/Account.cs new file mode 100644 index 0000000000000000000000000000000000000000..cc3ec07670a83895aa5ea5beb23cf1651eda4f42 --- /dev/null +++ b/Core/Core/Models/Account.cs @@ -0,0 +1,32 @@ +using Core.Models.Codebooks; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; + +namespace Core.Models +{ + public class Account + { + public long ID { get; set; } + + public int BankCode { get; set; } + public string AccountName { get; set; } + public decimal Ballance { get; set; } + + //N:1 Type (SÚ, KK, DK) + [ForeignKey("AccountType")] + public long AccountTypeID { get; set; } + //N:1 Person (Owner) + [ForeignKey("Owner")] + public long OwnerID { get; set; } + + public AccountType AccountType { get; set; } + public Person Owner {get; set;} + public ICollection<Transaction> SenderTransactions { get; set; } + public ICollection<Transaction> RecipientTransactions { get; set; } + + //1:N Transaction + } +} diff --git a/Core/Core/Models/Codebooks/AccountType.cs b/Core/Core/Models/Codebooks/AccountType.cs new file mode 100644 index 0000000000000000000000000000000000000000..27998b404e39303edb68db3903c8edd40b347a36 --- /dev/null +++ b/Core/Core/Models/Codebooks/AccountType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Core.Models.Codebooks +{ + public class AccountType + { + public long ID { get; set; } + + public string Shortname { get; set; } + public string Fullname { get; set; } + + public ICollection<Account> Accounts { get; set; } + } +} diff --git a/Core/Core/Models/Codebooks/ConstantSymbolVariation.cs b/Core/Core/Models/Codebooks/ConstantSymbolVariation.cs new file mode 100644 index 0000000000000000000000000000000000000000..fbb9558bca99f7408ccebc9a452180df10408d8a --- /dev/null +++ b/Core/Core/Models/Codebooks/ConstantSymbolVariation.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Core.Models.Codebooks +{ + public abstract class AbstractConstantSymbolVariation + { + public long ID { get; set; } + + public int Code { get; set; } + public string Value { get; set; } + + public ICollection<ConstantSymbol> ConstantSymbols { get; set; } + } + + //references for 1:N relationships + public class Kind : AbstractConstantSymbolVariation { } + public class LastNumber : AbstractConstantSymbolVariation { } + public class MinistryPredefined : AbstractConstantSymbolVariation { } + public class ReservedSymbol : AbstractConstantSymbolVariation { } + public class ForeignPayment : AbstractConstantSymbolVariation { } +} diff --git a/Core/Core/Models/ConstantSymbol.cs b/Core/Core/Models/ConstantSymbol.cs new file mode 100644 index 0000000000000000000000000000000000000000..769298312f4df6e6f6cee692117e373fce66e9c4 --- /dev/null +++ b/Core/Core/Models/ConstantSymbol.cs @@ -0,0 +1,66 @@ +using Core.Models.Codebooks; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; + +namespace Core.Models +{ + public class ConstantSymbol + { + public long ID { get; set; } + + public decimal ProvidedID { get; set; } + public bool Valid { get; set; } + public bool? DomesticPayment { get; set; } + + [ForeignKey("Kind")] + public long KindID { get; set; } + [ForeignKey("LastNumber")] + public long LastNumberID { get; set; } + [ForeignKey("MinistryPredefined")] + public long MinistryPredefinedID { get; set; } + [ForeignKey("ReservedSymbol")] + public long ReservedSymbolID { get; set; } + [ForeignKey("ForeignPayment")] + public long ForeignPaymentID { get; set; } + + public Kind Kind { get; set; } + public LastNumber LastNumber { get; set; } + public MinistryPredefined MinistryPredefined { get; set; } + public ReservedSymbol ReservedSymbol { get; set; } + public ForeignPayment ForeignPayment { get; set; } + + private void DomesticInitialization() + { + + } + + private void ForeignInitialization() + { + + } + + /*public ConstantSymbol(decimal providedID, bool domesticPayment) + { + ProvidedID = providedID; + DomesticPayment = domesticPayment; + + // https://cs.wikipedia.org/wiki/Konstantn%C3%AD_symbol_(pen%C4%9B%C5%BEn%C3%AD_p%C5%99evod) + + //neobsahuje právě čtyři cifry + if (providedID > 9999 || providedID < 1000) + { + Valid = false; + return; + } + + if (domesticPayment) DomesticInitialization(); + else ForeignInitialization(); + }*/ + + + + } +} diff --git a/Core/Core/Models/Expense.cs b/Core/Core/Models/Expense.cs index 7ee60f4bbd0e646bb74af438fafec4a3247cda1f..33a924ab5f2d5895345e0fcde09a6a08a8c1d206 100644 --- a/Core/Core/Models/Expense.cs +++ b/Core/Core/Models/Expense.cs @@ -9,7 +9,7 @@ namespace Core.Models public class Expense { //[DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int ID { get; set; } + public long ID { get; set; } public string Description { get; set; } public int Amount { get; set; } public DateTime Date { get; set; } diff --git a/Core/Core/Models/Person.cs b/Core/Core/Models/Person.cs new file mode 100644 index 0000000000000000000000000000000000000000..69863345d15df2a8a5815a1eb61fd49c6b14912f --- /dev/null +++ b/Core/Core/Models/Person.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Core.Models +{ + public class Person + { + public long ID { get; set; } + + public string Degree { get; set; } + public string Certification { get; set; } + + public string FirstName { get; set; } + public string MiddleName { get; set; } + public string LastName { get; set; } + + public bool? Sex { get; set; } + + //1:N Accounts + ICollection<Account> Accounts { get; set; } + + #region getters + public string GetFullName() + { + string fullName = string.Empty; + + if (!string.IsNullOrEmpty(Degree)) fullName += Degree; + if (!string.IsNullOrEmpty(FirstName)) fullName += ' ' + FirstName; + if (!string.IsNullOrEmpty(MiddleName)) fullName += ' ' + MiddleName; + if (!string.IsNullOrEmpty(LastName)) fullName += ' ' + LastName; + if (!string.IsNullOrEmpty(Certification)) Certification += ' ' + Certification; + + return fullName.Trim(); + } + #endregion + } +} diff --git a/Core/Core/Models/Transaction.cs b/Core/Core/Models/Transaction.cs new file mode 100644 index 0000000000000000000000000000000000000000..95870950db791fc430af449e810df5f6628e4617 --- /dev/null +++ b/Core/Core/Models/Transaction.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; + +namespace Core.Models +{ + public class Transaction + { + public long ID { get; set; } + public string ProvidedID { get; set; } + + public DateTime Date { get; set; } + // TODO: Currency normalization? + public decimal Amount { get; set; } + public decimal BalanceSender { get; set; } + + public string Note { get; set; } + public long VariableSymbol { get; set; } //DateofBirth/RČ/RČ bez id + public long SpecificSymbol { get; set; } + + [ForeignKey("ConstantSymbol")] + public long ConstantSymbolID { get; set; } + [ForeignKey("SenderAccount")] + public long SenderAccountID { get; set; } + [ForeignKey("RecipientAccount")] + public long RecipientAccountID { get; set; } + + public ConstantSymbol ConstantSymbol {get; set;} + public Account SenderAccount { get; set; } + public Account RecipientAccount { get; set; } + + // posssible Currency 1:N + + } +} diff --git a/Core/Core/Program.cs b/Core/Core/Program.cs index c6602d6ea5cdf8a2998ab4f503b03fc6ac0759fd..fe2076cf069a9a1fabf90d64a4a5071ac09465b5 100644 --- a/Core/Core/Program.cs +++ b/Core/Core/Program.cs @@ -37,7 +37,7 @@ namespace Core } } - host.Run(); + //host.Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>