// update all object members on a row in table based on primary key
        // links:
        //  docLink: http://sql2x.org/documentationLink/ce75e72e-fb16-4f4e-a2e6-dbd079dfa206
        public void Update(CrudeProductAttributeContract contract)
        {
            var data = new CrudeProductAttributeData();

            ContractToData(contract, data);
            data.Update();
        }
        // update all object members on a row in table based on primary key, on a transaction
        // the transaction and or connection state is not changed in any way other than what SqlClient does to it.
        // it is the callers responsibility to commit or rollback the transaction
        // links:
        //  docLink: http://sql2x.org/documentationLink/b798ad6b-f4b8-466a-9086-6588a814fcf3
        public void Update(CrudeProductAttributeContract contract, SqlConnection connection, SqlTransaction transaction)
        {
            var data = new CrudeProductAttributeData();

            ContractToData(contract, data);
            data.Update(connection, transaction);
        }
        // insert all object members as a new row in table
        // links:
        //  docLink: http://sql2x.org/documentationLink/75aad010-e6aa-4f19-a6e5-597456aa20d8
        public void Insert(CrudeProductAttributeContract contract)
        {
            var data = new CrudeProductAttributeData();

            ContractToData(contract, data);
            data.Insert();
        }
        // fetch by Primary key into current object
        // links:
        //  docLink: http://sql2x.org/documentationLink/bbab4791-c9e7-49bf-90d5-fca19b1fedaa
        // parameters:
        //  productAttributeId: primary key of table product_attribute
        public CrudeProductAttributeContract FetchByProductAttributeId(System.Guid productAttributeId)
        {
            var dataAccessLayer = new CrudeProductAttributeData();
            var contract        = new CrudeProductAttributeContract();

            dataAccessLayer.FetchByProductAttributeId(productAttributeId);
            DataToContract(dataAccessLayer, contract);

            return(contract);
        }
 // copy all columns from a serialized data object to a SOAP Contract
 // links:
 //  docLink: http://sql2x.org/documentationLink/7553d6dd-da65-4a72-84c8-81f2f99ef4f5
 public static void DataToContract(CrudeProductAttributeData data, CrudeProductAttributeContract contract)
 {
     contract.ProductAttributeId      = data.ProductAttributeId;
     contract.ProductId               = data.ProductId;
     contract.ProductAttributeRcd     = data.ProductAttributeRcd;
     contract.ProductAttributeUnitRcd = data.ProductAttributeUnitRcd;
     contract.Value    = data.Value;
     contract.UserId   = data.UserId;
     contract.DateTime = data.DateTime;
 }
 // copy all columns from a SOAP Contract to a serialized data object
 // links:
 //  docLink: http://sql2x.org/documentationLink/10700d38-2227-4021-be12-2f4f206f5dd9
 public static void ContractToData(CrudeProductAttributeContract contract, CrudeProductAttributeData data)
 {
     data.ProductAttributeId      = contract.ProductAttributeId;
     data.ProductId               = contract.ProductId;
     data.ProductAttributeRcd     = contract.ProductAttributeRcd;
     data.ProductAttributeUnitRcd = contract.ProductAttributeUnitRcd;
     data.Value    = contract.Value;
     data.UserId   = contract.UserId;
     data.DateTime = contract.DateTime;
 }
        // copy all rows from a List of serialized data objects to a List of SOAP Contracts
        // links:
        //  docLink: http://sql2x.org/documentationLink/7467f97d-14e5-4ccf-9282-ef8df4f63088
        public static List <CrudeProductAttributeContract> DataListToContractList(List <CrudeProductAttributeData> dataList)
        {
            var contractList = new List <CrudeProductAttributeContract>();

            foreach (CrudeProductAttributeData data in dataList)
            {
                var contract = new CrudeProductAttributeContract();
                DataToContract(data, contract);
                contractList.Add(contract);
            }

            return(contractList);
        }
        // copy all rows from a List of serialized data objects to a List of SOAP Contracts,
        //  with a limit on number of returned rows and order by columns, starting at a specific row
        // links:
        //  docLink: http://sql2x.org/documentationLink/3fe9f1b3-97b6-4f58-a0f2-adfcbd973bfc
        public List <CrudeProductAttributeContract> FetchAllWithLimitAndOffset(int limit, int offset)
        {
            var list = new List <CrudeProductAttributeContract>();
            List <CrudeProductAttributeData> dataList = CrudeProductAttributeData.FetchAllWithLimitAndOffset(limit, offset);

            foreach (CrudeProductAttributeData crudeProductAttribute in dataList)
            {
                var contract = new CrudeProductAttributeContract();
                DataToContract(crudeProductAttribute, contract);
                list.Add(contract);
            }

            return(list);
        }
        // copy all rows from a List of serialized data objects in CrudeProductAttributeData to a List of SOAP Contracts
        // links:
        //  docLink: http://sql2x.org/documentationLink/9204c68e-93b8-4c77-af3c-3181985ff75f
        public List <CrudeProductAttributeContract> FetchAll()
        {
            var list = new List <CrudeProductAttributeContract>();
            List <CrudeProductAttributeData> dataList = CrudeProductAttributeData.FetchAll();

            foreach (CrudeProductAttributeData crudeProductAttribute in dataList)
            {
                var contract = new CrudeProductAttributeContract();
                DataToContract(crudeProductAttribute, contract);
                list.Add(contract);
            }

            return(list);
        }
        // fetch all rows from table into new List of Contracts, filtered by any column
        // links:
        //  docLink: http://sql2x.org/documentationLink/ce01ef4a-5cd0-4e51-b211-9c0a15b791a0
        public List <CrudeProductAttributeContract> FetchWithFilter(System.Guid productAttributeId, System.Guid productId, string productAttributeRcd, string productAttributeUnitRcd, string value, System.Guid userId, System.DateTime dateTime)
        {
            var list = new List <CrudeProductAttributeContract>();
            List <CrudeProductAttributeData> dataList = CrudeProductAttributeData.FetchWithFilter(
                productAttributeId: productAttributeId,
                productId: productId,
                productAttributeRcd: productAttributeRcd,
                productAttributeUnitRcd: productAttributeUnitRcd,
                value: value,
                userId: userId,
                dateTime: dateTime
                );

            foreach (CrudeProductAttributeData data in dataList)
            {
                var crudeProductAttributeContract = new CrudeProductAttributeContract();
                DataToContract(data, crudeProductAttributeContract);
                list.Add(crudeProductAttributeContract);
            }

            return(list);
        }
Exemplo n.º 11
0
        /// <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);
                }
            }
        }
Exemplo n.º 12
0
        /// <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);
                }
            }
        }