Esempio n. 1
0
        public async Task <ActionResult> RolesEdit_Partial(EditModel model)
        {
            using (RoleDefinitionDataProvider dataProvider = new RoleDefinitionDataProvider()) {
                string         originalRole = model.OriginalName;
                RoleDefinition role         = await dataProvider.GetItemAsync(originalRole);// get the original item

                if (role == null)
                {
                    throw new Error(this.__ResStr("alreadyDeleted", "The role named \"{0}\" has been removed and can no longer be updated.", originalRole));
                }

                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }

                role = model.GetData(role); // merge new data into original
                model.SetData(role);        // and all the data back into model for final display

                switch (await dataProvider.UpdateItemAsync(originalRole, role))
                {
                default:
                case UpdateStatusEnum.RecordDeleted:
                    throw new Error(this.__ResStr("alreadyDeleted", "The role named \"{0}\" has been removed and can no longer be updated.", originalRole));

                case UpdateStatusEnum.NewKeyExists:
                    ModelState.AddModelError(nameof(model.Name), this.__ResStr("alreadyExists", "A role named \"{0}\" already exists.", model.Name));
                    return(PartialView(model));

                case UpdateStatusEnum.OK:
                    break;
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Role \"{0}\" saved", role.Name), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
Esempio n. 2
0
        public async Task <IdentityResult> UpdateAsync(RoleDefinition role, CancellationToken cancellationToken)
        {
            RoleDefinitionDataProvider dataProvider = new RoleDefinitionDataProvider(this.CurrentSiteIdentity);
            UpdateStatusEnum           status       = await dataProvider.UpdateItemAsync(role);

            switch (status)
            {
            default:
            case UpdateStatusEnum.RecordDeleted:
                throw new Error(this.__ResStr("alreadyDeleted", "The role named \"{0}\" has been removed and can no longer be updated.", role.Name));

            case UpdateStatusEnum.NewKeyExists:
                throw new Error(this.__ResStr("alreadyExists", "A role named \"{0}\" already exists.", role.Name));

            case UpdateStatusEnum.OK:
                break;
            }
            return(IdentityResult.Success);
        }