Пример #1
0
        public void AddPayments(object sender, FileSystemEventArgs e)
        {
            if (IsTargetExtension(Path.GetExtension(e.FullPath)))
            {
                var payments = new XMLDeserializator <List <Payment> >();
                var table    = payments.Load(e.FullPath);
                var comparer = new PaymentsCompare();

                if (table?.Any() == true)
                {
                    using (var context = new GeneratorContext())
                    {
                        using (var transaction = context.Database.BeginTransaction())
                        {
                            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Payments] ON");
                            var clientPayments = context.Payments.ToList();
                            var difPayments    = table.Except(clientPayments, comparer);
                            context.AddRange(difPayments);
                            context.SaveChanges();
                            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Payments] OFF");
                            transaction.Commit();
                        }
                    }
                }
            }
        }
Пример #2
0
        private CharacterNameRepository CreateInMemoryRepo(CharacterAncestryDto[] ancestries)
        {
            var options = new DbContextOptionsBuilder <GeneratorContext>()
                          .UseSqlite("DataSource=:memory:")
                          .Options;

            var context = new GeneratorContext(options);

            context.Database.OpenConnection();
            context.Database.EnsureCreated();
            context.AddRange(ancestries);
            context.SaveChanges();

            return(new CharacterNameRepository(context));
        }
Пример #3
0
        public async Task Execute(IJobExecutionContext context)
        {
            await Task.Run(() =>
            {
                var people           = new XMLDeserializator <List <Person> >();
                var payments         = new XMLDeserializator <List <Payment> >();
                var tablePeople      = people.Load(ConfigurationManager.AppSettings["BaseOfNames"]);
                var tablePayments    = payments.Load(ConfigurationManager.AppSettings["BaseOfPayments"]);
                var peopleComparer   = new PeopleCompare();
                var paymentsComparer = new PaymentsCompare();

                if (tablePeople?.Any() == true)
                {
                    using (var dbContext = new GeneratorContext())
                    {
                        using (var transaction = dbContext.Database.BeginTransaction())
                        {
                            dbContext.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[People] ON");
                            var clients    = dbContext.People.ToList();
                            var difClients = tablePeople.Except(clients, peopleComparer);
                            dbContext.AddRange(difClients);
                            dbContext.SaveChanges();
                            dbContext.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[People] OFF");
                            transaction.Commit();
                        }
                    }
                }

                if (tablePayments?.Any() == true)
                {
                    using (var context = new GeneratorContext())
                    {
                        using (var transaction = context.Database.BeginTransaction())
                        {
                            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Payments] ON");
                            var clientPayments = context.Payments.ToList();
                            var difPayments    = tablePayments.Except(clientPayments, paymentsComparer);
                            context.AddRange(difPayments);
                            context.SaveChanges();
                            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Payments] OFF");
                            transaction.Commit();
                        }
                    }
                }
            });
        }