private static void SyncBrokers(HttpClient httpClient, IRepository consoleRepository)
		{
			DatabaseInit._LogHandler.WriteLog("SyncBrokers()", LogSeverity.Information, LogCategory.DataAccess);

			var response = httpClient.GetAsync("rest/api/broker").Result;

			if (response.IsSuccessStatusCode)
			{
				var serviceBrokers = response.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.Broker>>().Result;

				foreach (var serviceBroker in serviceBrokers)
				{
					if (!consoleRepository.Query<Broker>().Any(cb => cb.BrokerSequenceId == serviceBroker.Id))
					{
						consoleRepository.Add(new Broker
						{
							BrokerSequenceId = serviceBroker.Id,
							Name = serviceBroker.Name,
							Code = serviceBroker.Code,
							Psu = serviceBroker.Psu,
							GroupCode = serviceBroker.GrpCd
						});
					}
					else
					{
						var consoleBroker = consoleRepository.Query<Broker>()
						                                     .FirstOrDefault(cb => cb.BrokerSequenceId == serviceBroker.Id);

						if (consoleBroker != null)
						{
							consoleBroker.Code = serviceBroker.Code;
							consoleBroker.GroupCode = serviceBroker.GrpCd;
							consoleBroker.Name = serviceBroker.Name;
							consoleBroker.Psu = serviceBroker.Psu;

							consoleRepository.Attach(consoleBroker);
						}
					}
				}
			}
			else
			{
				DatabaseInit._LogHandler.WriteLog("Get rest/api/broker failed", LogSeverity.Warning, LogCategory.DataAccess);
			}
		}
 public void Update(BusinessObjects.Model entity)
 {
     using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>())
     {
         entity.LastModifiedDate = DateTime.Now;
         //
         _ModelRepository.Attach((DAL.DataEntities.Model)entity.InnerEntity);
         _ModelRepository.SaveChanges();
     }
 }
 public void Update(BusinessObjects.Attribute entity)
 {
     using (_AttributeRepository = new GenericRepository<DAL.DataEntities.Attribute>())
     {
         //Update the Attribute
         _AttributeRepository.Attach((DAL.DataEntities.Attribute)entity.InnerEntity);
         _AttributeRepository.SaveChanges();
     }
 }
 public void Update(BusinessObjects.CustomRule entity)
 {
     using (_CustomRuleRepository = new GenericRepository<DAL.DataEntities.CustomRule>())
     {
         //
         _CustomRuleRepository.Attach((DAL.DataEntities.CustomRule)entity.InnerEntity);
         _CustomRuleRepository.SaveChanges();
     }
 }
 public void Update(BusinessObjects.Relation entity)
 {
     using (_RelationRepository = new GenericRepository<DAL.DataEntities.Relation>())
     {
         //
         _RelationRepository.Attach((DAL.DataEntities.Relation)entity.InnerEntity);
         _RelationRepository.SaveChanges();
     }
 }
 public void Update(BusinessObjects.Feature entity)
 {
     using (_FeatureRepository = new GenericRepository<DAL.DataEntities.Feature>())
     {
         //Update the Feature
         _FeatureRepository.Attach((DAL.DataEntities.Feature)entity.InnerEntity);
         _FeatureRepository.SaveChanges();
     }
 }
 public void Update(BusinessObjects.Configuration entity)
 {
     using (_ConfigurationRepository = new GenericRepository<DAL.DataEntities.Configuration>())
     {
         entity.LastModifiedDate = DateTime.Now;
         //
         _ConfigurationRepository.Attach((DAL.DataEntities.Configuration)entity.InnerEntity);
         _ConfigurationRepository.SaveChanges();
     }
 }
		private static void SyncRiskCodes(HttpClient httpClient, IRepository consoleRepository)
		{
			DatabaseInit._LogHandler.WriteLog("SyncRiskCodes()", LogSeverity.Information, LogCategory.DataAccess);

			var response = httpClient.GetAsync("rest/api/riskcode").Result;

			if (response.IsSuccessStatusCode)
			{
				var serviceRisks = response.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.RiskCode>>().Result;

				foreach (var serviceRisk in serviceRisks)
				{
					if (!consoleRepository.Query<RiskCode>()
					                      .Any(crc => crc.Code == serviceRisk.Code))
					{
						consoleRepository.Add(new RiskCode
						{
							Code = serviceRisk.Code,
							Name = serviceRisk.Name
						});
					}
					else
					{
						var consoleRisk = consoleRepository.Query<RiskCode>()
						                                   .FirstOrDefault(crc => crc.Code == serviceRisk.Code);

						if (consoleRisk != null)
						{
							consoleRisk.Code = serviceRisk.Code;
							consoleRisk.Name = serviceRisk.Name;

							consoleRepository.Attach(consoleRisk);
						}
					}
				}
			}
			else
			{
				DatabaseInit._LogHandler.WriteLog("Get rest/api/riskcode failed", LogSeverity.Warning, LogCategory.DataAccess);
			}
		}
		private static void SyncUnderwriters(HttpClient httpClient, IRepository consoleRepository)
		{
			DatabaseInit._LogHandler.WriteLog("SyncUnderwriters()", LogSeverity.Information, LogCategory.DataAccess);

			var response = httpClient.GetAsync("rest/api/underwriter").Result;

			if (response.IsSuccessStatusCode)
			{
				var serviceUnderwriters = response.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.Underwriter>>().Result;

				foreach (var serviceUnderwriter in serviceUnderwriters)
				{
					if (!consoleRepository.Query<Underwriter>().Any(cu => cu.Code == serviceUnderwriter.Code))
					{
						consoleRepository.Add(new Underwriter
						{
							Code = serviceUnderwriter.Code,
							Name = serviceUnderwriter.Name
						});
					}
					else
					{
						var consoleUnderwriter = consoleRepository.Query<Underwriter>()
						                                          .FirstOrDefault(b => b.Code == serviceUnderwriter.Code);

						if (consoleUnderwriter != null)
						{
							consoleUnderwriter.Code = serviceUnderwriter.Code;
							consoleUnderwriter.Name = serviceUnderwriter.Name;

							consoleRepository.Attach(consoleUnderwriter);
						}
					}
				}
			}
			else
			{
				DatabaseInit._LogHandler.WriteLog("Get rest/api/underwriter failed", LogSeverity.Warning, LogCategory.DataAccess);
			}
		}
		private static void SyncNonLondonBrokers(HttpClient httpClient, IRepository consoleRepository)
		{
            DatabaseInit._LogHandler.WriteLog("SyncNonLondonBrokers()", LogSeverity.Information, LogCategory.DataAccess);

			var responseOffices = httpClient.GetAsync("rest/api/office").Result;

		    if (responseOffices.IsSuccessStatusCode)
		    {
		        var serviceOffices = responseOffices.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.Office>>().Result;

		        foreach (var serviceOffice in serviceOffices)
		        {
                    DatabaseInit._LogHandler.WriteLog("SyncNonLondonBrokers()_" + serviceOffice.Code, LogSeverity.Information, LogCategory.DataAccess);

                    var responseNonLondonBroker = httpClient.GetAsync("rest/api/NonLondonBroker?office=" + serviceOffice.Code).Result;

                    if (responseNonLondonBroker.IsSuccessStatusCode)
                    {
                        var serviceNonLondonBrokers = responseNonLondonBroker.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.NonLondonBroker>>().Result;

                        foreach (var serviceNonLondonBroker in serviceNonLondonBrokers)
                        {
                            if (serviceNonLondonBroker.Code == "NA") continue;
                            if (!consoleRepository.Query<NonLondonBroker>().Any(cb => cb.Code == serviceNonLondonBroker.Code))
                            {
                                consoleRepository.Add(new NonLondonBroker
                                {
                                    Name = serviceNonLondonBroker.Name,
                                    Code = serviceNonLondonBroker.Code,
                                });
                            }
                            else
                            {
                                var consoleNonLondonBroker = consoleRepository.Query<NonLondonBroker>()
                                                                     .FirstOrDefault(cb => cb.Code == serviceNonLondonBroker.Code);

                                if (consoleNonLondonBroker != null)
                                {
                                    consoleNonLondonBroker.Code = serviceNonLondonBroker.Code;
                                    consoleNonLondonBroker.Name = serviceNonLondonBroker.Name;

                                    consoleRepository.Attach(consoleNonLondonBroker);
                                }
                            }
                        }
                    }
                    else
                    {
                        DatabaseInit._LogHandler.WriteLog("Get rest/api/NonLondonBroker failed_" + serviceOffice.Code, LogSeverity.Warning, LogCategory.DataAccess);
                    } 
		        }

                if (!consoleRepository.Query<NonLondonBroker>().Any(cb => cb.Code == "NA"))
                {
                    consoleRepository.Add(new NonLondonBroker
                    {
                        Name = "Not Applicable",
                        Code = "NA",
                    });
                }


		    }
            else
            {
                DatabaseInit._LogHandler.WriteLog("Get rest/api/NonLondonBroker failed", LogSeverity.Warning, LogCategory.DataAccess);
            } 
		  
                
            
		}
 public void Update(BusinessObjects.Constraint entity)
 {
     using (_ConstraintRepository = new GenericRepository<DAL.DataEntities.Constraint>())
     {
         //
         _ConstraintRepository.Attach((DAL.DataEntities.Constraint)entity.InnerEntity);
         _ConstraintRepository.SaveChanges();
     }
 }
        public void Update(BLL.BusinessObjects.UITemplate entity)
        {
            using (_UITemplateRepository = new GenericRepository<DAL.DataEntities.UITemplate>())
            {
                entity.LastModifiedDate = DateTime.Now;

                //
                _UITemplateRepository.Attach((DAL.DataEntities.UITemplate)entity.InnerEntity);
                _UITemplateRepository.SaveChanges();
            }
        }
        public void Update(BusinessObjects.FeatureSelection entity)
        {
            using (_FeatureSelectionRepository = new GenericRepository<DAL.DataEntities.FeatureSelection>())
            {
                //Update the FeatureSelection
                _FeatureSelectionRepository.Attach((DAL.DataEntities.FeatureSelection)entity.InnerEntity);
                _FeatureSelectionRepository.SaveChanges();

                //Update AttributeValues
                using (_AttributeValuesRepository = new GenericRepository<DAL.DataEntities.AttributeValue>())
                {
                    for (int i = entity.AttributeValues.Count - 1; i >= 0; i--)
                    {
                        BLL.BusinessObjects.AttributeValue BLLAttributeValue = entity.AttributeValues[i];
                        BLLAttributeValue.FeatureSelectionID = entity.ID;

                        //Add
                        if (BLLAttributeValue.ToBeDeleted == false && BLLAttributeValue.ID == 0)
                        {
                            _AttributeValuesRepository.Add((DAL.DataEntities.AttributeValue)BLLAttributeValue.InnerEntity);
                        }
                        //Update
                        else if (BLLAttributeValue.ToBeDeleted == false && BLLAttributeValue.ID != 0)
                        {
                            _AttributeValuesRepository.Attach((DAL.DataEntities.AttributeValue)BLLAttributeValue.InnerEntity);
                        }

                    }
                    _AttributeValuesRepository.SaveChanges();
                }
            }
        }