public async Task <IActionResult> EditAsync(CharacterEditBindingModel editModel)
        {
            var userId = this.userManager.GetUserId(this.User);

            await this.characterService
            .EditAsync(editModel, userId);

            return(this.RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        public async Task <Character> EditAsync(CharacterEditBindingModel editModel, string userId)
        {
            var character = await this.context.Characters.FindAsync(editModel.CharacterId);

            if (character.UserId != userId)
            {
                throw new InvalidOperationException(ErrorConstants.AccessDeniedErrorMessage);
            }

            character.Level  = editModel.Level;
            character.RoleId = this.GetRoleId(editModel.Role);

            this.context.Update(character);
            await this.context.SaveChangesAsync();

            return(character);
        }