Esempio n. 1
0
        // Gets parent and children
        // getter for service
        // links:
        //  docLink: http://sql2x.org/documentationLink/28672bb5-d65f-4daa-84f5-56d7bfad4b22
        public ProductReferenceCategoryDocumentationTypeContract ProductReferenceCategoryDocumentationTypeCompleteGet(string productCategoryDocumentationTypeRcd, System.Guid userId)
        {
            var productContract =
                new ProductReferenceCategoryDocumentationTypeContract();

            // open standard connection
            using (var connection = new SqlConnection(ConfigurationManager.AppSettings["Conn"])) {
                connection.Open();

                try {
                    productContract.ProductCategoryDocumentationTypeRef =
                        new CrudeProductCategoryDocumentationTypeRefService().FetchAll();

                    // save checksum for comparison on update
                    productContract.ChecksumAfterGet = productContract.Checksum();
                } catch (Exception ex) {
                    throw new Exception("Failed to get Parent/Child ProductCategoryDocumentationTypeRef", ex);
                }
            }

            return(productContract);
        }
Esempio n. 2
0
        // Updates parent, children are added or updated as needed
        // updater for service
        // links:
        //  docLink: http://sql2x.org/documentationLink/b1aacc4e-64a1-4147-8b95-3a76ab53cf0c
        public string ProductReferenceCategoryDocumentationTypeCompleteUpdate(string productCategoryDocumentationTypeRcd, ProductReferenceCategoryDocumentationTypeContract productContract, System.Guid userId)
        {
            // check for differences since fetch
            if (productContract.ChecksumAfterGet.Equals(productContract.Checksum()))
            {
                return(String.Empty);
            }

            // check for database differences since fetch
            ProductReferenceCategoryDocumentationTypeContract productContractCurrent = ProductReferenceCategoryDocumentationTypeCompleteGet(productCategoryDocumentationTypeRcd, userId);

            if (!productContract.ChecksumAfterGet.Equals(productContractCurrent.Checksum()))
            {
                throw new Exception("ProductReferenceCategoryDocumentationTypeCompleteUpdate, data has changed since fetch");
            }

            // open standard connection
            using (var connection = new SqlConnection(ConfigurationManager.AppSettings["Conn"])) {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction();

                try {
                    // update parent product category documentation type ref
                    foreach (CrudeProductCategoryDocumentationTypeRefContract productCategoryDocumentationTypeRef in productContract.ProductCategoryDocumentationTypeRef)
                    {
                        new CrudeProductCategoryDocumentationTypeRefService().Update(productCategoryDocumentationTypeRef, connection, transaction);
                    }

                    transaction.Commit();
                } catch (Exception ex) {
                    transaction.Rollback();
                    throw new Exception("Failed to update Parent/Child ProductCategoryDocumentationTypeRef", ex);
                }
            }

            return(String.Empty);
        }