Ejemplo n.º 1
0
        public void SyncEngagements(EnableDevEntities enableContext, UtilityContainerEntities utilityContainerContext)
        {
            _logger.Log("Running " + MethodBase.GetCurrentMethod().Name);
            var engagements          = enableContext.vwExt_Engagement.ToList();
            var enableEngagements    = _mappingService.Map <vwExt_Engagement[], Engagement[]>(engagements.ToArray()).ToList();
            var utilityEngagementIds = utilityContainerContext.Engagements.Select(c => c.ID).ToList();

            using (var transaction = utilityContainerContext.Database.BeginTransaction())
            {
                try
                {
                    utilityContainerContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Engagement] ON");
                    utilityContainerContext.AddAll(enableEngagements.Where(e => !utilityEngagementIds.Contains(e.ID)));
                    utilityContainerContext.UpdateAll(enableEngagements.Where(e => utilityEngagementIds.Contains(e.ID)));
                    utilityContainerContext.SaveChanges();
                    utilityContainerContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Engagement] OFF");
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    _logger.Log(ex);
                    transaction.Rollback();
                }
            }
        }
Ejemplo n.º 2
0
        public void SyncData()
        {
            try
            {
                AutoMapperConfiguration.Configure();
                using (var enableContext = new EnableDevEntities())
                    using (var utilityContainerContext = new UtilityContainerEntities())
                    {
                        enableContext.Configuration.AutoDetectChangesEnabled = false;
                        enableContext.Configuration.ValidateOnSaveEnabled    = false;

                        _logger.Log("Sync started");
                        //Master data
                        SyncClients(enableContext, utilityContainerContext);
                        SyncEngagementTypes(enableContext, utilityContainerContext);
                        SyncDepartments(enableContext, utilityContainerContext);
                        //SyncLocations(enableContext, utilityContainerContext);
                        //SyncResourceTypes(enableContext, utilityContainerContext);
                        SyncSkills(enableContext, utilityContainerContext);

                        // Data
                        SyncTitles(enableContext, utilityContainerContext);
                        SyncUsers(enableContext, utilityContainerContext);
                        SyncEngagements(enableContext, utilityContainerContext);
                        //SyncEngagementTaskTypes(enableContext, utilityContainerContext);
                        SyncResources(enableContext, utilityContainerContext);
                        SyncResourceHistories(enableContext, utilityContainerContext);
                        //SyncResourceSkillLevels(enableContext, utilityContainerContext);
                        SyncEngagementRoles(enableContext, utilityContainerContext);
                        //SyncCompanies(enableContext, utilityContainerContext);

                        _logger.Log("Sync finished");
                    }
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
            }
        }