public async Task <IActionResult> AddPeopleInControlDetails(AddEditPeopleInControlViewModel model)
        {
            var errorMessages = PeopleInControlValidator.Validate(model);

            if (errorMessages.Any())
            {
                model.ErrorMessages = errorMessages;
                return(View("~/Views/Roatp/WhosInControl/AddPeopleInControl.cshtml", model));
            }

            var whosInControlSection = await _qnaApiClient.GetSectionBySectionNo(model.ApplicationId, RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl);

            var personInControlData = await _tabularDataRepository.GetTabularDataAnswer(model.ApplicationId, RoatpWorkflowQuestionTags.AddPeopleInControl);

            var personInControl = new TabularDataRow
            {
                Id      = Guid.NewGuid().ToString(),
                Columns = new List <string>
                {
                    model.PersonInControlName,
                    DateOfBirthFormatter.FormatDateOfBirth(model.PersonInControlDobMonth, model.PersonInControlDobYear)
                }
            };

            if (personInControlData == null)
            {
                personInControlData = new TabularData
                {
                    HeadingTitles = new List <string> {
                        "Name", "Date of birth"
                    },
                    DataRows = new List <TabularDataRow>
                    {
                        personInControl
                    }
                };

                var result = await _tabularDataRepository.SaveTabularDataAnswer(
                    model.ApplicationId,
                    whosInControlSection.Id,
                    RoatpWorkflowPageIds.WhosInControl.AddPeopleInControl,
                    RoatpYourOrganisationQuestionIdConstants.AddPeopleInControl,
                    personInControlData);
            }
            else
            {
                var result = await _tabularDataRepository.UpsertTabularDataRecord(
                    model.ApplicationId,
                    whosInControlSection.Id,
                    RoatpWorkflowPageIds.WhosInControl.AddPeopleInControl,
                    RoatpYourOrganisationQuestionIdConstants.AddPeopleInControl,
                    RoatpWorkflowQuestionTags.AddPeopleInControl,
                    personInControl);
            }

            return(RedirectToAction("ConfirmPeopleInControl", new { model.ApplicationId }));
        }
        public async Task <IActionResult> UpdatePartnerDetails(AddEditPeopleInControlViewModel model)
        {
            var errorMessages = PeopleInControlValidator.Validate(model);

            if (errorMessages.Any())
            {
                model.ErrorMessages = errorMessages;
                return(View("~/Views/Roatp/WhosInControl/EditPartner.cshtml", model));
            }

            var partnerTableData = await _tabularDataRepository.GetTabularDataAnswer(model.ApplicationId, RoatpWorkflowQuestionTags.AddPartners);

            if (partnerTableData != null)
            {
                var partner = new TabularDataRow
                {
                    Columns = new List <string> {
                        model.PersonInControlName
                    }
                };
                if (!model.DateOfBirthOptional)
                {
                    partner.Columns.Add(DateOfBirthFormatter.FormatDateOfBirth(model.PersonInControlDobMonth, model.PersonInControlDobYear));
                }
                else
                {
                    partner.Columns.Add(string.Empty);
                }

                var whosInControlSection = await _qnaApiClient.GetSectionBySectionNo(model.ApplicationId, RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl);

                var result = await _tabularDataRepository.EditTabularDataRecord(
                    model.ApplicationId,
                    whosInControlSection.Id,
                    RoatpWorkflowPageIds.WhosInControl.AddPartners,
                    RoatpYourOrganisationQuestionIdConstants.AddPartners,
                    RoatpWorkflowQuestionTags.AddPartners,
                    partner,
                    model.Index);
            }

            return(RedirectToAction("ConfirmPartners", new { model.ApplicationId }));
        }