Ejemplo n.º 1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5AWSAR_CAPCfSCBO_1349 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            // Find priviges for current user
            var checkParam = new P_L5AWSSC_CUPfSCBO_1414();
            checkParam.ORD_PRC_ShoppingCartID = Parameter.ShoppingCartID;
            var checkResult = cls_Check_User_Permissions_for_ShoppingCart_Before_Order.Invoke(Connection, Transaction, checkParam, securityTicket).Result;

            if (!checkResult.HasPrivileges)
            {
                throw new Exception("User doesn't have privileges to order!");
            }

            if (checkResult.CreateApprovalShoppingCart)
            {
                // Check does user have ABDA articles
                var paramShoppingProducts = new P_L5AWSSC_GSPfSC_1650 {
                    ShoppingCartID = Parameter.ShoppingCartID
                };

                var shoppingProducts            = cls_Get_ShoppingProducts_for_ShoppingCartID.Invoke(Connection, Transaction, paramShoppingProducts, securityTicket).Result;
                var shoppingProductsForApproval = new List <CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Product>();

                foreach (var p in shoppingProducts.Products)
                {
                    if (p.Groups.Count() == 1 &&
                        p.Groups.Select(i => i.Group_GlobalPropertyMatchingID).Contains(EnumUtils.GetEnumDescription(EProductGroup.ABDA)))
                    {
                        var product = new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Product();
                        product.Load(Connection, Transaction, p.ORD_PRC_ShoppingCart_ProductID);
                        shoppingProductsForApproval.Add(product);
                    }
                }

                // Create new approval shopping cart
                if (shoppingProductsForApproval.Count > 0)
                {
                    #region Create approval shopping cart
                    // Find office for current shopping cart
                    var officeShoppingCart = CL1_ORD_PRC.ORM_ORD_PRC_Office_ShoppingCart.Query.Search(Connection, Transaction,
                                                                                                      new CL1_ORD_PRC.ORM_ORD_PRC_Office_ShoppingCart.Query
                    {
                        ORD_PRC_ShoppingCart_RefID = Parameter.ShoppingCartID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).Single();

                    // Create new shopping cart that will contain ABDA articles
                    var paramCreateShoppingCart = new P_L5AWSAR_CSC_1809();
                    paramCreateShoppingCart.IsWaitingForApproval = true;
                    paramCreateShoppingCart.OfficeID             = officeShoppingCart.CMN_STR_Office_RefID;
                    var newShoppingCartId = cls_Create_ShoppingChart_for_CurrentOffice.Invoke(Connection, Transaction, paramCreateShoppingCart, securityTicket).Result;

                    // Move products from current shopping cart to new shopping cart
                    foreach (var p in shoppingProductsForApproval)
                    {
                        p.ORD_PRC_ShoppingCart_RefID = newShoppingCartId;
                        p.Save(Connection, Transaction);
                    }
                    #endregion

                    #region Copy Comments to new shopping cart
                    // Copy comments from current cart to new cart
                    var comments = CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Note.Query.Search(Connection, Transaction,
                                                                                          new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Note.Query
                    {
                        ORD_PRC_ShoppingCart_RefID = Parameter.ShoppingCartID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    });

                    foreach (var comment in comments)
                    {
                        var memo = new CL1_CMN_BPT.ORM_CMN_BPT_Memo();
                        memo.Load(Connection, Transaction, comment.CMN_BPT_Memo_RefID);

                        var newMemo = new CL1_CMN_BPT.ORM_CMN_BPT_Memo();
                        newMemo.CreatedBy_Account_RefID       = memo.CreatedBy_Account_RefID;
                        newMemo.DocumentStructureHeader_RefID = memo.DocumentStructureHeader_RefID;
                        newMemo.Memo_Abbreviation             = memo.Memo_Abbreviation;
                        newMemo.Memo_Date               = memo.Memo_Date;
                        newMemo.Memo_Text               = memo.Memo_Text;
                        newMemo.Memo_Title              = memo.Memo_Title;
                        newMemo.Tenant_RefID            = securityTicket.TenantID;
                        newMemo.UpdatedBy_Account_RefID = memo.UpdatedBy_Account_RefID;
                        newMemo.UpdatedOn               = memo.UpdatedOn;
                        newMemo.Save(Connection, Transaction);

                        var newNote = new CL1_ORD_PRC.ORM_ORD_PRC_ShoppingCart_Note();
                        newNote.CMN_BPT_Memo_RefID         = newMemo.CMN_BPT_MemoID;
                        newNote.ORD_PRC_ShoppingCart_RefID = newShoppingCartId;
                        newNote.Tenant_RefID = securityTicket.TenantID;
                        newNote.Save(Connection, Transaction);
                    }
                    #endregion
                }
            }

            return(returnValue);

            #endregion UserCode
        }
Ejemplo n.º 2
0
 ///<summary>
 /// Invokes the method for the given Connection, and Transaction, leaving them open/not commited if no exceptions occured
 ///<summary>
 public static FR_Guid Invoke(DbConnection Connection, DbTransaction Transaction, P_L5AWSAR_CAPCfSCBO_1349 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(Connection, Transaction, null, Parameter, securityTicket));
 }
Ejemplo n.º 3
0
        ///<summary>
        /// Method Invocation of wrapper classes
        ///<summary>
        protected static FR_Guid Invoke(DbConnection Connection, DbTransaction Transaction, string ConnectionString, P_L5AWSAR_CAPCfSCBO_1349 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            bool cleanupConnection  = Connection == null;
            bool cleanupTransaction = Transaction == null;

            FR_Guid functionReturn = new FR_Guid();

            try
            {
                if (cleanupConnection == true)
                {
                    Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(ConnectionString);
                    Connection.Open();
                }
                if (cleanupTransaction == true)
                {
                    Transaction = Connection.BeginTransaction();
                }

                functionReturn = Execute(Connection, Transaction, Parameter, securityTicket);

                #region Cleanup Connection/Transaction
                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw new Exception("Exception occured in method cls_Create_Approval_Cart_for_ShoppingCart_Before_Order", ex);
            }
            return(functionReturn);
        }
Ejemplo n.º 4
0
 ///<summary>
 /// Opens the connection/transaction for the given connectionString, and closes them when complete
 ///<summary>
 public static FR_Guid Invoke(string ConnectionString, P_L5AWSAR_CAPCfSCBO_1349 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
 {
     return(Invoke(null, null, ConnectionString, Parameter, securityTicket));
 }