Exemple #1
0
        public async Task <IdentityResult> SetModules(TUser user, int[] modulos)
        {
            //Remove from removed modules
            foreach (var moduleUser in user.Modulos.ToList())
            {
                var module = await ModuleManager.FindByIdAsync(moduleUser.Id);

                if (modulos.All(moduleId => module.Id != moduleId))
                {
                    var result = await RemoveFromModuleAsync(user, module);

                    if (!result.Succeeded)
                    {
                        return(result);
                    }
                }
            }

            //Add to added modules
            foreach (var moduleUser in modulos)
            {
                var module = await ModuleManager.FindByIdAsync(moduleUser);

                if (user.Modulos.All(ur => ur.Id != module.Id))
                {
                    var result = await AddToModuleAsync(user, module);

                    if (!result.Succeeded)
                    {
                        return(result);
                    }
                }
            }

            return(IdentityResult.Success);
        }
Exemple #2
0
        public virtual async Task <LoginResult <TUser> > AccessAsync(int usuarioId, int moduloId)
        {
            var user = await UserManager.FindByIdAsync(usuarioId);

            if (user == null)
            {
                return(new LoginResult <TUser>(LoginResultType.InvalidUserNameOrEmailAddress));
            }

            var modulo = await ModuleManager.FindByIdAsync(moduloId);

            if (modulo == null)
            {
                return(new LoginResult <TUser>(LoginResultType.InvalidUserNameOrEmailAddress));
            }

            return(await AccessAsync(user, modulo));
        }