public async Task <DeliveryDto> Update(IExecutionContext executionContext, DeliveryDto entity) { AssertExecutionContext(executionContext); if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var existedEntity = await _deliveryRepo.Get(entity.Id); if (existedEntity == null) { return(null); } var oldState = existedEntity.State; var newState = entity.State; if (!_permissionChecker.RoleHasChangePermission(executionContext.UserRole, oldState, newState)) { throw new UnauthorizedException( $"This role has no permission to change the role from {oldState} to {newState}"); } var dbEntity = await _deliveryRepo.Update(_deliveryMapper.To(entity)); return(_deliveryMapper.From(dbEntity)); }