public async Task <IActionResult> EditPeopleInControl(Guid applicationId, int index)
        {
            var personTableData = await _tabularDataRepository.GetTabularDataAnswer(applicationId, RoatpWorkflowQuestionTags.AddPeopleInControl);

            if (personTableData != null)
            {
                if (index >= personTableData.DataRows.Count)
                {
                    return(RedirectToAction("ConfirmPeopleInControl", new { applicationId }));
                }

                var person      = personTableData.DataRows[index];
                var name        = person.Columns[0];
                var dateOfBirth = person.Columns[1];
                var model       = new AddEditPeopleInControlViewModel
                {
                    ApplicationId       = applicationId,
                    PersonInControlName = name,
                    Index      = index,
                    Identifier = "person",
                    PersonInControlDobMonth = DateOfBirthFormatter.GetMonthNumberFromShortDateOfBirth(dateOfBirth),
                    PersonInControlDobYear  = DateOfBirthFormatter.GetYearFromShortDateOfBirth(dateOfBirth),
                    DateOfBirthOptional     = false,
                    GetHelpAction           = "EditPeopleInControl",
                    PageId = "EditPeopleInControl"
                };

                PopulateGetHelpWithQuestion(model);
                return(View($"~/Views/Roatp/WhosInControl/EditPeopleInControl.cshtml", model));
            }
            return(RedirectToAction("ConfirmPeopleInControl", new { applicationId }));
        }
        private List <TrusteeDateOfBirth> MapTrusteesDataToViewModel(TabularData trusteeData)
        {
            var trusteeDatesOfBirth = new List <TrusteeDateOfBirth>();

            if (trusteeData != null && trusteeData.DataRows != null)
            {
                foreach (var trustee in trusteeData.DataRows)
                {
                    var trusteeDob = new TrusteeDateOfBirth
                    {
                        Id   = trustee.Id,
                        Name = trustee.Columns[0]
                    };
                    if (trustee.Columns.Count > 1)
                    {
                        var shortDob = trustee.Columns[1];
                        trusteeDob.DobMonth = DateOfBirthFormatter.GetMonthNumberFromShortDateOfBirth(shortDob);
                        trusteeDob.DobYear  = DateOfBirthFormatter.GetYearFromShortDateOfBirth(shortDob);
                    }
                    trusteeDatesOfBirth.Add(trusteeDob);
                }
            }

            return(trusteeDatesOfBirth);
        }
        public async Task <IActionResult> EditPartner(Guid applicationId, int index)
        {
            var partnerTableData = await _tabularDataRepository.GetTabularDataAnswer(applicationId, RoatpWorkflowQuestionTags.AddPartners);

            if (partnerTableData != null)
            {
                if (index >= partnerTableData.DataRows.Count)
                {
                    return(RedirectToAction("ConfirmPartners", new { applicationId }));
                }

                var partner = partnerTableData.DataRows[index];

                var model = new AddEditPeopleInControlViewModel
                {
                    ApplicationId       = applicationId,
                    PersonInControlName = partner.Columns[0],
                    Index               = index,
                    Identifier          = "organisation",
                    DateOfBirthOptional = true,
                    GetHelpAction       = "EditPartner",
                    PageId              = "EditPartner"
                };

                if (partner.Columns.Count > 1 && !string.IsNullOrEmpty(partner.Columns[1]))
                {
                    var dateOfBirth = partner.Columns[1];
                    model.PersonInControlDobMonth = DateOfBirthFormatter.GetMonthNumberFromShortDateOfBirth(dateOfBirth);
                    model.PersonInControlDobYear  = DateOfBirthFormatter.GetYearFromShortDateOfBirth(dateOfBirth);
                    model.DateOfBirthOptional     = false;
                    model.Identifier = "individual";
                }

                PopulateGetHelpWithQuestion(model);

                return(View($"~/Views/Roatp/WhosInControl/EditPartner.cshtml", model));
            }
            return(RedirectToAction("ConfirmPartners", new { applicationId }));
        }
        public void Get_month_number_converts_short_date_to_month_number(string shortDate, string expectedValue)
        {
            var monthNumber = DateOfBirthFormatter.GetMonthNumberFromShortDateOfBirth(shortDate);

            monthNumber.Should().Be(expectedValue);
        }