Пример #1
0
  public void Create(coreModel.CatalogProduct[] items)
  {
      var pkMap = new PrimaryKeyResolvingMap();
      using (var repository = _catalogRepositoryFactory())
      {
          foreach (var item in items)
          {
              var dbItem = item.ToDataModel(pkMap);
              repository.Add(dbItem);
              if (item.Variations != null)
              {
                  foreach (var variation in item.Variations)
                  {
                      variation.MainProductId = dbItem.Id;
                      variation.CatalogId = dbItem.CatalogId;
                      var dbVariation = variation.ToDataModel(pkMap);
                      repository.Add(dbVariation);
                  }
              }
          }
          CommitChanges(repository);
          pkMap.ResolvePrimaryKeys();
      }
 
      //Update SEO 
      var itemsWithVariations = items.Concat(items.Where(x => x.Variations != null).SelectMany(x => x.Variations)).ToArray();
      _commerceService.UpsertSeoForObjects(itemsWithVariations);
  }
Пример #2
0
        public void Update(coreModel.Contact[] contacts)
        {
            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = _repositoryFactory())
            using (var changeTracker = GetChangeTracker(repository))
            {
                foreach (var contact in contacts)
                {
                    var targetEntity = repository.GetContactById(contact.Id);
                    if (targetEntity != null)
                    {
                        changeTracker.Attach(targetEntity);

                        var sourceEntity = contact.ToDataModel(pkMap);
                        sourceEntity.Patch(targetEntity);

                        _dynamicPropertyService.SaveDynamicPropertyValues(contact);
                    }
                }

                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }
        }
        public void Update(coreModel.Organization[] organizations)
        {
            var pkMap = new PrimaryKeyResolvingMap();
            using (var repository = _repositoryFactory())
            using (var changeTracker = GetChangeTracker(repository))
            {
                foreach (var organization in organizations)
                {
                    var sourceEntity = organization.ToDataModel(pkMap);
                    var targetEntity = repository.GetOrganizationById(organization.Id);

                    if (targetEntity == null)
                    {
                        throw new NullReferenceException("targetEntity");
                    }

                    changeTracker.Attach(targetEntity);
                    sourceEntity.Patch(targetEntity);
                }

                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }

            foreach (var organization in organizations)
            {
                _dynamicPropertyService.SaveDynamicPropertyValues(organization);
            }
        }
Пример #4
0
		public coreModel.Catalog Create(coreModel.Catalog catalog)
        {
            var pkMap = new PrimaryKeyResolvingMap();
            var dbCatalog = catalog.ToDataModel(pkMap);
			coreModel.Catalog retVal = null;
			using (var repository = _catalogRepositoryFactory())
			{
				repository.Add(dbCatalog);
				CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }
			retVal = GetById(dbCatalog.Id);
			return retVal;
		}
        public coreModel.Organization Create(coreModel.Organization organization)
        {
            var pkMap = new PrimaryKeyResolvingMap();
            var entity = organization.ToDataModel(pkMap);

            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }

            _dynamicPropertyService.SaveDynamicPropertyValues(organization);

            var retVal = GetById(entity.Id);
            return retVal;
        }
        public coreModel.DynamicContentItem CreateContent(coreModel.DynamicContentItem content)
        {
            var pkMap = new PrimaryKeyResolvingMap();
            var entity = content.ToDataModel(pkMap);

            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }

            _dynamicPropertyService.SaveDynamicPropertyValues(content);

            var retVal = GetContentItemById(entity.Id);
            return retVal;
        }
		public ShoppingCart Create(ShoppingCart cart)
		{
            var pkMap = new PrimaryKeyResolvingMap();
            //Do business logic on temporary  order object
            _eventPublisher.Publish(new CartChangeEvent(Platform.Core.Common.EntryState.Added, null, cart));

			var entity = cart.ToDataModel(pkMap);
			ShoppingCart retVal = null;
			using (var repository = _repositoryFactory())
			{
				repository.Add(entity);
				CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }

            retVal = GetById(entity.Id);
			return retVal;
		}
