public IEnumerable<QuoteRequest> SaveChanges(QuoteRequest[] quoteRequests)
		{
			if (quoteRequests == null)
			{
				throw new ArgumentNullException("quoteRequests");
			}
			//Need for primary key resolving
			var domainEntityMap = new List<KeyValuePair<QuoteRequest, QuoteRequestEntity>>();
			//Generate Number
			EnsureThatQuoteHasNumber(quoteRequests);

			using (var repository = _repositoryFactory())
			{
				var ids = quoteRequests.Where(x => x.Id != null).Select(x => x.Id).Distinct().ToArray();

				var origDbQuotes = repository.GetQuoteRequestByIds(ids);
				using (var changeTracker = GetChangeTracker(repository))
				{
					//Update
					foreach (var origDbQuote in origDbQuotes)
					{
						var changedQuote = quoteRequests.First(x => x.Id == origDbQuote.Id);
						// Do business logic on  quote request
						_eventPublisher.Publish(new QuoteRequestChangeEvent(EntryState.Modified, GetByIds(new[] { origDbQuote.Id }).First(), changedQuote));
                        domainEntityMap.Add(new KeyValuePair<QuoteRequest, QuoteRequestEntity>(changedQuote, origDbQuote));

                        var changedDbQuote = changedQuote.ToDataModel();
                        changeTracker.Attach(origDbQuote);
						changedDbQuote.Patch(origDbQuote);
					}

					//Create
					var newQuotes = quoteRequests.Where(x => !origDbQuotes.Any(y => y.Id == x.Id));
					foreach(var newQuote in newQuotes)
					{
                        // Do business logic on  quote request
                        _eventPublisher.Publish(new QuoteRequestChangeEvent(EntryState.Added, newQuote, newQuote));
						var newDbQuote = newQuote.ToDataModel();
						repository.Add(newDbQuote);
                        domainEntityMap.Add(new KeyValuePair<QuoteRequest, QuoteRequestEntity>(newQuote, newDbQuote));
                    }
                    repository.UnitOfWork.Commit();
				}

				//Save dynamic properties
				foreach (var pair in domainEntityMap)
				{
                    //Set key for all objects
                    pair.Key.SetObjectId(pair.Value.Id);
                    _dynamicPropertyService.SaveDynamicPropertyValues(pair.Key);
                }
                return domainEntityMap.Select(x => x.Key);
			}
		}
		public IEnumerable<QuoteRequest> SaveChanges(QuoteRequest[] quoteRequests)
		{
			if (quoteRequests == null)
			{
				throw new ArgumentNullException("quoteRequests");
			}
		
			//Generate Number
			EnsureThatQuoteHasNumber(quoteRequests);
            var pkMap = new PrimaryKeyResolvingMap();
            using (var repository = _repositoryFactory())
			{
				var ids = quoteRequests.Where(x => x.Id != null).Select(x => x.Id).Distinct().ToArray();

				var origDbQuotes = repository.GetQuoteRequestByIds(ids);
				using (var changeTracker = GetChangeTracker(repository))
				{
					//Update
					foreach (var origDbQuote in origDbQuotes)
					{
						var changedQuote = quoteRequests.First(x => x.Id == origDbQuote.Id);
						// Do business logic on  quote request
						_eventPublisher.Publish(new QuoteRequestChangeEvent(EntryState.Modified, GetByIds(new[] { origDbQuote.Id }).First(), changedQuote));
                     
                        var changedDbQuote = changedQuote.ToDataModel(pkMap);
                        changeTracker.Attach(origDbQuote);
						changedDbQuote.Patch(origDbQuote);
					}

					//Create
					var newQuotes = quoteRequests.Where(x => !origDbQuotes.Any(y => y.Id == x.Id));
					foreach(var newQuote in newQuotes)
					{
                        // Do business logic on  quote request
                        _eventPublisher.Publish(new QuoteRequestChangeEvent(EntryState.Added, newQuote, newQuote));
						var newDbQuote = newQuote.ToDataModel(pkMap);
						repository.Add(newDbQuote);
                    
                    }
                    repository.UnitOfWork.Commit();
                    //Copy generated id from dbEntities to model
                    pkMap.ResolvePrimaryKeys();
				}

				//Save dynamic properties
				foreach (var quoteRequest in quoteRequests)
				{
                    _dynamicPropertyService.SaveDynamicPropertyValues(quoteRequest);
                }
                return quoteRequests;
			}
		}