From 54f90be4250ffd7d28ac02567d143bde26af253f Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 16 Jan 2020 23:40:36 +0000 Subject: [PATCH] --- server/AyaNova/models/AyContext.cs | 19 ++++++++++++++----- server/AyaNova/models/User.cs | 5 ++++- server/AyaNova/models/Widget.cs | 12 +++++++++--- server/AyaNova/util/AySchema.cs | 3 ++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/server/AyaNova/models/AyContext.cs b/server/AyaNova/models/AyContext.cs index 3a9532bc..51f6fa77 100644 --- a/server/AyaNova/models/AyContext.cs +++ b/server/AyaNova/models/AyContext.cs @@ -15,7 +15,7 @@ namespace AyaNova.Models public virtual DbSet UserOptions { get; set; } public virtual DbSet License { get; set; } public virtual DbSet Widget { get; set; } - public virtual DbSet FileAttachment { get; set; } + public virtual DbSet FileAttachment { get; set; } public virtual DbSet OpsJob { get; set; } public virtual DbSet OpsJobLog { get; set; } public virtual DbSet Locale { get; set; } @@ -40,7 +40,7 @@ namespace AyaNova.Models { // Replace table names //entity.Relational().TableName = "a" + entity.Relational().TableName.ToLowerInvariant(); - entity.SetTableName( "a" + entity.GetTableName().ToLowerInvariant()); + entity.SetTableName("a" + entity.GetTableName().ToLowerInvariant()); // Replace column names foreach (var property in entity.GetProperties()) @@ -53,7 +53,7 @@ namespace AyaNova.Models property.SetColumnType("xid"); // property.Relational().ColumnName = "xmin"; // property.Relational().ColumnType = "xid"; - property.ValueGenerated = ValueGenerated.OnAddOrUpdate; + property.ValueGenerated = ValueGenerated.OnAddOrUpdate; property.IsConcurrencyToken = true; } else @@ -63,13 +63,13 @@ namespace AyaNova.Models foreach (var key in entity.GetKeys()) { key.SetName(key.GetName().ToLowerInvariant()); - // key.Relational().Name = key.Relational().Name.ToLowerInvariant(); + // key.Relational().Name = key.Relational().Name.ToLowerInvariant(); } foreach (var key in entity.GetForeignKeys()) { //key.Relational().Name = key.Relational().Name.ToLowerInvariant(); - + key.SetConstraintName(key.GetConstraintName().ToLowerInvariant()); } @@ -95,6 +95,15 @@ namespace AyaNova.Models .HasForeignKey(b => b.UserId) .OnDelete(DeleteBehavior.Cascade);//Hopefully will delete the useroptions with the user? + //User->Widget this might be wrong + modelBuilder.Entity() + .HasOne(p => p.Widget) + .WithOne(i => i.User) + .HasForeignKey(b => b.UserId) + .OnDelete(DeleteBehavior.NoAction); + + + //----------- } diff --git a/server/AyaNova/models/User.cs b/server/AyaNova/models/User.cs index 98a39386..4ccccbc9 100644 --- a/server/AyaNova/models/User.cs +++ b/server/AyaNova/models/User.cs @@ -10,7 +10,7 @@ namespace AyaNova.Models { public long Id { get; set; } public uint ConcurrencyToken { get; set; } - + [Required] public bool Active { get; set; } [Required, MaxLength(255)] @@ -44,6 +44,9 @@ namespace AyaNova.Models [JsonIgnore]//hide from being returned (as null anyway) with User object in routes public UserOptions UserOptions { get; set; } + [JsonIgnore]//hide from being returned (as null anyway) with User object in routes + public Widget Widget { get; set; } + public User() { Tags = new List(); diff --git a/server/AyaNova/models/Widget.cs b/server/AyaNova/models/Widget.cs index db4d95e4..e0c6b0b9 100644 --- a/server/AyaNova/models/Widget.cs +++ b/server/AyaNova/models/Widget.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using AyaNova.Biz; - using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; namespace AyaNova.Models { @@ -14,7 +14,7 @@ namespace AyaNova.Models public long Id { get; set; } public uint ConcurrencyToken { get; set; } - [Required] + [Required] public string Name { get; set; } public uint Serial { get; set; } public decimal? DollarAmount { get; set; } @@ -26,10 +26,16 @@ namespace AyaNova.Models public int? Count { get; set; } public string CustomFields { get; set; } public List Tags { get; set; } + //relations + //https://docs.microsoft.com/en-us/ef/core/modeling/relationships#other-relationship-patterns + [JsonIgnore]//hide from being returned (as null anyway) with User object in routes + public User User { get; set; } + [Required] + public long UserId { get; set; } public Widget() { - Tags = new List(); + Tags = new List(); } } diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 59c34ade..08998b73 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -209,7 +209,8 @@ namespace AyaNova.Util //Add widget table //id, text, longtext, boolean, currency, exec("CREATE TABLE awidget (id BIGSERIAL PRIMARY KEY, name varchar(255) not null, serial bigint not null," + - "startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4, count integer, notes text, customfields text, tags varchar(255) ARRAY)"); + "startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4, count integer,"+ + "notes text, userid bigint, customfields text, tags varchar(255) ARRAY)"); //TEST TEST TEST ONLY FOR DEVELOPMENT TESTING TO ENSURE UNIQUENESS //exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);");