Example #1
0
        public RoleCreator_Main()
        {
            InitializeComponent();

            using (var db = new MySqlContext())
            {
                var permissions = from a in db.Permissions
                                  select a.Name;
                this.checkedListBox1.Items.AddRange(permissions.ToArray());

            }
        }
Example #2
0
        static void Main()
        {
            Database.SetInitializer<MySqlContext>(new DropCreateDatabaseIfModelChanges<MySqlContext>());
               // Database.SetInitializer<MySqlContext>(new DropCreateDatabaseAlways<MySqlContext>());

            var connString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ToString();

            using (var db = new MySqlContext())
            {
                #region read

                #region find a specific role

                //var user = db.Roles
                //    .Where(a => a.Name == "role2");

                //foreach (var role in user)
                //{
                //    MessageBox.Show(role.Name);
                //}
                #endregion

                #endregion

                #region insert

                //l = Unify.ServiceInterface.Utils.God2("Unify.ServiceInterface");
                //var l = new List<string>() { "Permiso1", "Permiso2", "Permiso3" };

                var role1 = new Roles() { Name = "role1" };
                var role2 = new Roles() { Name = "role2" };
                var Admin1 = new Roles() { Name = "Admin1" };
                var Admin2 = new Roles() { Name = "Admin2" };
                var roles = new List<Roles>();
                roles.Add(role1);
                roles.Add(role2);
                roles.Add(Admin1);
                roles.Add(Admin2);

                var rafa = new LoginModel() { User = "******", Pass = "******" };
                var javier = new LoginModel() { User = "******", Pass = "******" };
                var users = new List<LoginModel>();
                users.Add(rafa);
                users.Add(javier);

                var permission1 = new Permission() { Name = "Permission1" };
                var permission2 = new Permission() { Name = "Permission2" };
                var permissions2 = new List<Permission>();
                permissions2.Add(permission1);
                permissions2.Add(permission2);

                var p1 = new Permission() { Name = "p1" };
                var p2 = new Permission() { Name = "p2" };
                var permissions = new List<Permission>();
                permissions.Add(p1);
                permissions.Add(p2);

                db.LoginModel.Add(

                    new LoginModel
                    {
                        User = rafa.User,
                        Pass = rafa.Pass,
                        roles =
                        {
                            new Roles {Name = p1.Name, Permissions= new Collection<Permission>(permissions)}

                        }

                    }

                    );

                db.LoginModel.Add(
                    new LoginModel
                    {
                        User = javier.User,
                        Pass = javier.Pass,
                        roles =
                        {
                            new Roles {Name = Admin1.Name, Permissions = new Collection<Permission>(permissions2)},
                            new Roles {Name = Admin2.Name}
                        }

                    }

                    );

                #endregion

                db.SaveChanges();

            }
            MessageBox.Show("All ok!");
            Console.Read();

            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new RoleCreator_Main());
        }