Exemple #1
0
        public static void UpdateUserRole(Guid userId, string roleName)
        {
            Role role = new Role();

            using (var ctx = new DataClasses1DataContext())
            {
                role = ctx.Roles.FirstOrDefault(x => x.RoleName == roleName);
            }

            UsersInRole uir;

            using (var ctx = new DataClasses1DataContext())
            {
                uir = ctx.UsersInRoles.FirstOrDefault(x => x.RoleId == role.RoleId && x.UserId == userId);

                if (uir != null)
                {
                    ctx.UsersInRoles.DeleteOnSubmit(uir);
                }
                else
                {
                    uir = new UsersInRole();

                    uir.UserId = userId;
                    uir.RoleId = role.RoleId;

                    ctx.UsersInRoles.InsertOnSubmit(uir);
                }

                ctx.SubmitChanges();
            }
        }
Exemple #2
0
 private void detach_UsersInRoles(UsersInRole entity)
 {
     this.SendPropertyChanging();
     entity.User = null;
 }
Exemple #3
0
 private void attach_UsersInRoles(UsersInRole entity)
 {
     this.SendPropertyChanging();
     entity.User = this;
 }
Exemple #4
0
 partial void DeleteUsersInRole(UsersInRole instance);
Exemple #5
0
 partial void UpdateUsersInRole(UsersInRole instance);
Exemple #6
0
 partial void InsertUsersInRole(UsersInRole instance);