Example #1
0
        public async Task <IActionResult> EditReportSection([FromBody] ActivateFormSectionCommand 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));
        }
        public Task <Result <ActivateFormSectionResponse> > Handle(ActivateFormSectionCommand request, CancellationToken cancellationToken)
        {
            try
            {
                if (request.SectionList != null)
                {
                    foreach (var section in request.SectionList)
                    {
                        var formsection = _airUnitOfWork.Repository <ReportSection>().Get(x => x.Id == section.Id).FirstOrDefault();
                        if (formsection != null)
                        {
                            if (section.Active == true)
                            {
                                formsection.UpdateSection(true);
                            }
                            else if (section.Active == false)
                            {
                                formsection.UpdateSection(false);
                            }

                            _airUnitOfWork.Repository <ReportSection>().Update(formsection);
                        }

                        _airUnitOfWork.Save();
                    }
                }

                return(Task.FromResult(Result <ActivateFormSectionResponse> .Valid(new ActivateFormSectionResponse
                {
                    Message = $"The settings have been updated"
                })));
            }
            catch (Exception ex)
            {
                string message = $"An error has occurred: " + ex.Message.ToString();
                _logger.Error(ex, message);
                return(Task.FromResult(Result <ActivateFormSectionResponse> .Invalid(message)));
            }
        }