Пример #8
0
        public coreModel.Category Create(coreModel.Category category)
        {
            if (category == null)
                throw new ArgumentNullException("category");

            var pkMap = new PrimaryKeyResolvingMap();
            var dbCategory = category.ToDataModel(pkMap);
            
            using (var repository = _catalogRepositoryFactory())
            {	
                repository.Add(dbCategory);
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }
            //Need add seo separately
            _commerceService.UpsertSeoForObjects(new[] { category });
            return GetById(dbCategory.Id, Domain.Catalog.Model.CategoryResponseGroup.Info);
        }
        public void Create(coreModel.Category[] categories)
        {
            if (categories == null)
                throw new ArgumentNullException("categories");

            var pkMap = new PrimaryKeyResolvingMap();
            var dbCategories = categories.Select(x => x.ToDataModel(pkMap));

            using (var repository = _catalogRepositoryFactory())
            {
                foreach (var dbCategory in dbCategories)
                {
                    repository.Add(dbCategory);
                }
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }
            //Need add seo separately
            _commerceService.UpsertSeoForObjects(categories);         
        }
Пример #10
0
        public virtual CustomerOrder Create(CustomerOrder order)
        {
            EnsureThatAllOperationsHaveNumber(order);

            _eventPublisher.Publish(new OrderChangeEvent(EntryState.Added, order, order));
            var pkMap = new PrimaryKeyResolvingMap();
            var entity = order.ToDataModel(pkMap);

            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }

            _dynamicPropertyService.SaveDynamicPropertyValues(order);

            var retVal = GetById(entity.Id, CustomerOrderResponseGroup.Full);
            return retVal;
        }
Пример #11
0
        public void CreateOrUpdate(Member[] members)
        {
            var pkMap = new PrimaryKeyResolvingMap();
            using (var repository = _repositoryFactory())
            using (var changeTracker = GetChangeTracker(repository))
            {
                var dbExistsMembers = repository.GetMembersByIds(members.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray());
                foreach (var member in members)
                {
                    var dbChangedMember = ConvertToDataMember(member, pkMap);
                    var dbExistMember = dbExistsMembers.FirstOrDefault(x => x.Id == member.Id);
                    if (dbExistMember != null)
                    {
                        changeTracker.Attach(dbExistMember);
                        if (dbChangedMember is dataModel.Contact)
                        {
                            ((dataModel.Contact)dbChangedMember).Patch((dataModel.Contact)dbExistMember);
                        }
                        if (dbChangedMember is dataModel.Organization)
                        {
                            ((dataModel.Organization)dbChangedMember).Patch((dataModel.Organization)dbExistMember);
                        }
                    }
                    else
                    {
                        repository.Add(dbChangedMember);
                    }
                }
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();

                foreach (var member in members)
                {
                    _dynamicPropertyService.SaveDynamicPropertyValues(member);
                }
            }
        }
