This commit is contained in:
2020-01-16 23:40:36 +00:00
parent d3cb9bea90
commit 54f90be425
4 changed files with 29 additions and 10 deletions

View File

@@ -15,7 +15,7 @@ namespace AyaNova.Models
public virtual DbSet<UserOptions> UserOptions { get; set; } public virtual DbSet<UserOptions> UserOptions { get; set; }
public virtual DbSet<License> License { get; set; } public virtual DbSet<License> License { get; set; }
public virtual DbSet<Widget> Widget { get; set; } public virtual DbSet<Widget> Widget { get; set; }
public virtual DbSet<FileAttachment> FileAttachment { get; set; } public virtual DbSet<FileAttachment> FileAttachment { get; set; }
public virtual DbSet<OpsJob> OpsJob { get; set; } public virtual DbSet<OpsJob> OpsJob { get; set; }
public virtual DbSet<OpsJobLog> OpsJobLog { get; set; } public virtual DbSet<OpsJobLog> OpsJobLog { get; set; }
public virtual DbSet<Locale> Locale { get; set; } public virtual DbSet<Locale> Locale { get; set; }
@@ -40,7 +40,7 @@ namespace AyaNova.Models
{ {
// Replace table names // Replace table names
//entity.Relational().TableName = "a" + entity.Relational().TableName.ToLowerInvariant(); //entity.Relational().TableName = "a" + entity.Relational().TableName.ToLowerInvariant();
entity.SetTableName( "a" + entity.GetTableName().ToLowerInvariant()); entity.SetTableName("a" + entity.GetTableName().ToLowerInvariant());
// Replace column names // Replace column names
foreach (var property in entity.GetProperties()) foreach (var property in entity.GetProperties())
@@ -53,7 +53,7 @@ namespace AyaNova.Models
property.SetColumnType("xid"); property.SetColumnType("xid");
// property.Relational().ColumnName = "xmin"; // property.Relational().ColumnName = "xmin";
// property.Relational().ColumnType = "xid"; // property.Relational().ColumnType = "xid";
property.ValueGenerated = ValueGenerated.OnAddOrUpdate; property.ValueGenerated = ValueGenerated.OnAddOrUpdate;
property.IsConcurrencyToken = true; property.IsConcurrencyToken = true;
} }
else else
@@ -63,13 +63,13 @@ namespace AyaNova.Models
foreach (var key in entity.GetKeys()) foreach (var key in entity.GetKeys())
{ {
key.SetName(key.GetName().ToLowerInvariant()); 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()) foreach (var key in entity.GetForeignKeys())
{ {
//key.Relational().Name = key.Relational().Name.ToLowerInvariant(); //key.Relational().Name = key.Relational().Name.ToLowerInvariant();
key.SetConstraintName(key.GetConstraintName().ToLowerInvariant()); key.SetConstraintName(key.GetConstraintName().ToLowerInvariant());
} }
@@ -95,6 +95,15 @@ namespace AyaNova.Models
.HasForeignKey<UserOptions>(b => b.UserId) .HasForeignKey<UserOptions>(b => b.UserId)
.OnDelete(DeleteBehavior.Cascade);//Hopefully will delete the useroptions with the user? .OnDelete(DeleteBehavior.Cascade);//Hopefully will delete the useroptions with the user?
//User->Widget this might be wrong
modelBuilder.Entity<User>()
.HasOne(p => p.Widget)
.WithOne(i => i.User)
.HasForeignKey<Widget>(b => b.UserId)
.OnDelete(DeleteBehavior.NoAction);
//----------- //-----------
} }

View File

@@ -10,7 +10,7 @@ namespace AyaNova.Models
{ {
public long Id { get; set; } public long Id { get; set; }
public uint ConcurrencyToken { get; set; } public uint ConcurrencyToken { get; set; }
[Required] [Required]
public bool Active { get; set; } public bool Active { get; set; }
[Required, MaxLength(255)] [Required, MaxLength(255)]
@@ -44,6 +44,9 @@ namespace AyaNova.Models
[JsonIgnore]//hide from being returned (as null anyway) with User object in routes [JsonIgnore]//hide from being returned (as null anyway) with User object in routes
public UserOptions UserOptions { get; set; } 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() public User()
{ {
Tags = new List<string>(); Tags = new List<string>();

View File

@@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using AyaNova.Biz; using AyaNova.Biz;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace AyaNova.Models namespace AyaNova.Models
{ {
@@ -14,7 +14,7 @@ namespace AyaNova.Models
public long Id { get; set; } public long Id { get; set; }
public uint ConcurrencyToken { get; set; } public uint ConcurrencyToken { get; set; }
[Required] [Required]
public string Name { get; set; } public string Name { get; set; }
public uint Serial { get; set; } public uint Serial { get; set; }
public decimal? DollarAmount { get; set; } public decimal? DollarAmount { get; set; }
@@ -26,10 +26,16 @@ namespace AyaNova.Models
public int? Count { get; set; } public int? Count { get; set; }
public string CustomFields { get; set; } public string CustomFields { get; set; }
public List<string> Tags { get; set; } public List<string> 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() public Widget()
{ {
Tags = new List<string>(); Tags = new List<string>();
} }
} }

View File

@@ -209,7 +209,8 @@ namespace AyaNova.Util
//Add widget table //Add widget table
//id, text, longtext, boolean, currency, //id, text, longtext, boolean, currency,
exec("CREATE TABLE awidget (id BIGSERIAL PRIMARY KEY, name varchar(255) not null, serial bigint not null," + 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 //TEST TEST TEST ONLY FOR DEVELOPMENT TESTING TO ENSURE UNIQUENESS
//exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);"); //exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);");