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

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

                try {
                    cartProductContract.CartProduct =
                        new CrudeCartProductService().FetchAll();

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

            return(cartProductContract);
        }
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 System.Guid CartProductCompleteUpdate(System.Guid cartProductId, CartProductContract cartProductContract, System.Guid userId)
        {
            // check for differences since fetch
            if (cartProductContract.ChecksumAfterGet.Equals(cartProductContract.Checksum()))
            {
                return(Guid.Empty);
            }

            // check for database differences since fetch
            CartProductContract cartProductContractCurrent = CartProductCompleteGet(cartProductId, userId);

            if (!cartProductContract.ChecksumAfterGet.Equals(cartProductContractCurrent.Checksum()))
            {
                throw new Exception("CartProductCompleteUpdate, 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 cart product
                    foreach (CrudeCartProductContract cartProduct in cartProductContract.CartProduct)
                    {
                        new CrudeCartProductService().Update(cartProduct, connection, transaction);
                    }

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

            return(Guid.Empty);
        }