public void RegisterUser([FromBody, Required] RegisterUserModel model) { using (UserHolder.UserSession(AuthLogic.SystemUser !)) { var role = Database.Query <RoleEntity>().SingleEx(a => a.Name == "Standard user").ToLite(); if (Database.Query <UserEntity>().Any(a => a.UserName == model.EMail)) { throw new ApplicationException(RegisterUserMessage.User0IsAlreadyRegistered.NiceToString(model.EMail)); } var employee = new EmployeeEntity { TitleOfCourtesy = model.TitleOfCourtesy, FirstName = model.FirstName, LastName = model.LastName, ReportsTo = model.ReportsTo, Address = model.Address, }.Execute(EmployeeOperation.Save); new UserEntity { UserName = model.EMail, PasswordHash = Security.EncodePassword(model.Password), Email = model.EMail, Role = role, }.InitiMixin((UserEmployeeMixin um) => { um.Employee = employee.ToLite(); }).Execute(UserOperation.Save); } }
internal static void LoadEmployees() { var america = new RegionEntity { Description = "America" }; var east = new TerritoryEntity { Description = "East coast", Region = america }.Save(); var west = new TerritoryEntity { Description = "South coast", Region = america }.Save(); var super = new EmployeeEntity { FirstName = "Super", LastName = "User", Address = RandomAddress(1), HomePhone = RandomPhone(1), Territories = { east, west }, }.Save(); new EmployeeEntity { FirstName = "Advanced", LastName = "User", Address = RandomAddress(2), HomePhone = RandomPhone(2), Territories = { west }, ReportsTo = super.ToLite(), }.Save(); new EmployeeEntity { FirstName = "Normal", LastName = "User", Address = RandomAddress(3), HomePhone = RandomPhone(4), Territories = { east }, ReportsTo = super.ToLite(), }.Save(); } //LoadEmployees