public LInst.User CreateNewUser(Person personInstance, string userName, string password) { LInst.User output = new LInst.User(); output.FullName = ""; output.UserName = userName; output.HashedPassword = CalculateHash(password, userName); using (LInstContext context = _contextFactory.CreateDbContext(new string[] { })) { output.Person = context.People.First(per => per.ID == personInstance.ID); foreach (UserRole role in context.UserRoles) { UserRoleMapping tempMapping = new UserRoleMapping(); tempMapping.UserRole = role; tempMapping.IsSelected = false; output.RoleMappings.Add(tempMapping); } context.Users.Add(output); context.SaveChanges(); } return(output); }
public void AddOrganizationRole(string name) { using (LInstContext entities = _dbContextFactory.CreateDbContext(new string[] { })) { OrganizationRole newRole = new OrganizationRole { Name = name, Description = "" }; entities.OrganizationRoles.Add(newRole); foreach (Organization org in entities.Organizations) { OrganizationRoleMapping newMapping = new OrganizationRoleMapping { OrganizationRole = newRole, Organization = org, IsSelected = false }; entities.OrganizationRoleMappings.Add(newMapping); } entities.SaveChanges(); } }
/// <summary> /// Creates and inserts in the DB the mappings between a new OrganizationRole /// and all the existing organization /// </summary> /// <param name="newRole">The role for which will be built the mappings</param> internal void CreateMappingsForNewRole(OrganizationRole newRole) { using (LInstContext entities = _dbContextFactory.CreateDbContext(new string[] { })) { IEnumerable <Organization> _orgList = entities.Organizations.ToList(); foreach (Organization org in _orgList) { OrganizationRoleMapping tempMap = new OrganizationRoleMapping() { IsSelected = false, OrganizationRoleID = newRole.ID }; org.RoleMappings.Add(tempMap); } entities.SaveChanges(); } }
public PersonRole CreateNewPersonRole() { StringInputDialog addPersonRoleDialog = new StringInputDialog(); addPersonRoleDialog.Title = "Creazione nuovo Ruolo Persona"; addPersonRoleDialog.Message = "Nome:"; if (addPersonRoleDialog.ShowDialog() != true) { return(null); } PersonRole newRole = new PersonRole { Name = addPersonRoleDialog.InputString, Description = "" }; using (LInstContext entities = _dbContextFactory.CreateDbContext(new string[] { })) { entities.PersonRoles.Add(newRole); foreach (Person per in entities.People) { PersonRoleMapping newMapping = new PersonRoleMapping { Person = per, IsSelected = false }; newRole.RoleMappings.Add(newMapping); } entities.SaveChanges(); } return(newRole); }