コード例 #1
0
ファイル: ProductService.cs プロジェクト: aunebakk/nor-pim
        /// <summary>
        /// get product and all entities
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public ProductContract ProductGetCompleteById(
            Guid productId
            )
        {
            var contract = new ProductContract();
            var data     = new Product(productId);

            // move data from data access layer to business logic layer
            contract.Product = new CrudeProductContract();
            CrudeProductService.DataToContract(data.product, contract.Product);

            contract.ProductAttribute     = CrudeProductAttributeService.DataListToContractList(data.ProductAttribute);
            contract.ProductIdentifier    = CrudeProductIdentifierService.DataListToContractList(data.ProductIdentifier);
            contract.ProductInfo          = CrudeProductInfoService.DataListToContractList(data.ProductInfo);
            contract.ProductImage         = CrudeProductImageService.DataListToContractList(data.ProductImage);
            contract.ProductDocumentation = CrudeProductDocumentationService.DataListToContractList(data.ProductDocumentation);

            // generate checksum

            return(contract);
        }
コード例 #2
0
ファイル: ProductService.cs プロジェクト: aunebakk/nor-pim
        /// <summary>
        /// save product and all entities
        /// </summary>
        /// <param name="contract"></param>
        /// <param name="userId"></param>
        /// <returns>new product id</returns>
        public Guid ProductSaveCompleteById(
            ProductContract contract,
            Guid userId
            )
        {
            // check checksum ( object has hash code )

            // move from contract to data
            var data = new Product();

            CrudeProductService.ContractToData(contract.Product, data.product);
            CrudeProductAttributeService.ContractListToDataList(contract.ProductAttribute, data.ProductAttribute);
            CrudeProductIdentifierService.ContractListToDataList(contract.ProductIdentifier, data.ProductIdentifier);
            CrudeProductInfoService.ContractListToDataList(contract.ProductInfo, data.ProductInfo);
            CrudeProductImageService.ContractListToDataList(contract.ProductImage, data.ProductImage);
            CrudeProductDocumentationService.ContractListToDataList(contract.ProductDocumentation, data.ProductDocumentation);

            // save product
            data.Save(userId);

            return(data.product.ProductId);
        }
コード例 #3
0
ファイル: ProductService.cs プロジェクト: aunebakk/nor-pim
        /// <summary>
        /// change multiple product's entities
        /// </summary>
        /// <param name="productEntities">products and entities to change</param>
        /// <param name="userId">user who initiated the change</param>
        public void ProductChangeEntities(
            List <ProductChangeEntityContract> productEntities,
            Guid userId
            )
        {
            //productEntities.Reverse();  // because of updated by sort order

            foreach (ProductChangeEntityContract productEntity in productEntities)
            {
                // get current product
                ProductContract product = ProductGetCompleteById(productEntity.ProductId);
                // check if any change was made
                bool didChange = false;
                foreach (ProductChangeEntityDetailContract entityDetail in productEntity.EntityChanges)
                {
                    switch (entityDetail.ProductEntityTypeRcd)
                    {
                    case ProductEntityTypeRef.Product: {
                        // check if current column value is the same as proposed new value
                        if (product.Product.ProductName == null || !product.Product.ProductName.Equals(entityDetail.ProductEntityNewValue))
                        {
                            // change product name
                            product.Product.ProductName = entityDetail.ProductEntityNewValue;
                            product.Product.DateTime    = DateTime.UtcNow;
                            product.Product.UserId      = userId;
                            didChange = true;
                        }
                        break;
                    }

                    case ProductEntityTypeRef.ProductAttribute: {
                        bool didFind = false;
                        foreach (CrudeProductAttributeContract attribute in product.ProductAttribute)
                        {
                            if (attribute.ProductAttributeRcd.Equals(entityDetail.ProductEntityRcd))
                            {
                                // check if current column value is the same as proposed new value
                                if (attribute.Value == null || !attribute.Value.Equals(entityDetail.ProductEntityNewValue))
                                {
                                    // change column value
                                    attribute.Value    = entityDetail.ProductEntityNewValue;
                                    attribute.DateTime = DateTime.UtcNow;
                                    attribute.UserId   = userId;
                                    didChange          = true;
                                }
                                didFind = true;
                                break;
                            }
                        }
                        if (!didFind)
                        {
                            // attribute not present, add it
                            var attribute = new CrudeProductAttributeContract();
                            attribute.ProductAttributeRcd = entityDetail.ProductEntityRcd;
                            attribute.Value    = entityDetail.ProductEntityNewValue;
                            attribute.DateTime = DateTime.UtcNow;
                            attribute.UserId   = userId;
                            product.ProductAttribute.Add(attribute);
                            didChange = true;
                        }
                        break;
                    }

                    case ProductEntityTypeRef.ProductIdentifier: {
                        bool didFind = false;
                        foreach (CrudeProductIdentifierContract identifier in product.ProductIdentifier)
                        {
                            if (identifier.ProductIdentifierRcd.Equals(entityDetail.ProductEntityRcd))
                            {
                                // check if current column value is the same as proposed new value
                                if (identifier.Identifier == null || !identifier.Identifier.Equals(entityDetail.ProductEntityNewValue))
                                {
                                    // change column value
                                    identifier.Identifier = entityDetail.ProductEntityNewValue;
                                    identifier.DateTime   = DateTime.UtcNow;
                                    identifier.UserId     = userId;
                                    didChange             = true;
                                }
                                didFind = true;
                            }
                        }
                        if (!didFind)
                        {
                            // identifier not present, add it
                            var identifier = new CrudeProductIdentifierContract();
                            identifier.ProductIdentifierRcd = entityDetail.ProductEntityRcd;
                            identifier.Identifier           = entityDetail.ProductEntityNewValue;
                            identifier.DateTime             = DateTime.UtcNow;
                            identifier.UserId = userId;
                            product.ProductIdentifier.Add(identifier);
                            didChange = true;
                        }
                        break;
                    }
                    }
                }

                // save if any change was made
                if (didChange)
                {
                    ProductSaveCompleteById(product, userId);
                }
            }
        }
