public IActionResult AddOrUpdateFamilyResearch([FromForm] FamilyResearchViewModel model)
        {
            try
            {
                if (model == null)
                {
                    throw new ArgumentNullException(nameof(model), "Model cannot be null or empty");
                }

                if (model.IsValid(ModelState) == false)
                {
                    model.LoadMaritalStatuses(familyResearchRepository);
                    model.LoadRelationships(familyResearchRepository);
                    model.LoadStatesOfMexico(familyResearchRepository);
                    model.LoadMunicipalitiesOfMexico(familyResearchRepository);
                    model.LoadHomeAcquisitionList(familyResearchRepository);
                    model.LoadTipoDeMobiliarioList(familyResearchRepository);
                    model.LoadTypeOfDistrictList(familyResearchRepository);
                    model.SetInitialPatrimonyViewModelCollection(familyResearchRepository);
                    model.LoadFoods(familyResearchRepository);
                    model.LoadFrequencies(familyResearchRepository);
                    model.LoadTypesOfHousesList(familyResearchRepository);
                    model.CreationDate = DateTime.Now.ToCentralMexicoTime();

                    return(View("ShowForm", model));
                }

                model.VisitTime = DateTime.Parse(model.FormVisitTime);
                model.GetEconomicSituationPatrimonyRelationFromViewModel(familyResearchRepository);
                model.GetFamilyNutritionFoodRelationFromViewModel(familyResearchRepository);
                model.GetBenefitsProvidedFromSession();
                model.GetIngresosMensualesFromSession();
                model.GetFamilyMembersFromSession();

                if (model.Id > 0) // update item
                {
                    if (model.LegalGuardianId > 0)
                    {
                        model.LegalGuardian.Id = Convert.ToInt32(model.LegalGuardianId);
                    }

                    if (model.MinorId > 0)
                    {
                        model.Minor.Id = Convert.ToInt32(model.MinorId);
                    }

                    if (model.PreviousFoundationId > 0)
                    {
                        model.PreviousFoundation.Id = Convert.ToInt32(model.PreviousFoundationId);
                    }

                    if (model.FamilyHealthId > 0)
                    {
                        model.FamilyHealth.Id = Convert.ToInt32(model.FamilyHealthId);
                    }

                    if (model.SocioEconomicStudyId > 0)
                    {
                        model.SocioEconomicStudy.Id = Convert.ToInt32(model.SocioEconomicStudyId);
                    }

                    if (model.IngresosEgresosMensualesId > 0)
                    {
                        model.IngresosEgresosMensuales.Id = Convert.ToInt32(model.IngresosEgresosMensualesId);
                    }

                    if (model.DistrictId > 0)
                    {
                        model.District.Id = Convert.ToInt32(model.DistrictId);
                    }

                    if (model.Minor.FormalEducationId > 0)
                    {
                        model.Minor.FormalEducation.Id = Convert.ToInt32(model.Minor.FormalEducationId);
                    }

                    familyResearchRepository.Update(model);
                }
                else // add new item
                {
                    familyResearchRepository.Add(model);
                }
            }
            catch (BusinessLogicException ex)
            {
                ModelState.AddModelError("", ex.Message);
                model.LoadMaritalStatuses(familyResearchRepository);
                model.LoadRelationships(familyResearchRepository);
                model.LoadStatesOfMexico(familyResearchRepository);
                model.LoadMunicipalitiesOfMexico(familyResearchRepository);
                model.LoadHomeAcquisitionList(familyResearchRepository);
                model.LoadTipoDeMobiliarioList(familyResearchRepository);
                model.LoadTypeOfDistrictList(familyResearchRepository);
                model.SetInitialPatrimonyViewModelCollection(familyResearchRepository);
                model.LoadFoods(familyResearchRepository);
                model.LoadFrequencies(familyResearchRepository);
                model.LoadTypesOfHousesList(familyResearchRepository);

                return(View("ShowForm", model));
            }
            catch (Exception)
            {
                throw;
            }

            ClearSessionForTablesObject();

            return(RedirectToAction("Index"));
        }