From 0a3c9274294493610037033cc0e51bc1ec2df84b Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 5 Sep 2018 23:05:43 +0000 Subject: [PATCH] --- server/AyaNova/biz/PrimeData.cs | 5 ++--- server/AyaNova/biz/UserBiz.cs | 6 ++++-- server/AyaNova/models/AyContext.cs | 9 ++++----- server/AyaNova/models/User.cs | 11 ++++++++--- server/AyaNova/models/UserOptions.cs | 20 +++++++++++++------- server/AyaNova/util/Seeder.cs | 10 ++++++---- 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/server/AyaNova/biz/PrimeData.cs b/server/AyaNova/biz/PrimeData.cs index 09ff2a74..1fe6cf95 100644 --- a/server/AyaNova/biz/PrimeData.cs +++ b/server/AyaNova/biz/PrimeData.cs @@ -38,11 +38,10 @@ namespace AyaNova.Biz u.OwnerId = 1; u.LocaleId=ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;//Ensure primeLocales is called first u.UserType=UserType.Administrator; + u.UserOptions=new UserOptions(1); 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 d73e6569..3bed56eb 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -48,6 +48,8 @@ namespace AyaNova.Biz //do stuff with User User outObj = inObj; outObj.OwnerId = userId; + outObj.UserOptions = new UserOptions(userId); + await ct.User.AddAsync(outObj); //save to get Id await ct.SaveChangesAsync(); @@ -60,8 +62,8 @@ namespace AyaNova.Biz //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); + // UserOptions options = new UserOptions(outObj.Id, userId); + // ct.UserOptions.Add(options); //Save the final changes await ct.SaveChangesAsync(); diff --git a/server/AyaNova/models/AyContext.cs b/server/AyaNova/models/AyContext.cs index 16852b76..297c2612 100644 --- a/server/AyaNova/models/AyContext.cs +++ b/server/AyaNova/models/AyContext.cs @@ -52,7 +52,6 @@ namespace AyaNova.Models } else property.Relational().ColumnName = property.Name.ToLowerInvariant(); - } foreach (var key in entity.GetKeys()) @@ -69,21 +68,21 @@ namespace AyaNova.Models { index.Relational().Name = index.Relational().Name.ToLowerInvariant(); } - - } //Indexes must be specified through fluent api unfortunately modelBuilder.Entity().HasIndex(p => p.StoredFileName); - //Relationships modelBuilder.Entity() .HasMany(c => c.LocaleItems) .WithOne(e => e.Locale) .IsRequired();//default delete behaviour is cascade when set to isrequired - + modelBuilder.Entity() + .HasOne(p => p.UserOptions) + .WithOne(i => i.User) + .HasForeignKey(b => b.UserId); //----------- diff --git a/server/AyaNova/models/User.cs b/server/AyaNova/models/User.cs index 65e3430c..cb5c1edf 100644 --- a/server/AyaNova/models/User.cs +++ b/server/AyaNova/models/User.cs @@ -18,10 +18,10 @@ namespace AyaNova.Models [Required] public string Login { get; set; } [Required] - public string Password { get; set; } + public string Password { get; set; } public string Salt { get; set; } [Required] - public AuthorizationRoles Roles { get; set; } + public AuthorizationRoles Roles { get; set; } [Required] public long LocaleId { get; set; } public string DlKey { get; set; } @@ -31,11 +31,16 @@ namespace AyaNova.Models public UserType UserType { get; set; } [MaxLength(255)] public string EmployeeNumber { get; set; } - public string Notes { get; set; } + public string Notes { get; set; } public long? ClientId { get; set; } public long? HeadOfficeId { get; set; } public long? SubVendorId { get; set; } + + //relations + //https://docs.microsoft.com/en-us/ef/core/modeling/relationships#other-relationship-patterns + public UserOptions UserOptions { get; set; } + } } /* diff --git a/server/AyaNova/models/UserOptions.cs b/server/AyaNova/models/UserOptions.cs index f5612ed2..7c5342a2 100644 --- a/server/AyaNova/models/UserOptions.cs +++ b/server/AyaNova/models/UserOptions.cs @@ -11,19 +11,25 @@ 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 int UiColor { get; set; } - public UserOptions(long userId, long ownerId) + //relations + //https://docs.microsoft.com/en-us/ef/core/modeling/relationships#other-relationship-patterns + public User User { get; set; } + [Required] + public long UserId { get; set; }//will be auto-set by EF due to relationship defined + + + public UserOptions(long ownerId) { - UserId=userId; - TimeZoneOffset=0; - UiColor=0; - OwnerId=ownerId; + + TimeZoneOffset = 0; + UiColor = 0; + OwnerId = ownerId; } } diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index d8ba0ded..6f44b3f1 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -199,7 +199,7 @@ namespace AyaNova.Util //PRIVACY TEST USER - this is used for a test to see if user info leaks into the logs GenSeedUser(1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, "TEST_PRIVACY_USER_ACCOUNT", "TEST_PRIVACY_USER_ACCOUNT"); - //TEST NOT ACTIVE - this is used for a test to see if inactive user can login + //TEST NOT ACTIVE - this is used for a test to see if inactive user can login GenSeedUser(1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, false, "TEST_INACTIVE", "TEST_INACTIVE"); } @@ -254,6 +254,10 @@ namespace AyaNova.Util u.UserType = userType; //TODO: After have USER and HEADOFFICE and VENDOR, if usertype is subcontractor or client or headoffice it needs to set a corresponding user's parent org record id to go with it + //Children and relations + u.UserOptions = new UserOptions(1); + u.UserOptions.EmailAddress = p.Email.Replace("gmail.com","helloayanova.com").Replace("hotmail.com","helloayanova.com").Replace("yahoo.com","helloayanova.com"); + ct.User.Add(u); } //save to get id values @@ -271,9 +275,7 @@ namespace AyaNova.Util //Now we have all the id's can actually add them to the context 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); + EventLogProcessor.AddEntry(new Event(1, l, AyaType.User, AyaEvent.Created), ct); } //Now save the Event Log entries