Beispiel #1
0
        protected virtual void ProjectToTable(IRepository <TDest> repository, IDbConnectionContextFactory connectionCtxFactory, ICPRContext ctx, T cmd, ILoggerFactory loggerFactory, IConfiguration config)
        {
            var id   = s_srcKey(cmd);
            var dest = repository.Get(id);

            var newObject = (dest == null);

            if (newObject)
            {
                dest = Activator.CreateInstance <TDest>();
            }

            s_mapper.Map(cmd, dest);

            Intercept(connectionCtxFactory, ctx, newObject, dest, loggerFactory, config);

            if (newObject)
            {
                repository.Insert(dest);
            }
            else
            {
                repository.Update(dest);
            }
        }
Beispiel #2
0
        protected void ProjectToTable(
            IRepository <TOriginal> originalRepository,
            IRepository <TArchive> archiveRepository,
            IDbConnectionContextFactory connectionCtxFactory,
            ICPRContext ctx,
            T cmd,
            ILoggerFactory loggerFactory,
            IConfiguration config)
        {
            var id   = s_srcKey(cmd);
            var orig = originalRepository.Get(id);
            var arch = Activator.CreateInstance <TArchive>();

            if (orig != null)
            {
                s_mapper.Map(orig, arch);

                arch.LUID            = Guid.NewGuid();
                arch.DeletedByUserID = ctx.UserID;
                arch.DeletedOn       = DateTime.UtcNow;

                archiveRepository.Insert(arch);
                originalRepository.Delete(orig);
            }
        }
Beispiel #3
0
        protected virtual void Intercept(IDbConnectionContextFactory connectionCtxFactory, ICPRContext ctx, bool created, TDest dest, ILoggerFactory loggerFactory, IConfiguration config)
        {
            if (dest is ICPRTable)
            {
                var table = (ICPRTable)dest;

                if (created)
                {
                    table.CreatedByUserID = ctx.UserID;
                    table.CreatedOn       = DateTime.UtcNow;
                }

                table.ModifiedByUserID = ctx.UserID;
                table.ModifiedOn       = DateTime.UtcNow;
            }
        }
Beispiel #4
0
        public virtual void Project(IDbConnectionContextFactory connectionCtxFactory, ICPRContext ctx, T cmd, ILoggerFactory loggerFactory, IConfiguration config)
        {
            if (m_originalRepository != null)
            {
                throw new Exception("You must either pass in both repositories to use ICPRDatabaseProject.Project with an IDbConnectionContextFactory.");
            }
            if (m_archiveRepository != null)
            {
                throw new Exception("You must either pass in both repositories to use ICPRDatabaseProject.Project with an IDbConnectionContextFactory.");
            }

            var originalRepository = new Repository <TOriginal>(connectionCtxFactory, loggerFactory, config);
            var archiveRepository  = new Repository <TArchive>(connectionCtxFactory, loggerFactory, config);

            ProjectToTable(originalRepository, archiveRepository, connectionCtxFactory, ctx, cmd, loggerFactory, config);
        }
Beispiel #5
0
 protected override void Intercept(IDbConnectionContextFactory connectionCtxFactory, ICPRContext ctx, bool created, DataTable dest, ILoggerFactory loggerFactory, IConfiguration config)
 {
     InterceptCalled();
 }
Beispiel #6
0
        public virtual void Project(IDbConnectionContextFactory connectionCtxFactory, ICPRContext ctx, T cmd, ILoggerFactory loggerFactory, IConfiguration config)
        {
            var rep = new Repository <TDest>(connectionCtxFactory, loggerFactory, config);

            ProjectToTable(rep, connectionCtxFactory, ctx, cmd, loggerFactory, config);
        }
Beispiel #7
0
 public Repository(IDbConnectionContextFactory connectionCtxFactory, ILoggerFactory loggerFactory, IConfiguration config)
 {
     m_connectionCtxFactory = connectionCtxFactory;
     m_logger = loggerFactory.CreateLogger <Repository <T> >();
 }
Beispiel #8
0
 public RepositorySetup(IDbConnectionContextFactory connectionInstantiator, IConfiguration config, ILoggerFactory loggerFactory)
 {
     m_connectionInstantiator = connectionInstantiator;
     m_logger = loggerFactory.CreateLogger <RepositorySetup>();
 }