private static void AddProductBrand(IProductCommand command, Product product)
        {
            if (command.ProductBrand.Name == null)
            {
                return;
            }

            var brand = new ProductBrand
            {
                Name         = command.ProductBrand.Name,
                CreationDate = DateTime.Now,
                Creator      = command.UserIdentity.Email
            };

            if (command.ProductBrand.IsNew)
            {
                product.ProductBrand = brand;
                //product.ProductCategory = new ProductCategory();
                //product.ProductCategory.AddBrand(brand);
            }
            else
            {
                product.Brand = command.ProductBrand.Name;
            }
        }
        private void AddProductSize(IProductCommand command, Product product)
        {
            if (command.ProductSizes == null)
            {
                return;
            }

            foreach (var item in command.ProductSizes.Where(c => c.Name != null))
            {
                var size = new ProductSize
                {
                    Name         = item.Name,
                    CreationDate = DateTime.Now,
                    Creator      = command.UserIdentity.Email
                };

                if (item.IsNew)
                {
                    product.AddSize(size);
                }
                else
                {
                    var productSize = _productRepository.GetProductSizeByValue(item.Name);
                    product.ProductSizes.Add(productSize);
                }
            }
        }
        private void AddProductAttribute(IProductCommand command, Product product)
        {
            if (command.ProductAttributes == null)
            {
                return;
            }

            foreach (var attribute in command.ProductAttributes)
            {
                if (!attribute.IsNew)
                {
                    continue;
                }

                var productAttribute = _productRepository.GetProductAttribute(attribute.AttributeId);

                product.ProductAttributes.Add(productAttribute);

                foreach (var option in attribute.AttributeOptionCommands)
                {
                    var productAttributeOption = _productRepository.GetProductAttributeOption(option.Name);
                    foreach (var item in product.ProductAttributes)
                    {
                        item.AttributeOptions.Add(productAttributeOption);
                    }
                }
            }
        }
Exemplo n.º 4
0
 private static void SetSelectedValues(IProductCommand command, ProductDto product)
 {
     SetSelectdCategory(command, product);
     SetSelectdBrand(command, product);
     SetSelectTag(command, product);
     SetSelectedAttribute(command, product);
 }
Exemplo n.º 5
0
        private void FillStores(IProductCommand command)
        {
            var query    = new StoresQueryRequest(1, 20, CurrentUser.Id);
            var response = _storeQueryService.GetStores(query);

            ViewBag.Stores = response.Stores;
        }
 private void AddProductCategory(IProductCommand command, Product product)
 {
     if (command.ProductCategory.Name == null)
     {
         return;
     }
     product.Category = command.ProductCategory.Name;
 }
Exemplo n.º 7
0
        public MainViewModel(IProductQuery productQuery, ICustomerQuery customerQuery, IProductCommand productCommand)
        {
            _ProductQuery  = productQuery;
            _CustomerQuery = customerQuery;

            _ProductCommand = productCommand;

            SetViewModel();
        }
Exemplo n.º 8
0
 public ProductService(IProductQuery productHelper,
                       IDestinationQuery destionationQueryHelper,
                       IProductCommand productCommand
                       )
 {
     this.productHelper           = productHelper;
     this.destionationQueryHelper = destionationQueryHelper;
     this.productCommand          = productCommand;
 }
 private static void AddProduct(IProductCommand command, Product product)
 {
     product.Name         = command.Name;
     product.OriginalName = command.OriginalName;
     product.Description  = command.Description;
     product.Price        = command.Price;
     product.DollarPrice  = command.DollarPrice;
     product.Slug         = command.Name.GenerateSlug();
 }
Exemplo n.º 10
0
        public MainViewModel()
        {
            _ProductQuery  = LogicFactory.ProductQuery;
            _CustomerQuery = LogicFactory.CustomerQuery;

            _ProductCommand = LogicFactory.ProductCommand;

            SetViewModel();
        }
 /// <summary>
 /// Find products from given database using given query.
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public IEnumerable <Product> Find(IProductCommand <Product, bool> query)
 {
     if (query == null)
     {
         throw new ArgumentException("Command can not be null");
     }
     else
     {
         return(this.products.Where(query.Command()));
     }
 }
Exemplo n.º 12
0
        private static void SetSelectTag(IProductCommand command, ProductDto product)
        {
            if (command.ProductTags == null)
            {
                return;
            }

            foreach (var tag in product.ProductTags.Where(c => c.Name != null))
            {
                command.ProductTags.First(c => c.Name == tag.Name).IsSelected = true;
            }
        }
Exemplo n.º 13
0
        private static void SetSelectdBrand(IProductCommand command, ProductDto product)
        {
            if (command.ProductBrand == null)
            {
                return;
            }

            if (product.ProductBrand.Name == command.ProductBrand.Name)
            {
                command.ProductBrand.IsSelected = true;
            }
        }
Exemplo n.º 14
0
        private static void SetSelectdCategory(IProductCommand command, ProductDto product)
        {
            if (command.ProductCategory == null)
            {
                return;
            }

            if (product.ProductCategory.Name == command.ProductCategory.Name)
            {
                command.ProductCategory.IsSelected = true;
            }
        }
Exemplo n.º 15
0
 private void AddProductSpecialState(IProductCommand command, Product product)
 {
     if (command.IsInSpecialState)
     {
         product.ProductSpecialState = new ProductSpecialState
         {
             StartDate   = command.ProductSpecialState.StartDate,
             EndDate     = command.ProductSpecialState.EndDate,
             Description = command.ProductSpecialState.Description
         };
     }
 }
Exemplo n.º 16
0
        private void AddProductAttributeOption(IProductCommand command, Product product)
        {
            if (command.ProductAttributeOptions == null)
            {
                return;
            }

            foreach (var item in command.ProductAttributeOptions)
            {
                var productAttributeOption = _productRepository.GetProductAttributeOption(item.Name);
                product.ProductAttributeOptions.Add(productAttributeOption);
            }
        }
