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> Create(RoleCreateForm form)
        {
            var validationResult =
                new RoleCreateFormValidator(
                    RoleStore,
                    ResourceStore,
                    CodeRule,
                    DescriptionRule,
                    DisplayNameRule)
                .Validate(form);

            validationResult.AddToModelState(this.ModelState, null);

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

            Role role = new Role(form.Code, form.Name, form.Description, form.Permissions);
            await RoleStore.Create(role);

            var view = Element <Role>(role);

            return(CreatedAtAction(nameof(GetByCode), new { role.Code }, view));
        }