Example #1
0
        } //CSharpMigrations

        internal static void CreateRoles()
        {
            using (Transaction tr = new Transaction())
            {
                RoleEntity su = new RoleEntity() { Name = "Super user", MergeStrategy = MergeStrategy.Intersection }.Save();
                RoleEntity u = new RoleEntity() { Name = "User", MergeStrategy = MergeStrategy.Union }.Save();

                RoleEntity au = new RoleEntity()
                {
                    Name = "Advanced user",
                    Roles = new MList<Lite<RoleEntity>> { u.ToLite() },
                    MergeStrategy = MergeStrategy.Union
                }.Save();
                tr.Commit();
            }
        }
        static void CreateUser(string userName, RoleEntity role)
        {
            var user = new UserEntity
            {
                UserName = userName,
                PasswordHash = Security.EncodePassword(userName),
                Role = role.ToLite(),
                State = UserState.Saved,
            };

            user.SetMixin((UserEmployeeMixin e) => e.Employee, Database.Query<EmployeeEntity>().Single(e => e.FirstName == userName).ToLite());

            user.Save();
        }
Example #3
0
        internal static void CreateUsers()
        {
            using (Transaction tr = new Transaction())
            {
                RoleEntity su = new RoleEntity() { Name = "Super user", MergeStrategy = MergeStrategy.Intersection }.Save();
                RoleEntity u = new RoleEntity() { Name = "User", MergeStrategy = MergeStrategy.Union }.Save();

                RoleEntity au = new RoleEntity()
                {
                    Name = "Advanced user",
                    Roles = new MList<Lite<RoleEntity>> { u.ToLite() },
                    MergeStrategy = MergeStrategy.Union
                }.Save();

                var employees = Database.Query<EmployeeEntity>().OrderByDescending(a => a.Notes.Length).ToList();

                using (OperationLogic.AllowSave<UserEntity>())
                    for (int i = 0; i < employees.Count; i++)
                    {
                        var employee = employees[i];
                        new UserEntity
                        {
                            UserName = employee.FirstName,
                            PasswordHash = Security.EncodePassword(employee.FirstName),
                            Role = i < 2 ? su :
                                   i < 5 ? au : u,
                            State = UserState.Saved,

                        }.SetMixin((UserEmployeeMixin e)=>e.Employee, employee).Save();
                    }

                tr.Commit();
            }
        }