Ejemplo n.º 1
0
        public virtual Store Create(Store store)
        {
            var pkMap = new PrimaryKeyResolvingMap();

            ValidateStoreProperties(store);

            var dbStore = AbstractTypeFactory <StoreEntity> .TryCreateInstance();

            dbStore = dbStore.FromModel(store, pkMap);

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

            //Need add seo separately
            _commerceService.UpsertSeoForObjects(new[] { store });

            //Deep save properties
            _dynamicPropertyService.SaveDynamicPropertyValues(store);
            //Deep save settings
            _settingManager.SaveEntitySettingsValues(store);

            var retVal = GetById(store.Id);

            return(retVal);
        }
Ejemplo n.º 2
0
        public coreModel.Store Create(coreModel.Store store)
        {
            var dbStore = store.ToDataModel();

            using (var repository = _repositoryFactory())
            {
                repository.Add(dbStore);
                CommitChanges(repository);
                store.Id = dbStore.Id;
            }

            //Need add seo separately
            _commerceService.UpsertSeoForObjects(new[] { store });

            //Deep save properties
            _dynamicPropertyService.SaveDynamicPropertyValues(store);
            //Deep save settings
            _settingManager.SaveEntitySettingsValues(store);

            //Invalidate module cache region
            _cacheManager.ClearRegion("StoreModuleRegion");

            var retVal = GetById(store.Id);

            return(retVal);
        }
Ejemplo n.º 3
0
        public coreModel.Store Create(coreModel.Store store)
        {
            var dbStore = store.ToDataModel();

            using (var repository = _repositoryFactory())
            {
                repository.Add(dbStore);
                CommitChanges(repository);
            }

            //Need add seo separately
            if (store.SeoInfos != null)
            {
                foreach (var seoInfo in store.SeoInfos)
                {
                    seoInfo.ObjectId   = dbStore.Id;
                    seoInfo.ObjectType = typeof(coreModel.Store).Name;
                    _commerceService.UpsertSeo(seoInfo);
                }
            }

            //Deep save properties
            _dynamicPropertyService.SaveDynamicPropertyValues(store);
            //Deep save settings
            _settingManager.SaveEntitySettingsValues(store);

            //Reset cache
            var cacheKey = CacheKey.Create("StoreModule", "GetById", store.Id);

            _cacheManager.Remove(cacheKey);

            var retVal = GetById(store.Id);

            return(retVal);
        }
        public coreModel.DynamicContentItem CreateContent(coreModel.DynamicContentItem content)
        {
            var entity = content.ToDataModel();

            coreModel.DynamicContentItem retVal = null;
            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);
                CommitChanges(repository);
            }

            _dynamicPropertyService.SaveDynamicPropertyValues(content);

            retVal = GetContentItemById(entity.Id);
            return(retVal);
        }
Ejemplo n.º 5
0
        public coreModel.Contact Create(coreModel.Contact contact)
        {
            var entity = contact.ToDataModel();

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

            _dynamicPropertyService.SaveDynamicPropertyValues(contact);

            var retVal = GetById(entity.Id);

            return(retVal);
        }
Ejemplo n.º 6
0
        public coreModel.Organization Create(coreModel.Organization organization)
        {
            var entity = organization.ToDataModel();

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

            _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 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));
            }
        }
Ejemplo n.º 9
0
        public virtual CustomerOrder Create(CustomerOrder order)
        {
            EnsureThatAllOperationsHaveNumber(order);

            _eventPublisher.Publish(new OrderChangeEvent(EntryState.Added, null, order));

            var orderEntity = order.ToDataModel();

            using (var repository = _repositoryFactory())
            {
                repository.Add(orderEntity);
                CommitChanges(repository);
            }

            _dynamicPropertyService.SaveDynamicPropertyValues(order);

            var retVal = GetById(orderEntity.Id, CustomerOrderResponseGroup.Full);

            return(retVal);
        }
Ejemplo n.º 10
0
        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 virtual void SaveChanges(ShoppingCart[] carts)
        {
            var pkMap         = new PrimaryKeyResolvingMap();
            var changedEvents = new List <CartChangedEvent>();

            using (var repository = _repositoryFactory())
                using (var changeTracker = GetChangeTracker(repository))
                {
                    var dataExistCarts = repository.GetShoppingCartsByIds(carts.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray());
                    foreach (var cart in carts)
                    {
                        //Calculate cart totals before save
                        _totalsCalculator.CalculateTotals(cart);

                        var originalEntity = dataExistCarts.FirstOrDefault(x => x.Id == cart.Id);
                        var originalCart   = originalEntity != null?originalEntity.ToModel(AbstractTypeFactory <ShoppingCart> .TryCreateInstance()) : cart;

                        var changingEvent = new CartChangeEvent(originalEntity == null ? EntryState.Added : EntryState.Modified, originalCart, cart);
                        _changingEventPublisher.Publish(changingEvent);
                        changedEvents.Add(new CartChangedEvent(changingEvent.ChangeState, changingEvent.OrigCart, changingEvent.ModifiedCart));

                        var modifiedEntity = AbstractTypeFactory <ShoppingCartEntity> .TryCreateInstance().FromModel(cart, pkMap);

                        if (originalEntity != null)
                        {
                            changeTracker.Attach(originalEntity);
                            modifiedEntity.Patch(originalEntity);
                        }
                        else
                        {
                            repository.Add(modifiedEntity);
                        }
                    }

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

            //Save dynamic properties
            foreach (var cart in carts)
            {
                _dynamicPropertyService.SaveDynamicPropertyValues(cart);
            }

            //Raise changed events
            foreach (var changedEvent in changedEvents)
            {
                _changedEventPublisher.Publish(changedEvent);
            }
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
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);
                    }
                }
        }
Ejemplo n.º 14
0
        public void SaveContentItems(DynamicContentItem[] items)
        {
            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = _repositoryFactory())
                using (var changeTracker = GetChangeTracker(repository))
                {
                    var existEntities = repository.GetContentItemsByIds(items.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray());
                    foreach (var item in items)
                    {
                        var sourceEntity = AbstractTypeFactory <DynamicContentItemEntity> .TryCreateInstance();

                        if (sourceEntity != null)
                        {
                            sourceEntity = sourceEntity.FromModel(item, pkMap);
                            var targetEntity = existEntities.FirstOrDefault(x => x.Id == item.Id);
                            if (targetEntity != null)
                            {
                                changeTracker.Attach(targetEntity);
                                sourceEntity.Patch(targetEntity);
                            }
                            else
                            {
                                repository.Add(sourceEntity);
                            }
                        }
                    }
                    CommitChanges(repository);
                    pkMap.ResolvePrimaryKeys();
                }

            foreach (var item in items)
            {
                _dynamicPropertyService.SaveDynamicPropertyValues(item);
            }
        }