public void ApplyChangesAndNotify(Group group, PatchGroupConfigRequest request, INotificationSession notificationSession) { var config = _jsonUtil.DeserializeOrCreate <GroupConfig>(group.Config); if (request.AllowPlayersToAddObject.HasValue) { config.AllowPlayersToAddObject = request.AllowPlayersToAddObject.Value; } if (request.AllowPlayersToSeeSkillGmDetails.HasValue) { config.AllowPlayersToSeeSkillGmDetails = request.AllowPlayersToSeeSkillGmDetails.Value; } if (request.AllowPlayersToSeeGemPriceWhenIdentified.HasValue) { config.AllowPlayersToSeeGemPriceWhenIdentified = request.AllowPlayersToSeeGemPriceWhenIdentified.Value; } group.Config = _jsonUtil.SerializeNonNull(config); notificationSession.NotifyGroupChangeConfig(group.Id, config); }
public async Task <IActionResult> PatchGroupConfigAsync( [FromServices] NaheulbookExecutionContext executionContext, [FromRoute] int groupId, PatchGroupConfigRequest request ) { try { await _groupService.EditGroupConfigAsync(executionContext, groupId, request); return(NoContent()); } catch (ForbiddenAccessException ex) { throw new HttpErrorException(StatusCodes.Status403Forbidden, ex); } catch (GroupNotFoundException ex) { throw new HttpErrorException(StatusCodes.Status404NotFound, ex); } }
public async Task EditGroupConfigAsync(NaheulbookExecutionContext executionContext, int groupId, PatchGroupConfigRequest request) { var notificationSession = _notificationSessionFactory.CreateSession(); using (var uow = _unitOfWorkFactory.CreateUnitOfWork()) { var group = await uow.Groups.GetAsync(groupId); if (group == null) { throw new GroupNotFoundException(groupId); } _authorizationUtil.EnsureIsGroupOwner(executionContext, group); _groupConfigUtil.ApplyChangesAndNotify(group, request, notificationSession); await uow.SaveChangesAsync(); } await notificationSession.CommitAsync(); }