public async Task <CreatedActionResult <ItemResponse> > PatchMonsterAsync( [FromServices] NaheulbookExecutionContext executionContext, [FromRoute] int monsterId, PatchMonsterRequest request ) { try { await _monsterService.UpdateMonsterAsync(executionContext, monsterId, request); return(NoContent()); } catch (ForbiddenAccessException ex) { throw new HttpErrorException(StatusCodes.Status403Forbidden, ex); } catch (MonsterNotFoundException ex) { throw new HttpErrorException(StatusCodes.Status404NotFound, ex); } }
public async Task UpdateMonsterAsync(NaheulbookExecutionContext executionContext, int monsterId, PatchMonsterRequest request) { using (var uow = _unitOfWorkFactory.CreateUnitOfWork()) { var monster = await uow.Monsters.GetWithGroupWithItemsAsync(monsterId); if (monster == null) { throw new MonsterNotFoundException(monsterId); } _authorizationUtil.EnsureIsGroupOwner(executionContext, monster.Group); monster.Name = request.Name; var notificationSession = _notificationSessionFactory.CreateSession(); notificationSession.NotifyMonsterChangeName(monster.Id, request.Name); await uow.SaveChangesAsync(); await notificationSession.CommitAsync(); } }