I'm writing a setup sequence where I'm populating the required data for a new site in a multi-tenancy CMS. However, while I'm quite familiar with the data design and all the web front end, I'm extremely new to actual coding.
As you can see from the code below, I have a 'for each' expression for creating my roles that are in a list in the config.cs - these create beautifully.
For each default user however, I need to assign one of the values from the user roles that I just created by name. I think this might have something to do with LINQ, but I'm not sure how to break this out. Any suggestions?
Here is the code:
foreach (var userRoleName in _configData.UserRoles)
{
var newUserRole = new UserRole(newSite, userRoleName);
_daoFactory.GetUserRoleDao().Save(newUserRole);
}
_daoFactory.GetUserRoleDao().FlushChanges();
//Thinking this is not needed?
Thread.Sleep(500);
//var newSiteCopy = _daoFactory.GetSiteDao().GetById(newSite.Id);
_daoFactory.GetSiteDao().Refresh(newSite);
foreach (var defaultUser in _configData.Users)
{
var newUser = new User(newSite, defaultUser.FullName, defaultUser.Login, defaultUser.Password);
_daoFactory.GetUserDao().Save(newUser);
}
_daoFactory.GetUserDao().FlushChanges();
Here is the config.cs code: (The actual values will be moved out of this file into a doc but are here for dev purposes only.)
public class ConfigData
{
public ConfigData()
{
SystemDomainDefault = ".joyatechsolutions.com";
UserRoles = new List<string>{"Administrator","Editor","Public","God"};
Users = new List<DefaultUser>
{
new DefaultUser { FullName = "Default Public User", Login = "", Password = "", UserRoleName = "Public"},
new DefaultUser { FullName = "Mary Camacho", Login = "mc", Password = "test1", UserRoleName = "God"},
new DefaultUser { FullName = "Mary", Login = "mn", Password = "test2", UserRoleName = "God"},
};
}
public List<DefaultUser> Users { get; set; }
public string SystemDomainDefault { get; set; }
public List<string> UserRoles { get; set; }
}
public class DefaultUser
{
public string FullName { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public string UserRoleName { get; set; }
}