Beispiel #1
0
        public async Task <FamilyModel> AddFamilyAsync(FamilyModel family)
        {
            // Authorize user

            // Validate input
            #region Validate input

            /// TODO: think of a strategy for validation => one solution to have one validation class that creates only
            /// one SQL call to check different validations => only one SQL access for validation

            // check at least one insuree in the family
            NotEmptyFamilyValidator      notEmptyFamilyValidator      = new NotEmptyFamilyValidator(null);
            OnlyOneHeadInFamilyValidator onlyOneHeadInFamilyValidator = new OnlyOneHeadInFamilyValidator(notEmptyFamilyValidator);
            onlyOneHeadInFamilyValidator.Validate(family);

            // check each insuree number is correct and unique
            /// TODO: add only one validator for the Insuree class as it will be used here and in the InsureeLogic
            //IInsureeLogic insureeLogic = this.imisModules.GetInsureeManagementModule().GetInsureeLogic();
            //UniqueInsureeNumberValidator uniqueInsureeNumberValidator = new UniqueInsureeNumberValidator(insureeLogic, insureeNumberValidator);
            //foreach (InsureeModel insuree in family.Insurees) {
            //	await uniqueInsureeNumberValidator.ValidateAsync(insuree.CHFID);
            //}

            #endregion

            // Execute business behaviour
            FamilyModel newFamily = await familyRepository.AddNewFamilyAsync(family);

            // Validate results

            // Validate data access rights

            // Return results
            return(newFamily);
        }