diff --git a/server/AyaNova/Controllers/UserController.cs b/server/AyaNova/Controllers/UserController.cs index e84104a7..0bed7680 100644 --- a/server/AyaNova/Controllers/UserController.cs +++ b/server/AyaNova/Controllers/UserController.cs @@ -345,13 +345,7 @@ namespace AyaNova.Api.Controllers else { - //save to get Id - await ct.SaveChangesAsync(); - - //Log now that we have the Id - EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.User, AyaEvent.Created), ct); - await ct.SaveChangesAsync(); - + //return success and link //NOTE: this is a USER object so we don't want to return some key fields for security reasons //which is why the object is "cleaned" before return diff --git a/server/AyaNova/biz/PrimeData.cs b/server/AyaNova/biz/PrimeData.cs index d2e8d17b..09ff2a74 100644 --- a/server/AyaNova/biz/PrimeData.cs +++ b/server/AyaNova/biz/PrimeData.cs @@ -9,6 +9,7 @@ using AyaNova.Models; namespace AyaNova.Biz { +//Prime the database with initial, minimum required data to boot and do things (manager account, locales) public static class PrimeData { // private readonly AyContext ct; @@ -21,7 +22,7 @@ namespace AyaNova.Biz // } /// - /// Prime the database + /// Prime the database with manager account /// public static void PrimeManagerAccount(AyContext ct) { @@ -39,6 +40,9 @@ namespace AyaNova.Biz u.UserType=UserType.Administrator; ct.User.Add(u); ct.SaveChanges(); + UserOptions UO=new UserOptions(1,1); + ct.UserOptions.Add(UO); + ct.SaveChanges(); } diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 41aa432b..d73e6569 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -48,11 +48,24 @@ namespace AyaNova.Biz //do stuff with User User outObj = inObj; outObj.OwnerId = userId; + await ct.User.AddAsync(outObj); + //save to get Id + await ct.SaveChangesAsync(); + //Handle child and associated items //SearchHelper(break down text fields, save to db) //TagHelper(collection of tags??) - await ct.User.AddAsync(outObj); + + //Log event + EventLogProcessor.AddEntry(new Event(userId, outObj.Id, AyaType.User, AyaEvent.Created), ct); + + UserOptions options = new UserOptions(outObj.Id, userId); + ct.UserOptions.Add(options); + + //Save the final changes + await ct.SaveChangesAsync(); + return outObj; } @@ -235,6 +248,9 @@ namespace AyaNova.Biz { //TAGS TagMapBiz.DeleteAllForObject(new AyaTypeId(AyaType.User, dbObj.Id), ct); + + //USEROPTIONS + ct.Database.ExecuteSqlCommand($"delete from auseroptions where userid={dbObj.Id}"); } //////////////////////////////////////////////////////////////////////////////////////////////// @@ -664,6 +680,7 @@ namespace AyaNova.Biz var mapItem = new ImportAyaNova7MapItem(V7Id, AyaType.User, o.Id); importMap.Add(mapItem); + } #endregion } diff --git a/server/AyaNova/models/AyContext.cs b/server/AyaNova/models/AyContext.cs index 6cd5daa5..16852b76 100644 --- a/server/AyaNova/models/AyContext.cs +++ b/server/AyaNova/models/AyContext.cs @@ -10,6 +10,7 @@ namespace AyaNova.Models { public virtual DbSet Event { get; set; } public virtual DbSet User { get; set; } + public virtual DbSet UserOptions { get; set; } public virtual DbSet License { get; set; } public virtual DbSet Widget { get; set; } public virtual DbSet FileAttachment { get; set; } @@ -30,6 +31,7 @@ namespace AyaNova.Models protected override void OnModelCreating(ModelBuilder modelBuilder) { + //AUTOMATICALLY MATCH NAMES //https://andrewlock.net/customising-asp-net-core-identity-ef-core-naming-conventions-for-postgresql/ foreach (var entity in modelBuilder.Model.GetEntityTypes()) { diff --git a/server/AyaNova/models/UserOptions.cs b/server/AyaNova/models/UserOptions.cs index 8f388ab2..f5612ed2 100644 --- a/server/AyaNova/models/UserOptions.cs +++ b/server/AyaNova/models/UserOptions.cs @@ -11,11 +11,23 @@ namespace AyaNova.Models public uint ConcurrencyToken { get; set; } [Required] public long OwnerId { get; set; } + [Required] + public long UserId { get; set; } //------------- public string EmailAddress { get; set; } - public decimal? TimeZoneOffset { get; set; } + public decimal TimeZoneOffset { get; set; } + public int UiColor { get; set; } + public UserOptions(long userId, long ownerId) + { + UserId=userId; + TimeZoneOffset=0; + UiColor=0; + OwnerId=ownerId; + } } + + } /* v7 export record sample diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 40f3bf7a..2f39e70b 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -22,8 +22,8 @@ namespace AyaNova.Util //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!! private const int DESIRED_SCHEMA_LEVEL = 9; - internal const long EXPECTED_COLUMN_COUNT = 77; - internal const long EXPECTED_INDEX_COUNT = 15; + internal const long EXPECTED_COLUMN_COUNT = 83; + internal const long EXPECTED_INDEX_COUNT = 16; //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!! ///////////////////////////////////////////////////////////////// @@ -144,7 +144,8 @@ namespace AyaNova.Util "dlkey text, dlkeyexpire timestamp, usertype integer not null, employeenumber varchar(255), notes text, clientid bigint, headofficeid bigint, subvendorid bigint)"); //Add user options table - exec("CREATE TABLE auseroptions (id BIGSERIAL PRIMARY KEY, ownerid bigint not null)"); + exec("CREATE TABLE auseroptions (id BIGSERIAL PRIMARY KEY, ownerid bigint not null, "+ + "userid bigint not null, timezoneoffset decimal(19,5) not null default 0, emailaddress text, uicolor int not null default 0)"); //Prime the db with the default MANAGER account @@ -176,7 +177,7 @@ namespace AyaNova.Util //Add widget table //id, text, longtext, boolean, currency, exec("CREATE TABLE awidget (id BIGSERIAL PRIMARY KEY, ownerid bigint not null, name varchar(255) not null, " + - "startdate timestamp, enddate timestamp, dollaramount money, active bool, roles int4)"); + "startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4)"); setSchemaLevel(++currentSchema); } diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index cc020447..d8ba0ded 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -272,6 +272,8 @@ namespace AyaNova.Util foreach (long l in ItemsAdded) { EventLogProcessor.AddEntry(new Event(1, l, AyaType.User, AyaEvent.Created), ct); + UserOptions UO=new UserOptions(l,1); + ct.UserOptions.Add(UO); } //Now save the Event Log entries