Exemplo n.º 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();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void DeserializationBeforeLINQ(out List <Person> NewPeople, out List <Payment> NewPayments)
        {
            var xml_people   = new XMLDeserializator <List <Person> >();
            var xml_payments = new XMLDeserializator <List <Payment> >();

            NewPeople   = xml_people.Load(ConfigurationManager.AppSettings["BaseOfNames"]);
            NewPayments = xml_payments.Load(ConfigurationManager.AppSettings["BaseOfPayments"]);
        }
Exemplo n.º 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();
                        }
                    }
                }
            });
        }