public async Task <Result> Handle(CreateOperatorActivityCommand request, CancellationToken cancellationToken) { dynamic jObject = request.OperatorActivities; var activitiesArray = JArray.Parse(jObject.Activities.ToString()) as JArray; var activities = _jsonService.ToObject <List <OperatorActivityDto> >(activitiesArray); var result = Result.Ok(); try { foreach (var activityDto in activities) { var id = _identifierProvider.Generate(); var version = _versionProvider.Generate(); var operatorActivity = new OperatorActivity(id); _mapper.Map(activityDto, operatorActivity); operatorActivity.Version = version; await _operatorActivityWriteRepository.CreateAsync(operatorActivity); result = Result.Ok(id, operatorActivity.Version); } } catch (Exception) { result = Result.Fail(CustomFailures.CreateOperatorActivityFailure); } return(result); }