コード例 #4
0
ファイル: ProductService.cs プロジェクト: aunebakk/nor-pim
        /// <summary>
        /// change attributes on a series of products
        /// check if current column value is what it was when displayed, if not; change column value and save history
        /// </summary>
        /// <param name="productIds">List if product's to change</param>
        /// <param name="productIdentifierRcd">identifier type</param>
        /// <param name="newIdentifierValue">new identifier</param>
        /// <param name="productAttributeRcd">attribute type</param>
        /// <param name="newAttributeValue">attribute value</param>
        /// <param name="userId">user who initiated the change</param>
        public void ProductChangeAttribute(
            List <Guid> productIds,
            string productAttributeRcd,
            string newAttributeValue,
            string productIdentifierRcd,
            string newIdentifierValue,
            Guid userId
            )
        {
            if (productIds.Count.Equals(0))
            {
                throw new Exception("ProductService, ProductChangeAttribute, no products");
            }

            foreach (Guid productId in productIds)
            {
                // get current product
                ProductContract product = ProductGetCompleteById(productId);

                if (product.Product.ProductId.Equals(Guid.Empty))
                {
                    throw new Exception("ProductService, ProductChangeAttribute, product: " + productId + " not found");
                }

                // check if any change was made
                bool didChange = false;
                bool didFind   = false;

                // check attributes
                foreach (CrudeProductAttributeContract attribute in product.ProductAttribute)
                {
                    if (attribute.ProductAttributeRcd.Equals(productAttributeRcd))
                    {
                        // check if current column value is the same as proposed new value
                        if (!attribute.Value.Equals(newAttributeValue))
                        {
                            // change column value
                            attribute.Value    = newAttributeValue;
                            attribute.DateTime = DateTime.UtcNow;
                            attribute.UserId   = userId;
                            didChange          = true;
                        }
                        didFind = true;
                    }
                }

                if (!didFind)
                {
                    // attribute not present, add it
                    var attribute = new CrudeProductAttributeContract();

                    attribute.ProductAttributeRcd = productAttributeRcd;
                    attribute.Value    = newAttributeValue;
                    attribute.DateTime = DateTime.UtcNow;
                    attribute.UserId   = userId;

                    product.ProductAttribute.Add(attribute);
                }

                // check identifiers
                foreach (CrudeProductIdentifierContract identifier in product.ProductIdentifier)
                {
                    if (identifier.ProductIdentifierRcd.Equals(productIdentifierRcd))
                    {
                        // check if current column value is the same as proposed new value
                        if (!identifier.Identifier.Equals(newIdentifierValue))
                        {
                            // change column value
                            identifier.Identifier = newIdentifierValue;
                            identifier.DateTime   = DateTime.UtcNow;
                            identifier.UserId     = userId;

                            didChange = true;
                        }
                    }
                }

                // save if any change was made
                if (didChange)
                {
                    ProductSaveCompleteById(product, userId);
                }
            }
        }