This commit is contained in:
2018-09-26 19:07:08 +00:00
parent 1f6695079f
commit 942b7b7b82
2 changed files with 84 additions and 80 deletions

View File

@@ -34,9 +34,6 @@ namespace AyaNova.Biz
}
//todo:
//then move all indexing and eventlog and associated record handling into here so that routes can just call into it simply and it handles all
//here at the biz level
//Then after that go into seeder and re-org to use the biz object to create the users (it will be slower but WTF other way is this going to work properly to generate data??)
//then after that go into widget and anywhere else that there is this associated type code being called for event and search and implement everywhere,
@@ -47,6 +44,12 @@ namespace AyaNova.Biz
return new UserBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
}
//Version for internal use
internal static UserBiz GetBizInternal(AyContext ct)
{
return new UserBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
}
////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE
internal async Task<User> CreateAsync(User inObj)

View File

@@ -223,12 +223,70 @@ namespace AyaNova.Util
GenSeedUser(count, roles, userType, true, login, password);
}
//////////////////////////////////////////////////////
//Seed user - default login / pw is first name
//
// //////////////////////////////////////////////////////
// //Seed user - default login / pw is first name
// //
// public static void GenSeedUser(int count, AuthorizationRoles roles, UserType userType, bool active = true, string login = null, string password = null)
// {
// AyContext ct = ServiceProviderProvider.DBContext;
// for (int x = 0; x < count; x++)
// {
// User u = new User();
// u.Active = active;
// u.OwnerId = 1;
// var p = new Bogus.Person();
// u.Name = p.FullName;
// u.Salt = Hasher.GenerateSalt();
// if (login != null)
// {
// u.Login = login;
// u.Name += " - " + login;
// }
// else
// u.Login = p.FirstName;
// if (password != null)
// u.Password = Hasher.hash(u.Salt, password);
// else
// u.Password = Hasher.hash(u.Salt, u.Login);
// u.Roles = roles;
// u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
// 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
// ct.SaveChanges();
// //Now that we have the ID values bulk add the event log entries
// //To save a db call iterate the local collection in the context, but...
// //can't modify the context in the foreach, even if it's another collection entirely, so need to save the id's in a temporary list
// List<long> ItemsAdded = new List<long>();
// foreach (User o in ct.User.Local)
// {
// ItemsAdded.Add(o.Id);
// }
// //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);
// }
// //Now save the Event Log entries
// ct.SaveChanges();
// }
public static void GenSeedUser(int count, AuthorizationRoles roles, UserType userType, bool active = true, string login = null, string password = null)
{
AyContext ct = ServiceProviderProvider.DBContext;
UserBiz Biz = UserBiz.GetBizInternal(ServiceProviderProvider.DBContext);
// Biz.CreateAsync()
for (int x = 0; x < count; x++)
{
@@ -256,87 +314,30 @@ namespace AyaNova.Util
//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);
u.UserOptions.EmailAddress = p.Email.Replace("gmail.com", "helloayanova.com").Replace("hotmail.com", "helloayanova.com").Replace("yahoo.com", "helloayanova.com");
Biz.CreateAsync(u).Wait();
}
//save to get id values
ct.SaveChanges();
// ct.SaveChanges();
//Now that we have the ID values bulk add the event log entries
//To save a db call iterate the local collection in the context, but...
//can't modify the context in the foreach, even if it's another collection entirely, so need to save the id's in a temporary list
List<long> ItemsAdded = new List<long>();
foreach (User o in ct.User.Local)
{
ItemsAdded.Add(o.Id);
}
// List<long> ItemsAdded = new List<long>();
// foreach (User o in ct.User.Local)
// {
// ItemsAdded.Add(o.Id);
// }
//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);
}
// //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);
// }
//Now save the Event Log entries
ct.SaveChanges();
}
public static void GenSeedUserViaBiz(int count, AuthorizationRoles roles, UserType userType, bool active = true, string login = null, string password = null)
{
AyContext ct = ServiceProviderProvider.DBContext;
for (int x = 0; x < count; x++)
{
User u = new User();
u.Active = active;
u.OwnerId = 1;
var p = new Bogus.Person();
u.Name = p.FullName;
u.Salt = Hasher.GenerateSalt();
if (login != null)
{
u.Login = login;
u.Name += " - " + login;
}
else
u.Login = p.FirstName;
if (password != null)
u.Password = Hasher.hash(u.Salt, password);
else
u.Password = Hasher.hash(u.Salt, u.Login);
u.Roles = roles;
u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
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
ct.SaveChanges();
//Now that we have the ID values bulk add the event log entries
//To save a db call iterate the local collection in the context, but...
//can't modify the context in the foreach, even if it's another collection entirely, so need to save the id's in a temporary list
List<long> ItemsAdded = new List<long>();
foreach (User o in ct.User.Local)
{
ItemsAdded.Add(o.Id);
}
//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);
}
//Now save the Event Log entries
ct.SaveChanges();
// //Now save the Event Log entries
// ct.SaveChanges();
}
//////////////////////////////////////////////////////