Пример #12
0
		public void Update(coreModel.Catalog[] catalogs)
		{
            var pkMap = new PrimaryKeyResolvingMap();
            using (var repository = _catalogRepositoryFactory())
			using (var changeTracker = base.GetChangeTracker(repository))
			{
				foreach (var catalog in catalogs)
				{
					var dbCatalog = repository.GetCatalogById(catalog.Id);
					if (dbCatalog == null)
					{
						throw new NullReferenceException("dbCatalog");
					}
					var dbCatalogChanged = catalog.ToDataModel(pkMap);

					changeTracker.Attach(dbCatalog);
					dbCatalogChanged.Patch(dbCatalog);
	
				}

				CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
			}
		}
        public void Update(CustomerOrder[] orders)
        {
            var pkMap = new PrimaryKeyResolvingMap();
            using (var repository = _repositoryFactory())
            {
                foreach (var order in orders)
                {
                    EnsureThatAllOperationsHaveNumber(order);
                    var origOrder = GetById(order.Id, CustomerOrderResponseGroup.Full);

                    // Do business logic on temporary order object
                    _eventPublisher.Publish(new OrderChangeEvent(EntryState.Modified, origOrder, order));

                    var sourceOrderEntity = order.ToDataModel(pkMap);
                    var targetOrderEntity = repository.GetCustomerOrderById(order.Id, CustomerOrderResponseGroup.Full);

                    if (targetOrderEntity == null)
                    {
                        throw new NullReferenceException("targetOrderEntity");
                    }

                    using (var changeTracker = GetChangeTracker(repository))
                    {
                        changeTracker.Attach(targetOrderEntity);
                        sourceOrderEntity.Patch(targetOrderEntity);
                    }
                }
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }

            //Save dynamic properties
            foreach (var order in orders)
            {
                _dynamicPropertyService.SaveDynamicPropertyValues(order);
            }
        }
        public void Update(coreModel.Category[] categories)
        {
            var pkMap = new PrimaryKeyResolvingMap();
            using (var repository = _catalogRepositoryFactory())
            using (var changeTracker = base.GetChangeTracker(repository))
            {
                foreach (var category in categories)
                {
                    var dbCategory = repository.GetCategoriesByIds(new[] { category.Id }, Domain.Catalog.Model.CategoryResponseGroup.Full).FirstOrDefault();

                    if (dbCategory == null)
                    {
                        throw new NullReferenceException("dbCategory");
                    }
                    changeTracker.Attach(dbCategory);

                    category.Patch(dbCategory, pkMap);
                }
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }
            //Update seo
            _commerceService.UpsertSeoForObjects(categories);
        }
		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;
			}
		}
		public void Update(ShoppingCart[] carts)
		{
			var changedCarts = new List<ShoppingCart>();
            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = _repositoryFactory())
			using (var changeTracker = base.GetChangeTracker(repository))
			{
				foreach (var changedCart in carts)
				{
					var origCart = GetById(changedCart.Id);

                    var productIds = changedCart.Items.Select(x => x.ProductId).ToArray();
                    var products = _productService.GetByIds(productIds, Domain.Catalog.Model.ItemResponseGroup.ItemInfo);
                    foreach (var lineItem in changedCart.Items)
                    {
                        var product = products.FirstOrDefault(x => x.Id == lineItem.ProductId);
                        if (product != null)
                        {
                            lineItem.Product = product;
                        }
                    }

					_eventPublisher.Publish(new CartChangeEvent(Platform.Core.Common.EntryState.Modified, origCart, changedCart));

					var sourceCartEntity = changedCart.ToDataModel(pkMap);
					var targetCartEntity = repository.GetShoppingCartById(changedCart.Id);
					if (targetCartEntity == null)
					{
						throw new NullReferenceException("targetCartEntity");
					}

					changeTracker.Attach(targetCartEntity);
					sourceCartEntity.Patch(targetCartEntity);
                }
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }

            //Save dynamic properties for carts and all nested objects
            foreach(var cart in carts)
            {
                _dynamicPropertyService.SaveDynamicPropertyValues(cart);
            }
        }
Пример #17
0
        public void Update(coreModel.CatalogProduct[] items)
        {
            var pkMap = new PrimaryKeyResolvingMap();
            var now = DateTime.UtcNow;
            using (var repository = _catalogRepositoryFactory())
            using (var changeTracker = base.GetChangeTracker(repository))
            {
                var dbItems = repository.GetItemByIds(items.Select(x => x.Id).ToArray(), coreModel.ItemResponseGroup.ItemLarge);
                foreach (var dbItem in dbItems)
                {
                    var item = items.FirstOrDefault(x => x.Id == dbItem.Id);
                    if (item != null)
                    {
                        changeTracker.Attach(dbItem);

                        item.Patch(dbItem, pkMap);
                    }
                }
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }

            //Update seo for products
            _commerceService.UpsertSeoForObjects(items);

        }