Пример #1
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            Coupon.OnModelCreating(builder);
            Invoice.OnModelCreating(builder);
            LogMessage.OnModelCreating(builder);
            MoneyMovementJobRecord.OnModelCreating(builder);
            TaxReportJobRecord.OnModelCreating(builder);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            // setup env
            Configure();

            // log run
            var jobRecord = new MoneyMovementJobRecord()
            {
                Id     = Guid.NewGuid().ToString(),
                Name   = MoneyMovementJob.JobName,
                RanOn  = DateTime.UtcNow,
                Status = "Running",
            };

            _log = Log.Logger
                   .ForContext("jobname", jobRecord.Name)
                   .ForContext("jobid", jobRecord.Id);

            var assembyName = typeof(Program).Assembly.GetName();

            _log.Information("Running {job} build {build}", assembyName.Name, assembyName.Version);
            _log.Information("MoneyMovement Version 3");

            // setup di
            var provider  = ConfigureServices();
            var dbContext = provider.GetService <ApplicationDbContext>();

            // save log to db
            dbContext.MoneyMovementJobRecords.Add(jobRecord);
            dbContext.SaveChanges();

            try
            {
                // create job service
                var moneyMovementJob = provider.GetService <MoneyMovementJob>();

                // call each step
                moneyMovementJob.FindBankReconcileTransactions(_log).GetAwaiter().GetResult();

                moneyMovementJob.FindIncomeTransactions(_log).GetAwaiter().GetResult();
                jobRecord.Status = "Finished";
            }
            catch (Exception ex)
            {
                jobRecord.Status = "Error";
                _log.Error("Error running money movement job", ex);
                throw;
            }
            finally
            {
                dbContext.SaveChanges();
            }
        }