This commit is contained in:
2018-09-05 22:02:23 +00:00
parent e0e5dd1942
commit cd52c3e83f
7 changed files with 46 additions and 14 deletions

View File

@@ -345,13 +345,7 @@ namespace AyaNova.Api.Controllers
else 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 //return success and link
//NOTE: this is a USER object so we don't want to return some key fields for security reasons //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 //which is why the object is "cleaned" before return

View File

@@ -9,6 +9,7 @@ using AyaNova.Models;
namespace AyaNova.Biz namespace AyaNova.Biz
{ {
//Prime the database with initial, minimum required data to boot and do things (manager account, locales)
public static class PrimeData public static class PrimeData
{ {
// private readonly AyContext ct; // private readonly AyContext ct;
@@ -21,7 +22,7 @@ namespace AyaNova.Biz
// } // }
/// <summary> /// <summary>
/// Prime the database /// Prime the database with manager account
/// </summary> /// </summary>
public static void PrimeManagerAccount(AyContext ct) public static void PrimeManagerAccount(AyContext ct)
{ {
@@ -39,6 +40,9 @@ namespace AyaNova.Biz
u.UserType=UserType.Administrator; u.UserType=UserType.Administrator;
ct.User.Add(u); ct.User.Add(u);
ct.SaveChanges(); ct.SaveChanges();
UserOptions UO=new UserOptions(1,1);
ct.UserOptions.Add(UO);
ct.SaveChanges();
} }

View File

@@ -48,11 +48,24 @@ namespace AyaNova.Biz
//do stuff with User //do stuff with User
User outObj = inObj; User outObj = inObj;
outObj.OwnerId = userId; 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) //SearchHelper(break down text fields, save to db)
//TagHelper(collection of tags??) //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; return outObj;
} }
@@ -235,6 +248,9 @@ namespace AyaNova.Biz
{ {
//TAGS //TAGS
TagMapBiz.DeleteAllForObject(new AyaTypeId(AyaType.User, dbObj.Id), ct); 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); var mapItem = new ImportAyaNova7MapItem(V7Id, AyaType.User, o.Id);
importMap.Add(mapItem); importMap.Add(mapItem);
} }
#endregion #endregion
} }

View File

@@ -10,6 +10,7 @@ namespace AyaNova.Models
{ {
public virtual DbSet<Event> Event { get; set; } public virtual DbSet<Event> Event { get; set; }
public virtual DbSet<User> User { get; set; } public virtual DbSet<User> User { 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; }
@@ -30,6 +31,7 @@ namespace AyaNova.Models
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
//AUTOMATICALLY MATCH NAMES
//https://andrewlock.net/customising-asp-net-core-identity-ef-core-naming-conventions-for-postgresql/ //https://andrewlock.net/customising-asp-net-core-identity-ef-core-naming-conventions-for-postgresql/
foreach (var entity in modelBuilder.Model.GetEntityTypes()) foreach (var entity in modelBuilder.Model.GetEntityTypes())
{ {

View File

@@ -11,11 +11,23 @@ namespace AyaNova.Models
public uint ConcurrencyToken { get; set; } public uint ConcurrencyToken { get; set; }
[Required] [Required]
public long OwnerId { get; set; } public long OwnerId { get; set; }
[Required]
public long UserId { get; set; }
//------------- //-------------
public string EmailAddress { 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 v7 export record sample

View File

@@ -22,8 +22,8 @@ namespace AyaNova.Util
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!! //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
private const int DESIRED_SCHEMA_LEVEL = 9; private const int DESIRED_SCHEMA_LEVEL = 9;
internal const long EXPECTED_COLUMN_COUNT = 77; internal const long EXPECTED_COLUMN_COUNT = 83;
internal const long EXPECTED_INDEX_COUNT = 15; internal const long EXPECTED_INDEX_COUNT = 16;
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!! //!!!!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)"); "dlkey text, dlkeyexpire timestamp, usertype integer not null, employeenumber varchar(255), notes text, clientid bigint, headofficeid bigint, subvendorid bigint)");
//Add user options table //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 //Prime the db with the default MANAGER account
@@ -176,7 +177,7 @@ 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, ownerid bigint not null, name varchar(255) not null, " + 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); setSchemaLevel(++currentSchema);
} }

View File

@@ -272,6 +272,8 @@ namespace AyaNova.Util
foreach (long l in ItemsAdded) foreach (long l in ItemsAdded)
{ {
EventLogProcessor.AddEntry(new Event(1, l, AyaType.User, AyaEvent.Created), ct); 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 //Now save the Event Log entries