Exemplo n.º 17
0
        private void AssignProductToStore(IProductCommand command, Product product)
        {
            if (command.StoreCommands == null)
            {
                throw new NoStoreHasBeenChoosenForProductException(ProductExceptionMessage.ProductStoreIsNotDeterminded);
            }

            foreach (var item in command.StoreCommands)
            {
                var store = _storeRepository.GetById(item.StoreId);
                product.Stores.Add(store);
            }
        }
Exemplo n.º 18
0
 private static void AddProductPicture(IProductCommand command, Product product)
 {
     foreach (var productPicture in command.ProductPictures.Select(item => new ProductPicture
     {
         Name = item.Name,
         Address = item.Address,
         CreationDate = DateTime.Now,
         LastUpdateDate = DateTime.Now,
     }))
     {
         product.AddPicture(productPicture);
     }
 }
Exemplo n.º 19
0
        protected bool IsRepeatedCommand(IProductCommand command, IEventStoreAggregateId eventStoreAggregateId, IProductState state)
        {
            bool repeated = false;

            if (((IProductStateProperties)state).Version > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(IProductEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
Exemplo n.º 20
0
        private static void SetSelectedAttribute(IProductCommand command, ProductDto product)
        {
            if (command.ProductAttributes == null)
            {
                return;
            }

            foreach (var attribute in product.ProductCategory.ProductAttributes.Where(c => c.Name != null))
            {
                foreach (var option in attribute.AttributeOptions)
                {
                    command.ProductAttributes.Select(c => c.AttributeOptionCommands.First(o => o.Name == option.Name).IsSelected == true);
                }
            }
        }
Exemplo n.º 21
0
 private void AddProductAppurtenance(IProductCommand command, Product product)
 {
     AddProduct(command, product);
     AddProductBrand(command, product);
     AddProductTag(command, product);
     AddProductCategory(command, product);
     AddProductColor(command, product);
     AddProductPicture(command, product);
     AddProductSize(command, product);
     AddProductAttribute(command, product);
     AddProductAttributeOption(command, product);
     AssigProductToUser(command, product);
     AssignProductToStore(command, product);
     AddProductSpecialState(command, product);
 }
Exemplo n.º 22
0
        protected virtual void Update(IProductCommand c, Action <IProductAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetProductAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

            var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state);

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            Persist(eventStoreAggregateId, aggregate, state);
        }
Exemplo n.º 23
0
        protected void ThrowOnInconsistentCommands(IProductCommand command, IGoodIdentificationCommand innerCommand)
        {
            var properties      = command as ICreateOrMergePatchOrDeleteProduct;
            var innerProperties = innerCommand as ICreateOrMergePatchOrRemoveGoodIdentification;

            if (properties == null || innerProperties == null)
            {
                return;
            }
            if (innerProperties.ProductId == default(string))
            {
                innerProperties.ProductId = properties.ProductId;
            }
            else
            {
                var outerProductIdName  = "ProductId";
                var outerProductIdValue = properties.ProductId;
                var innerProductIdName  = "ProductId";
                var innerProductIdValue = innerProperties.ProductId;
                ThrowOnInconsistentIds(innerProperties, innerProductIdName, innerProductIdValue, outerProductIdName, outerProductIdValue);
            }
        }// END ThrowOnInconsistentCommands /////////////////////
Exemplo n.º 24
0
        }// END ThrowOnInconsistentCommands /////////////////////

        protected virtual IGoodIdentificationEvent Map(IGoodIdentificationCommand c, IProductCommand outerCommand, long version, IProductState outerState)
        {
            var create = (c.CommandType == CommandType.Create) ? (c as ICreateGoodIdentification) : null;

            if (create != null)
            {
                return(MapCreate(create, outerCommand, version, outerState));
            }

            var merge = (c.CommandType == CommandType.MergePatch || c.CommandType == null) ? (c as IMergePatchGoodIdentification) : null;

            if (merge != null)
            {
                return(MapMergePatch(merge, outerCommand, version, outerState));
            }

            var remove = (c.CommandType == CommandType.Remove) ? (c as IRemoveGoodIdentification) : null;

            if (remove != null)
            {
                return(MapRemove(remove, outerCommand, version));
            }
            throw new NotSupportedException();
        }
Exemplo n.º 25
0
 public ProductRepository(IUnitOfWork unitOfWork, IProductCommand productCommand, IProductQuery productQuery) : base(unitOfWork)
 {
     _productCommand = productCommand;
     _productQuery   = productQuery;
 }
Exemplo n.º 26
0
 public ProductController(IProductQuery productQuery, IProductCommand productCommand)
 {
     this.productQuery   = productQuery;
     this.productCommand = productCommand;
 }
Exemplo n.º 27
0
        private void AssigProductToUser(IProductCommand command, Product product)
        {
            var user = _membershipRepository.GetById(command.UserIdentity.Id);

            product.Users.Add(user);
        }
Exemplo n.º 28
0
 private static bool IsCommandCreate(IProductCommand c)
 {
     return(c.Version == ProductState.VersionZero);
 }
 private static void Execute(ProductReceiver product, ModifyPriceInvoker modifyPrice, IProductCommand productCommand)
 {
     modifyPrice.SetCommand(productCommand);
     modifyPrice.Invoke();
 }
Exemplo n.º 30
0
 public MainController(int p2p_port = 8081) : base(p2p_port)
 {
     _ProductQuery   = LogicFactory.ProductQuery;
     _CustomerQuery  = LogicFactory.CustomerQuery;
     _ProductCommand = LogicFactory.ProductCommand;
 }