コード例 #1
0
        private async Task <bool> SaveNestedMAField(MAFieldSubmoduleType maField, int maID, bool isVariation, int createdByUserID, bool accumulator = true, bool commit = true)
        {
            if (maField.FieldSubmoduleType.IsSelected)
            {
                var tMAField = new MAFieldSubmoduleType();
                tMAField.CopyProperties(maField);
                tMAField.NullifyForeignKeys();

                accumulator = accumulator && (await _maFieldSubmoduleType.CreateOrUpdateAsync(tMAField, commit, mf => mf.MAID == tMAField.MAID && mf.FieldSubmoduleTypeID == tMAField.FieldSubmoduleTypeID && mf.IsVariation == tMAField.IsVariation));

                foreach (var child in maField.FieldSubmoduleType.Children.Where(f => f.IsSelected))
                {
                    var newMAField = new MAFieldSubmoduleType
                    {
                        MAID = maID,
                        FieldSubmoduleTypeID = child.ID,
                        FieldSubmoduleType   = child,
                        IsVariation          = isVariation,
                        CreatedByUserID      = createdByUserID
                    };
                    await SaveNestedMAField(newMAField, maID, isVariation, createdByUserID, accumulator);
                }

                return(accumulator);
            }
            return(false);
        }
コード例 #2
0
        public async Task <bool> SaveMAField(MAFieldSubmoduleType maField)
        {
            var existingMAFields = await _maFieldSubmoduleType.FindByAsync(mf => mf.MAID == maField.MAID);

            //Make inactive all existingMAFields
            foreach (var mf in existingMAFields)
            {
                mf.IsActive = false;
            }
            await _maFieldSubmoduleType.UpdateAsync(existingMAFields);

            var result = await this.SaveNestedMAField(maField, maField.MAID, maField.IsVariation, maField.CreatedByUserID, true);

            return(result);
        }