This commit is contained in:
2018-09-05 23:05:43 +00:00
parent cd52c3e83f
commit 0a3c927429
6 changed files with 37 additions and 24 deletions

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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<FileAttachment>().HasIndex(p => p.StoredFileName);
//Relationships
modelBuilder.Entity<Locale>()
.HasMany(c => c.LocaleItems)
.WithOne(e => e.Locale)
.IsRequired();//default delete behaviour is cascade when set to isrequired
modelBuilder.Entity<User>()
.HasOne(p => p.UserOptions)
.WithOne(i => i.User)
.HasForeignKey<UserOptions>(b => b.UserId);
//-----------

View File

@@ -36,6 +36,11 @@ namespace AyaNova.Models
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; }
}
}
/*

View File

@@ -11,16 +11,22 @@ 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;

View File

@@ -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
@@ -272,8 +276,6 @@ 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