public async static Task <IDTO> AddUpdateMode(List <Risk> risks)
        {
            string SPName  = "";
            string message = "";
            ComplateOperation <int> complate = new ComplateOperation <int>();

            foreach (var risk in risks)
            {
                OracleDynamicParameters oracleParams = new OracleDynamicParameters();
                List <DynamicDdl[]>     newCloumns   = new List <DynamicDdl[]>();

                if (risk.ID.HasValue)
                {
                    oracleParams.Add(RiskSpParams.PARAMETER_ID, OracleDbType.Int64, ParameterDirection.Input, (object)risk.ID ?? DBNull.Value);

                    SPName  = RiskSpName.SP_UPADTE_RISK;
                    message = "Updated Successfully";
                }
                else
                {
                    oracleParams.Add(RiskSpParams.PARAMETER_ID, OracleDbType.Int64, ParameterDirection.Output);
                    SPName  = RiskSpName.SP_INSERT_RISK;
                    message = "Inserted Successfully";
                }

                oracleParams.Add(RiskSpParams.PARAMETER_SERIAL, OracleDbType.Int64, ParameterDirection.Input, (object)risk.Serial ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_NAME, OracleDbType.Varchar2, ParameterDirection.Input, (object)risk.Name ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_DESCRIPTION, OracleDbType.Varchar2, ParameterDirection.Input, (object)risk.Description ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_EFFECTIVE_DATE, OracleDbType.Date, ParameterDirection.Input, (object)risk.EffectiveDate ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_EXPIRY_DATE, OracleDbType.Date, ParameterDirection.Input, (object)risk.ExpiryDate ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_OUR_SHARE, OracleDbType.Decimal, ParameterDirection.Input, (object)risk.OurShare ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_MIN_EXCESS_AMT, OracleDbType.Decimal, ParameterDirection.Input, (object)risk.MinExcessAmount ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_MAX_EXCESS_AMT, OracleDbType.Decimal, ParameterDirection.Input, (object)risk.MaxExcessAmount ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_REF_NO, OracleDbType.Varchar2, ParameterDirection.Input, (object)risk.RefNo ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_ST_LOB, OracleDbType.Int64, ParameterDirection.Input, (object)risk.StLOB ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_ST_SUB_LOB, OracleDbType.Int64, ParameterDirection.Input, (object)risk.StSubLOB ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_UW_DOC_ID, OracleDbType.Int64, ParameterDirection.Input, (object)risk.UwDocumentID ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_SUMINSURED, OracleDbType.Decimal, ParameterDirection.Input, (object)risk.Suminsured ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_SUMINSURED_LC, OracleDbType.Decimal, ParameterDirection.Input, (object)risk.SuminsuredLC ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_NET_PREMIUM, OracleDbType.Decimal, ParameterDirection.Input, (object)risk.NetPremium ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_NET_PREMIUM_LC, OracleDbType.Decimal, ParameterDirection.Input, (object)risk.NetPremiumLc ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_GROSS_PREMIUM, OracleDbType.Decimal, ParameterDirection.Input, (object)risk.GrossPremium ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_GROSS_PREMIUM_LC, OracleDbType.Decimal, ParameterDirection.Input, (object)risk.GrossPremiumLc ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_ST_PRD_SBT_ID, OracleDbType.Int64, ParameterDirection.Input, (object)risk.ProductSubjectTypeID ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_ST_SBT_ID, OracleDbType.Int64, ParameterDirection.Input, (object)risk.SubjectTypeID ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_ST_PROD_ID, OracleDbType.Int64, ParameterDirection.Input, (object)risk.ProductID ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_ST_PRDT_ID, OracleDbType.Int64, ParameterDirection.Input, (object)risk.ProductDetailID ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_UW_MBR_ID, OracleDbType.Int64, ParameterDirection.Input, (object)risk.MemberID ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_CREATED_BY, OracleDbType.Varchar2, ParameterDirection.Input, (object)risk.CreatedBy ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_CREATION_DATE, OracleDbType.Date, ParameterDirection.Input, (object)risk.CreationDate ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_MODIFIED_BY, OracleDbType.Varchar2, ParameterDirection.Input, (object)risk.ModifiedBy ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_MODIFICATION_DATE, OracleDbType.Date, ParameterDirection.Input, (object)risk.ModificationDate ?? DBNull.Value);
                oracleParams.Add(RiskSpParams.PARAMETER_UW_RISK_ID, OracleDbType.Int64, ParameterDirection.Input, (object)risk.UwRiskID ?? DBNull.Value);


                if (await NonQueryExecuter.ExecuteNonQueryAsync(SPName, oracleParams) == -1)
                {
                    complate.message = message;
                    complate.ID      = oracleParams.Get(0);
                    if (!risk.UpdateMode)
                    {
                        Attachment atacchment = new Attachment();
                        atacchment.RiskID       = complate.ID;
                        atacchment.Level        = 3;
                        atacchment.CreatedBy    = risk.CreatedBy;
                        atacchment.CreationDate = risk.CreationDate;
                        atacchment.ReceivedDate = null;
                        var attachmentResult = AutoAddAttachment.AutoAdd(atacchment);
                    }
                    if (risk.DynamicCategory != null)
                    {
                        foreach (var item2 in risk.DynamicCategory)
                        {
                            // map to category

                            if (item2.IsMulitRecords > 0)
                            {
                                if (item2.Result != null)
                                {
                                    foreach (var col in item2.Result)
                                    {
                                        if (risk.UpdateMode)
                                        {
                                            foreach (var c in col)
                                            {
                                                if (c.UwColID.HasValue)
                                                {
                                                    var result = AddUpdateCoulmns.AddUpdateMode(c);
                                                }
                                                else
                                                {
                                                    if (!newCloumns.Contains(col))
                                                    {
                                                        newCloumns.Add(col);
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            var category   = AddUpdateCategory.MapToCategory(item2, complate.ID, risk.UwDocumentID);
                                            var categoryID = await AddUpdateCategory.AddUpdateMode(category);

                                            var id = ((ComplateOperation <int>)categoryID).ID.Value;
                                            foreach (var c in col)
                                            {
                                                c.UnderWritingColCatID = id;
                                                c.UnderWritingRiskID   = category.RiskID;
                                                c.UnderWritingDocID    = category.DocumentID;
                                                c.LineOfBuisness       = category.LineOfBusiness;
                                                c.SubLineOfBuisness    = category.SubLineOfBusiness;
                                                c.ProductCategoryID    = category.ProductCategoryID;
                                                var result = AddUpdateCoulmns.AddUpdateMode(c);
                                            }
                                        }
                                    }
                                    if (newCloumns.Count > 0)
                                    {
                                        foreach (var newCol in newCloumns)
                                        {
                                            var category   = AddUpdateCategory.MapToCategory(item2, complate.ID, risk.UwDocumentID);
                                            var categoryID = await AddUpdateCategory.AddUpdateMode(category);

                                            var id = ((ComplateOperation <int>)categoryID).ID.Value;

                                            foreach (var item in newCol)
                                            {
                                                item.UnderWritingColCatID = id;
                                                item.UnderWritingRiskID   = category.RiskID;
                                                item.UnderWritingDocID    = category.DocumentID;
                                                item.LineOfBuisness       = category.LineOfBusiness;
                                                item.SubLineOfBuisness    = category.SubLineOfBusiness;
                                                item.ProductCategoryID    = category.ProductCategoryID;
                                                var result = AddUpdateCoulmns.AddUpdateMode(item);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                var category   = AddUpdateCategory.MapToCategory(item2, complate.ID, risk.UwDocumentID);
                                var categoryID = await AddUpdateCategory.AddUpdateMode(category);

                                var id = ((ComplateOperation <int>)categoryID).ID.Value;
                                foreach (var col in item2.ResultList)
                                {
                                    col.ID = null;
                                    col.UnderWritingColCatID = id;
                                    col.UnderWritingRiskID   = category.RiskID;
                                    col.UnderWritingDocID    = category.DocumentID;
                                    col.LineOfBuisness       = category.LineOfBusiness;
                                    col.SubLineOfBuisness    = category.SubLineOfBusiness;
                                    var result = AddUpdateCoulmns.AddUpdateMode(col);
                                }
                            }
                        }
                    }
                    // insert category
                }
                else
                {
                    complate.message = "Operation Failed";
                }
            }
            return(complate);
        }
        public async static Task <IDTO> AddUpdateMode(Document document)
        {
            string SPName  = "";
            string message = "";
            OracleDynamicParameters oracleParams = new OracleDynamicParameters();
            ComplateOperation <int> complate     = new ComplateOperation <int>();
            List <DynamicDdl[]>     newCloumns   = new List <DynamicDdl[]>();

            if (document.ID.HasValue)
            {
                oracleParams.Add(DocumentSpParams.PARAMETER_ID, OracleDbType.Int64, ParameterDirection.Input, (object)document.ID ?? DBNull.Value);

                SPName  = DocumentSpName.SP_UPADTE_DOCUMENT;
                message = "Updated Successfully";
            }
            else
            {
                oracleParams.Add(DocumentSpParams.PARAMETER_ID, OracleDbType.Int64, ParameterDirection.Output);
                SPName  = DocumentSpName.SP_INSERT_DOCUMENT;
                message = "Inserted Successfully";
            }


            oracleParams.Add(DocumentSpParams.PARAMETER_DOC_TYPE, OracleDbType.Int64, ParameterDirection.Input, (object)document.DocumentType ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_DCOUMENT_NO, OracleDbType.Int64, ParameterDirection.Input, (object)document.DocumentNo ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_TRN_SERIAL, OracleDbType.Int64, ParameterDirection.Input, (object)document.TrnSerial ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_UW_YEAR, OracleDbType.Int64, ParameterDirection.Input, (object)document.UwYear ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_DOC_SEGMENT, OracleDbType.Varchar2, ParameterDirection.Input, (object)document.DocumentSegment ?? DBNull.Value, 1000);
            oracleParams.Add(DocumentSpParams.PARAMETER_ISSUE_DATE, OracleDbType.Date, ParameterDirection.Input, (object)document.IssueDate ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_EFFECTIVE_DATE, OracleDbType.Date, ParameterDirection.Input, (object)document.EffectiveDate ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_EXPIRY_DATE, OracleDbType.Date, ParameterDirection.Input, (object)document.ExpiryDate ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_REF_NO, OracleDbType.Varchar2, ParameterDirection.Input, (object)document.ReferenceNo ?? DBNull.Value, 1000);
            oracleParams.Add(DocumentSpParams.PARAMETER_DOC_SHARE, OracleDbType.Decimal, ParameterDirection.Input, (object)document.DocumentShare ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_EXRATE, OracleDbType.Decimal, ParameterDirection.Input, (object)document.Exrate ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_ST_CUR_CODE, OracleDbType.Varchar2, ParameterDirection.Input, (object)document.CurrencyCode ?? DBNull.Value, 1000);
            oracleParams.Add(DocumentSpParams.PARAMETER_NOTES, OracleDbType.Varchar2, ParameterDirection.Input, (object)document.Notes ?? DBNull.Value, 1000);
            oracleParams.Add(DocumentSpParams.PARAMETER_NOTES2, OracleDbType.Varchar2, ParameterDirection.Input, (object)document.Notes2 ?? DBNull.Value, 1000);
            oracleParams.Add(DocumentSpParams.PARAMETER_ACC_FOR, OracleDbType.Int64, ParameterDirection.Input, (object)document.AccountedFor ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_IS_CLAIMED, OracleDbType.Int64, ParameterDirection.Input, (object)document.IsClaimed ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_IS_PRINTED, OracleDbType.Int64, ParameterDirection.Input, (object)document.IsPrinted ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_IS_REINSURED, OracleDbType.Int64, ParameterDirection.Input, (object)document.IsReinsured ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_IS_POSTED, OracleDbType.Int64, ParameterDirection.Input, (object)document.IsPosted ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_IS_CANCELLED, OracleDbType.Int64, ParameterDirection.Input, (object)document.IsCancelled ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_OPEN_COVER_TYPE, OracleDbType.Int64, ParameterDirection.Input, (object)document.OpenCoverType ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_STATUS, OracleDbType.Int64, ParameterDirection.Input, (object)document.Status ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_STATUS_DATE, OracleDbType.Date, ParameterDirection.Input, (object)document.StatusDate ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_CREATED_BY, OracleDbType.Varchar2, ParameterDirection.Input, (object)document.CreatedBy ?? DBNull.Value, 1000);
            oracleParams.Add(DocumentSpParams.PARAMETER_CREATION_DATE, OracleDbType.Date, ParameterDirection.Input, (object)document.CreationDate ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_MODIFIED_BY, OracleDbType.Varchar2, ParameterDirection.Input, (object)document.ModifiedBy ?? DBNull.Value, 1000);
            oracleParams.Add(DocumentSpParams.PARAMETER_MODIFICATION_DATE, OracleDbType.Date, ParameterDirection.Input, (object)document.ModificationDate ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_UW_DOC_ID, OracleDbType.Int64, ParameterDirection.Input, (object)document.UwDocId ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_ST_PROD_ID, OracleDbType.Int64, ParameterDirection.Input, (object)document.ProductId ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_LOC_PYM_ID, OracleDbType.Int64, ParameterDirection.Input, (object)document.PaymentId ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_LOC_BUST_ID, OracleDbType.Int64, ParameterDirection.Input, (object)document.LocBustId ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_LOC_ENDT_ID, OracleDbType.Int64, ParameterDirection.Input, (object)document.LocEndtId ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_ST_COM_ID, OracleDbType.Int64, ParameterDirection.Input, (object)document.StComId ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_ST_BRN_ID, OracleDbType.Int64, ParameterDirection.Input, (object)document.StBrnId ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_QUT_VALIDITY, OracleDbType.Int64, ParameterDirection.Input, (object)document.QutValidity ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_FYR_YEAR, OracleDbType.Int64, ParameterDirection.Input, (object)document.FyrYear ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_FINANCIAL_DATE, OracleDbType.Date, ParameterDirection.Input, (object)document.FinancialDate ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_CALC_BASES, OracleDbType.Int64, ParameterDirection.Input, (object)document.CalcBases ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_LOC_DIST_CHNALES, OracleDbType.Int64, ParameterDirection.Input, (object)document.LocDistChnales ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_NET_AMOUNT, OracleDbType.Decimal, ParameterDirection.Input, (object)document.NetAmount ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_NET_AMOUNT_LC, OracleDbType.Decimal, ParameterDirection.Input, (object)document.NetAmountLc ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_LOADING_AMOUNT, OracleDbType.Decimal, ParameterDirection.Input, (object)document.LoadingAmount ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_LOADING_AMOUNT_LC, OracleDbType.Decimal, ParameterDirection.Input, (object)document.LoadingAmountLc ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_DISCOUNT_AMOUNT, OracleDbType.Decimal, ParameterDirection.Input, (object)document.DiscountAmount ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_DISCOUNT_AMOUNT_LC, OracleDbType.Decimal, ParameterDirection.Input, (object)document.DiscountAmountLc ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_CHARGES_AMOUNT, OracleDbType.Decimal, ParameterDirection.Input, (object)document.ChargesAmount ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_CHARGES_AMOUNT_LC, OracleDbType.Decimal, ParameterDirection.Input, (object)document.ChargesAmountLc ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_COMM_AMOUNT, OracleDbType.Decimal, ParameterDirection.Input, (object)document.CommAmount ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_COMM_AMOUNT_LC, OracleDbType.Decimal, ParameterDirection.Input, (object)document.CommAmountLc ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_GROSS_AMMOUNT, OracleDbType.Decimal, ParameterDirection.Input, (object)document.GrossAmmount ?? DBNull.Value);
            oracleParams.Add(DocumentSpParams.PARAMETER_GROSS_AMOUNT_LC, OracleDbType.Decimal, ParameterDirection.Input, (object)document.GrossAmountLc ?? DBNull.Value);



            if (await NonQueryExecuter.ExecuteNonQueryAsync(SPName, oracleParams) == -1)
            {
                complate.message = message;
                complate.ID      = oracleParams.Get(0);

                if (!document.UpdateMode)
                {
                    Attachment atacchment = new Attachment();
                    atacchment.DocumentID   = complate.ID;
                    atacchment.Level        = document.DocumentType;
                    atacchment.CreatedBy    = document.CreatedBy;
                    atacchment.CreationDate = document.CreationDate;
                    atacchment.ReceivedDate = null;
                    var attachmentResult = AutoAddAttachment.AutoAdd(atacchment);
                }

                if (document.NewCustomer.ID.HasValue)
                {
                    var customerResult = AddUpdateCustomer.AddUpdateMode(document.NewCustomer, false);

                    // check if has bene
                    foreach (var item in document.share.customer)
                    {
                        if (item.ShareID.HasValue)
                        {
                            Share customerShare = new Share();
                            customerShare.ID           = item.ShareID;
                            customerShare.DocumentID   = complate.ID;
                            customerShare.SharePercent = 100;
                            customerShare.Amount       = 0;
                            customerShare.AmountLC     = 0;
                            customerShare.Percent      = item.Commision;
                            customerShare.StSubLOB     = null;
                            customerShare.StLOB        = null;
                            customerShare.CreatedBy    = document.CreatedBy;
                            customerShare.CreationDate = document.CreationDate;
                            customerShare.LocShareType = item.shareType;
                            customerShare.CustomerId   = item.CustomerID;
                            var shhareResult = DBSharesSetup.AddUpdateMode(customerShare);
                        }
                        else
                        {
                            Share customerShare = new Share();
                            customerShare.DocumentID   = complate.ID;
                            customerShare.SharePercent = 100;
                            customerShare.Amount       = 0;
                            customerShare.AmountLC     = 0;
                            customerShare.Percent      = item.Commision;
                            customerShare.StSubLOB     = null;
                            customerShare.StLOB        = null;
                            customerShare.CreatedBy    = document.CreatedBy;
                            customerShare.CreationDate = document.CreationDate;
                            customerShare.LocShareType = item.shareType;
                            customerShare.CustomerId   = item.CustomerID;
                            var shhareResult = DBSharesSetup.AddUpdateMode(customerShare);
                        }
                    }
                }
                else
                {
                    var customerResult = await AddUpdateCustomer.AddUpdateMode(document.NewCustomer, true);

                    var   CustomerID = ((ComplateOperation <int>)customerResult).ID.Value;
                    Share share      = new Share();
                    share.DocumentID   = complate.ID;
                    share.SharePercent = 100;
                    share.Amount       = 0;
                    share.AmountLC     = 0;
                    share.StSubLOB     = null;
                    share.StLOB        = null;
                    share.LocShareType = 1;
                    share.CustomerId   = CustomerID;
                    share.CreatedBy    = document.CreatedBy;
                    share.CreationDate = document.CreationDate;
                    var result = DBSharesSetup.AddUpdateMode(share);

                    Share share2 = new Share();
                    share2.DocumentID   = complate.ID;
                    share2.SharePercent = 100;
                    share2.Amount       = 0;
                    share2.AmountLC     = 0;
                    share2.StSubLOB     = null;
                    share2.StLOB        = null;
                    share2.LocShareType = 2;
                    share2.CustomerId   = CustomerID;
                    share2.CreatedBy    = document.CreatedBy;
                    share2.CreationDate = document.CreationDate;
                    var result2 = DBSharesSetup.AddUpdateMode(share2);
                    foreach (var item in document.share.customer)
                    {
                        Share customerShare = new Share();
                        customerShare.DocumentID   = complate.ID;
                        customerShare.SharePercent = 100;
                        customerShare.Percent      = item.Commision;
                        customerShare.Amount       = 0;
                        customerShare.AmountLC     = 0;
                        customerShare.StSubLOB     = null;
                        customerShare.StLOB        = null;
                        customerShare.LocShareType = item.shareType;
                        customerShare.CustomerId   = item.CustomerID;
                        var shhareResult = DBSharesSetup.AddUpdateMode(customerShare);
                    }
                }

                foreach (var item2 in document.DynamicCategories)
                {
                    // map to category

                    if (item2.IsMulitRecords > 0)
                    {
                        if (item2.Result != null)
                        {
                            foreach (var col in item2.Result)
                            {
                                if (document.UpdateMode)
                                {
                                    foreach (var c in col)
                                    {
                                        if (c.UwColID.HasValue)
                                        {
                                            var result = AddUpdateCoulmns.AddUpdateMode(c);
                                        }
                                        else
                                        {
                                            if (!newCloumns.Contains(col))
                                            {
                                                newCloumns.Add(col);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    var category   = AddUpdateCategory.MapToCategory(item2, null, complate.ID);
                                    var categoryID = await AddUpdateCategory.AddUpdateMode(category);

                                    var id = ((ComplateOperation <int>)categoryID).ID.Value;
                                    foreach (var c in col)
                                    {
                                        c.UnderWritingColCatID = id;
                                        c.UnderWritingRiskID   = category.RiskID;
                                        c.UnderWritingDocID    = category.DocumentID;
                                        c.LineOfBuisness       = category.LineOfBusiness;
                                        c.SubLineOfBuisness    = category.SubLineOfBusiness;
                                        c.ProductCategoryID    = category.ProductCategoryID;
                                        var result = AddUpdateCoulmns.AddUpdateMode(c);
                                    }
                                }
                            }
                            if (newCloumns.Count > 0)
                            {
                                foreach (var newCol in newCloumns)
                                {
                                    var category   = AddUpdateCategory.MapToCategory(item2, null, complate.ID);
                                    var categoryID = await AddUpdateCategory.AddUpdateMode(category);

                                    var id = ((ComplateOperation <int>)categoryID).ID.Value;

                                    foreach (var item in newCol)
                                    {
                                        item.UnderWritingColCatID = id;
                                        item.UnderWritingRiskID   = category.RiskID;
                                        item.UnderWritingDocID    = category.DocumentID;
                                        item.LineOfBuisness       = category.LineOfBusiness;
                                        item.SubLineOfBuisness    = category.SubLineOfBusiness;
                                        item.ProductCategoryID    = category.ProductCategoryID;
                                        var result = AddUpdateCoulmns.AddUpdateMode(item);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        var category   = AddUpdateCategory.MapToCategory(item2, null, complate.ID);
                        var categoryID = await AddUpdateCategory.AddUpdateMode(category);

                        var id = ((ComplateOperation <int>)categoryID).ID.Value;
                        foreach (var col in item2.ResultList)
                        {
                            col.ID = null;
                            col.UnderWritingColCatID = id;
                            col.UnderWritingRiskID   = category.RiskID;
                            col.UnderWritingDocID    = category.DocumentID;
                            col.LineOfBuisness       = category.LineOfBusiness;
                            col.SubLineOfBuisness    = category.SubLineOfBusiness;
                            var result = AddUpdateCoulmns.AddUpdateMode(col);
                        }
                    }
                }
            }
            else
            {
                complate.message = "Operation Failed";
            }

            return(complate);
        }