public async Task <ActionResult> Edit(string id)
        {
            this.Authorize();

            // 選択したロールを表示
            ApplicationRole role = await RoleManager.FindByIdAsync(id);

            // マルチテナントの場合、所有権を確認する。
            if (await this.CheckOwnershipInMultitenantMode(role.ParentId))
            {
                // 配下のobjectである。
            }
            else
            {
                // 配下のobjectでない。
                // エラー → リダイレクト(一覧へ)
                return(RedirectToAction("Index", new { Message = EnumAdminMessageId.DoNotHaveOwnershipOfTheObject }));
            }

            RolesAdminEditViewModel roleModel = new RolesAdminEditViewModel
            {
                Id       = role.Id,
                ParentId = role.ParentId,
                Name     = role.Name
            };

            return(View(roleModel));
        }
        public async Task <ActionResult> Create(RolesAdminEditViewModel roleViewModel)
        {
            this.Authorize();

            if (ModelState.IsValid)
            {
                // RolesAdminEditViewModelの検証に成功

                // テナントのロールを追加
                ApplicationUser user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                ApplicationRole role   = ApplicationRole.CreateForIndividual(user, roleViewModel.Name);
                IdentityResult  result = await RoleManager.CreateAsync(role);

                if (result.Succeeded)
                {
                    // ロールの追加に成功

                    // リダイレクト(一覧へ)
                    return(RedirectToAction("Index", new { Message = EnumAdminMessageId.AddSuccess }));
                }
                else
                {
                    // ロールの追加に失敗
                    ModelState.AddModelError("", result.Errors.First());
                }
            }
            else
            {
                // RolesAdminEditViewModelの検証に失敗
            }

            // 再表示
            return(View());
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,ParentId,Name")] RolesAdminEditViewModel roleModel)
        {
            this.Authorize();

            // 選択したロールを更新
            if (ModelState.IsValid)
            {
                // RolesAdminEditViewModelの検証に成功

                // 選択したロールを取得
                ApplicationRole role = await RoleManager.FindByIdAsync(roleModel.Id);

                // マルチテナントの場合、所有権を確認する。
                if (await this.CheckOwnershipInMultitenantMode(role.ParentId))
                {
                    // 配下のobjectである。
                }
                else
                {
                    // 配下のobjectでない。
                    // エラー → リダイレクト(一覧へ)
                    return(RedirectToAction("Index", new { Message = EnumAdminMessageId.DoNotHaveOwnershipOfTheObject }));
                }

                if (string.IsNullOrEmpty(role.ParentId))
                {
                    // グローバル ロールは更新しない。
                    // (ボタンを表示しないのでココには来ない)
                }
                else
                {
                    // 選択したテナント ロールを更新
                    role.Name = roleModel.Name;
                    IdentityResult result = await RoleManager.UpdateAsync(role);

                    if (result.Succeeded)
                    {
                        // 更新の成功

                        // リダイレクト(一覧へ)
                        return(RedirectToAction("Index", new { Message = EnumAdminMessageId.EditSuccess }));
                    }
                    else
                    {
                        // 更新の失敗
                        ModelState.AddModelError("", result.Errors.First());
                    }
                }
            }
            else
            {
                // RoleViewModelの検証に失敗
            }

            // 再表示
            return(View(roleModel));
        }
Пример #4
0
        public async Task <ActionResult> Edit(string id)
        {
            this.Authorize();

            // 選択したロールを表示
            ApplicationRole role = await RoleManager.FindByIdAsync(id);

            RolesAdminEditViewModel roleModel = new RolesAdminEditViewModel
            {
                Id   = role.Id,
                Name = role.Name
            };

            return(View(roleModel));
        }
Пример #5
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name")] RolesAdminEditViewModel roleModel)
        {
            this.Authorize();

            // 選択したロールを更新
            if (ModelState.IsValid)
            {
                // RolesAdminEditViewModelの検証に成功

                // 選択したロールを取得
                ApplicationRole role = await RoleManager.FindByIdAsync(roleModel.Id);


                // 選択したロールを更新
                role.Name = roleModel.Name;
                IdentityResult result = await RoleManager.UpdateAsync(role);

                if (result.Succeeded)
                {
                    // 更新の成功

                    // リダイレクト(一覧へ)
                    return(RedirectToAction("Index", new { Message = EnumAdminMessageId.EditSuccess }));
                }
                else
                {
                    // 更新の失敗
                    ModelState.AddModelError("", result.Errors.First());
                }
            }
            else
            {
                // RoleViewModelの検証に失敗
            }

            // 再表示
            return(View(roleModel));
        }