コード例 #1
0
        public override bool Save(SyncConfiguration entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            using (var db = this.GetDb(true))
            {
                var result = true;
                var pm     = AutoMapper.Mapper.Map <SyncConfigurationPM>(entity);

                // Insert the main sync config object
                result &= base.SavePM(pm);
                if (!result)
                {
                    return(false); // Should be rolled back by the open transaction
                }

                // Insert the backup source
                if (pm.Source != null)
                {
                    var backupSourceRepo = new BackupSourceRepository(db);
                    result &= backupSourceRepo.Save(pm.Source);
                    if (!result)
                    {
                        return(false); // Should be rolled back by the open transaction
                    }
                }

                // Insert each destination record
                var backupDestinationRepo = new BackupDestinationRepository(db);
                foreach (var destination in pm.Destinations)
                {
                    result &= backupDestinationRepo.Save(destination);
                }

                // Commit or rollback open transaction
                if (result)
                {
                    db.Commit();
                }
                // Else it will rollback automatically

                // Return the hydrated domain entity
                AutoMapper.Mapper.Map(pm, entity);

                return(result);
            }
        }