Beispiel #1
0
        public virtual async Task Seed(IResourceStore resourceStore, IRoleStore roleStore)
        {
            IEnumerable <string> resourceCodes = await resourceStore.GetAllCodes();

            bool isExistingAdminRole = roleStore.IsExisting(GtkRoleCodes.Admin).Result;

            if (!isExistingAdminRole)
            {
                Role defaultAdminRole = GetDefaultAdminRole(resourceCodes);
                await roleStore.Create(defaultAdminRole);
            }

            bool isExistingUserRole = roleStore.IsExisting(GtkRoleCodes.User).Result;

            if (!isExistingUserRole)
            {
                Role defaultUserRole = GetDefaultUserRole(resourceCodes);
                await roleStore.Create(defaultUserRole);
            }

            bool isExistingGuestRole = roleStore.IsExisting(GtkRoleCodes.Guest).Result;

            if (!isExistingGuestRole)
            {
                Role defaultGuestRole = GetDefaultGuestRole(resourceCodes);
                await roleStore.Create(defaultGuestRole);
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(
            [FromRoute] string code,
            [FromBody] RoleUpdateForm form)
        {
            if (string.IsNullOrEmpty(code))
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (!await RoleStore.IsExisting(code))
            {
                return(NotFound());
            }

            var validationResult =
                new RoleUpdateFormValidator(
                    RoleStore,
                    ResourceStore,
                    DisplayNameRule,
                    DescriptionRule)
                .Validate(form);

            validationResult.AddToModelState(this.ModelState, null);

            if (!validationResult.IsValid)
            {
                return(ValidationError());
            }

            Role role = await RoleStore.Get(code);

            role.DisplayName = form.DisplayName;
            role.Description = form.Description;
            role.Permissions = form.Permissions;

            await RoleStore.Update(role);

            var view = Element <Role>(role);

            return(AcceptedAtAction(nameof(GetByCode), new { role.Code }, view));
        }
Beispiel #3
0
        private async Task <bool> NotBeExistingCodeAsync(string roleCode, CancellationToken cancelToken)
        {
            bool isExisting = await RoleStore.IsExisting(roleCode);

            return(!isExisting);
        }