public async Task <Result <IndicatorResponse> > Handle(SubmitIndicatorResultsCommand request, CancellationToken cancellationToken)
        {
            using (var transaction = _airUnitOfWork.BeginTransaction(IsolationLevel.ReadCommitted))
            {
                try
                {
                    var reportingPeriod = new ReportingPeriod(request.ReportingFormId, request.ReportingDate, request.CreatedBy);
                    await _airUnitOfWork.Repository <ReportingPeriod>().AddAsync(reportingPeriod);

                    var indicatorResults = request.IndicatorResults.Select(x =>
                                                                           new IndicatorResult(reportingPeriod.Id, x.Id, x.ResultText, x.ResultNumeric, request.CreatedBy));

                    await _airUnitOfWork.Repository <IndicatorResult>().AddRangeAsync(indicatorResults);

                    await _airUnitOfWork.SaveAsync();

                    transaction.Commit();

                    return(Result <IndicatorResponse> .Valid(new IndicatorResponse()
                    {
                        Message = "Indicator results added succesfully",
                        ReportingFormId = request.ReportingFormId
                    }));
                }
                catch (Exception ex)
                {
                    _logger.Error(ex,
                                  $"An error occured while submitting indicator results for period {request.ReportingDate} and ReportId {request.ReportingFormId}");
                    transaction.Rollback();

                    return(Result <IndicatorResponse> .Invalid("An error occured while submittig indicator results"));
                }
            }
        }
        public async Task <IActionResult> AddResults([FromBody] SubmitIndicatorResultsCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.Select(x => x.Errors)));
            }

            var response = await _mediator.Send(command, HttpContext.RequestAborted);

            if (!response.IsValid)
            {
                return(BadRequest(response));
            }

            return(Ok(response.Value));
        }