Ejemplo n.º 1
0
        public ResultModel CreateStock(UserModel user, Model.CashInAllot allot, List<Model.CashInStcok> details, int stockLogId)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.Contract.DAL.ContractCorporationDetailDAL corpDetailDAL = new Contract.DAL.ContractCorporationDetailDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                DAL.CashInDAL cashInDAL = new CashInDAL();
                NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new WareHouse.DAL.StockLogDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取库存流水
                    result = stockLogDAL.Get(user, stockLogId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.StockLog stockLog = result.ReturnValue as NFMT.WareHouse.Model.StockLog;
                    if (stockLog == null || stockLog.StockLogId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存流水不存在";
                        return result;
                    }

                    //获取库存
                    result = stockDAL.Get(user, stockLog.StockId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock;
                    if (stock == null || stock.StockId <= 0)
                    {
                        result.Message = "库存不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //获取合约
                    result = subDAL.Get(user, stockLog.SubContractId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约不存在";
                        return result;
                    }

                    if (sub.SubStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约状态不允许分配收款";
                        return result;
                    }

                    //获取外部公司
                    result = corpDetailDAL.LoadCorpListByContractId(user, sub.ContractId, false);
                    if (result.ResultStatus != 0)
                        return result;
                    List<NFMT.Contract.Model.ContractCorporationDetail> outCorps = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                    if (outCorps == null)
                    {
                        result.Message = "合约对方抬头获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.CashInStcok detail in details)
                    {
                        //收款登记验证
                        result = cashInDAL.Get(user, detail.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.Message = "收款登记不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //收款登记与合约币种验证
                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.Message = "收款登记币种与合约币种不相同";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //获取合约收款分配
                        result = cashInContractDAL.Get(user, detail.ContractRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInContract cashInContract = result.ReturnValue as Model.CashInContract;
                        if (cashInContract == null || cashInContract.RefId <= 0)
                        {
                            result.Message = "收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (cashInContract.DetailStatus != StatusEnum.已生效)
                        {
                            result.Message = "收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //获取公司收款分配
                        result = cashInCorpDAL.Get(user, cashInContract.CorpRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInCorp cashInCorp = result.ReturnValue as Model.CashInCorp;
                        if (cashInCorp == null || cashInCorp.RefId <= 0 || cashInCorp.DetailStatus != StatusEnum.已生效)
                        {
                            result.Message = "收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //验证公司抬头
                        if (!outCorps.Any(temp => temp.CorpId == cashInCorp.CorpId))
                        {
                            result.Message = "收款分配公司不在合约对方抬头,收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //新增库存收款分配
                        detail.AllotId = cashInContract.AllotId;
                        detail.CashInId = cashInContract.CashInId;
                        detail.ContractRefId = cashInContract.RefId;
                        detail.CorpRefId = cashInContract.CorpRefId;
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.StockId = stock.StockId;
                        detail.StockLogId = stockLog.StockLogId;
                        detail.StockNameId = stock.StockNameId;

                        result = this.cashinstcokDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.ResultStatus = -1;
            }

            return result;
        }
Ejemplo n.º 2
0
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL();
                DAL.CashInDAL cashInDAL = new CashInDAL();
                Model.CashIn cashIn = null;
                DAL.FundsLogDAL fundsLogDAL = new FundsLogDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = cashInAllotDAL.Get(user, dataSource.RowId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CashInAllot cashInAllot = result.ReturnValue as Model.CashInAllot;
                    if (cashInAllot == null || cashInAllot.AllotId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "收款分配不存在";
                        return result;
                    }

                    //审核,修改数据状态
                    result = cashInAllotDAL.Audit(user, cashInAllot, isPass);
                    if (result.ResultStatus != 0)
                        return result;

                    //审核通过
                    if (isPass)
                    {
                        result = this.cashinstcokDAL.LoadByAllot(user, cashInAllot.AllotId, NFMT.Common.StatusEnum.已生效);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CashInStcok> cashInStcoks = result.ReturnValue as List<Model.CashInStcok>;
                        if (cashInStcoks == null || !cashInStcoks.Any())
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取明细失败";
                            return result;
                        }

                        foreach (Model.CashInStcok cashInStcok in cashInStcoks)
                        {
                            result = cashInDAL.Get(user, cashInStcok.CashInId);
                            if (result.ResultStatus != 0)
                                return result;

                            cashIn = result.ReturnValue as Model.CashIn;
                            if (cashIn == null)
                            {
                                result.ResultStatus = -1;
                                result.Message = "获取收款失败";
                                return result;
                            }

                            result = cashInContractDAL.Get(user, cashInStcok.ContractRefId);
                            if (result.ResultStatus != 0)
                                return result;

                            Model.CashInContract cashInContract = result.ReturnValue as Model.CashInContract;
                            if (cashInContract == null)
                            {
                                result.ResultStatus = -1;
                                result.Message = "获取失败";
                                return result;
                            }

                            result = fundsLogDAL.Insert(user, new FundsLog()
                            {
                                //FundsLogId
                                ContractId = cashInContract.ContractId,
                                SubId = cashInContract.SubContractId,
                                //InvoiceId
                                LogDate = DateTime.Now,
                                InBlocId = cashIn.CashInBlocId,
                                InCorpId = cashIn.CashInCorpId,
                                InBankId = cashIn.CashInBank,
                                InAccountId = cashIn.CashInAccoontId,
                                OutBlocId = cashIn.PayBlocId,
                                OutCorpId = cashIn.PayCorpId,
                                OutBankId = cashIn.PayBankId,
                                OutBank = cashIn.PayBank,
                                OutAccountId = cashIn.PayAccountId,
                                OutAccount = cashIn.PayAccount,
                                FundsBala = cashInStcok.AllotBala,
                                //FundsType
                                CurrencyId = cashInAllot.CurrencyId,
                                LogDirection = (int)NFMT.WareHouse.LogDirectionEnum.In,
                                LogType = (int)NFMT.WareHouse.LogTypeEnum.收款,
                                //PayMode
                                //IsVirtualPay
                                FundsDesc = cashInAllot.AllotDesc,
                                OpPerson = user.EmpId,
                                LogSourceBase = "NFMT",
                                LogSource = "dbo.Fun_CashInContract_Ref",
                                SourceId = dataSource.RowId,
                                LogStatus = StatusEnum.已生效
                            });
                            if (result.ResultStatus != 0)
                                return result;

                            int fundsLogId = (int)result.ReturnValue;

                            cashInStcok.FundsLogId = fundsLogId;
                            result = cashinstcokDAL.Update(user, cashInStcok);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
                return result;
            }

            return result;
        }
Ejemplo n.º 3
0
        public ResultModel CreateDirectStock(UserModel user, Model.CashInAllot allot, List<Model.CashInCorp> details, int stockLogId)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new WareHouse.DAL.StockLogDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInAllotDAL allotDAL = new CashInAllotDAL();
                DAL.CashInDAL cashInDAL = new CashInDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取库存流水
                    result = stockLogDAL.Get(user, stockLogId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.StockLog stockLog = result.ReturnValue as NFMT.WareHouse.Model.StockLog;
                    if (stockLog == null || stockLog.StockLogId <= 0)
                    {
                        result.Message = "库存流水不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //获取库存
                    result = stockDAL.Get(user, stockLog.StockId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock;
                    if (stock == null || stock.StockId <= 0)
                    {
                        result.Message = "库存不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //获取子合约
                    result = subDAL.Get(user, stockLog.SubContractId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.Message = "子合约不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    allot.AllotBala = details.Sum(temp => temp.AllotBala);
                    allot.Alloter = user.EmpId;
                    allot.AllotStatus = StatusEnum.已录入;
                    allot.AllotTime = DateTime.Now;
                    allot.AllotType = (int)NFMT.Funds.CashInAllotTypeEnum.Stock;
                    allot.CurrencyId = sub.SettleCurrency;

                    result = allotDAL.Insert(user, allot);
                    if (result.ResultStatus != 0)
                        return result;

                    int allotId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out allotId) || allotId <= 0)
                    {
                        result.Message = "收款分配新增失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //获取外部公司
                    NFMT.Contract.DAL.ContractCorporationDetailDAL corpDAL = new Contract.DAL.ContractCorporationDetailDAL();
                    result = corpDAL.LoadCorpListByContractId(user, sub.ContractId, false);
                    if (result.ResultStatus != 0)
                        return result;
                    List<NFMT.Contract.Model.ContractCorporationDetail> outCorps = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                    if (outCorps == null)
                    {
                        result.Message = "合约对方抬头获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.CashInCorp corpDetail in details)
                    {
                        NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == corpDetail.CorpId);
                        if (corp == null || corp.CorpId <= 0)
                        {
                            result.Message = "收款分配公司不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (!outCorps.Any(temp => temp.CorpId == corp.CorpId))
                        {
                            result.Message = "收款分配公司不在合约对方抬头,收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        result = cashInDAL.Get(user, corpDetail.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.Message = "收款登记不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.Message = "收款登记币种与合约币种不相同";
                            result.ResultStatus = -1;
                            return result;
                        }

                        corpDetail.AllotId = allotId;
                        corpDetail.BlocId = corp.ParentId;
                        corpDetail.CashInId = cashIn.CashInId;
                        corpDetail.CorpId = corp.CorpId;
                        corpDetail.DetailStatus = StatusEnum.已生效;
                        corpDetail.IsShare = false;

                        result = cashInCorpDAL.Insert(user, corpDetail);
                        if (result.ResultStatus != 0)
                            return result;

                        int corpRefId = 0;
                        if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out corpRefId) || corpRefId <= 0)
                        {
                            result.Message = "收款分配新增失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        Model.CashInContract cashInContract = new CashInContract();
                        cashInContract.AllotBala = corpDetail.AllotBala;
                        cashInContract.AllotId = corpDetail.AllotId;
                        cashInContract.CashInId = corpDetail.CashInId;
                        cashInContract.ContractId = sub.ContractId;
                        cashInContract.CorpRefId = corpRefId;
                        cashInContract.DetailStatus = StatusEnum.已生效;
                        cashInContract.SubContractId = sub.SubId;

                        result = cashInContractDAL.Insert(user, cashInContract);
                        if (result.ResultStatus != 0)
                            return result;

                        int contractRefId = 0;
                        if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out contractRefId) || contractRefId <= 0)
                        {
                            result.Message = "收款分配新增失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        Model.CashInStcok cashInStock = new CashInStcok();
                        cashInStock.AllotBala = cashInContract.AllotBala;
                        cashInStock.AllotId = cashInContract.AllotId;
                        cashInStock.CashInId = cashInContract.CashInId;
                        cashInStock.ContractRefId = contractRefId;
                        cashInStock.CorpRefId = cashInContract.CorpRefId;
                        cashInStock.DetailStatus = StatusEnum.已生效;
                        cashInStock.StockId = stockLog.StockId;
                        cashInStock.StockLogId = stockLog.StockLogId;
                        cashInStock.StockNameId = stockLog.StockNameId;

                        result = this.cashinstcokDAL.Insert(user, cashInStock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 修改分配主表和明细表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rec"></param>
        /// <param name="details"></param>
        /// <returns></returns>
        public ResultModel UpdateMain(UserModel user, Model.CashInAllot allot, ref List<Model.CashInAllotDetail> details)
        {
            ResultModel result = new ResultModel();

            if (details.Count == 0)
            {
                result.ResultStatus = -1;
                result.Message = "修改收款分配失败,未分配任何款项";
                return result;
            }

            //验证明细币种是否相同
            int currencyId = 0;
            NFMT.Funds.DAL.CashInDAL cashInDAL = new CashInDAL();
            foreach (Model.CashInAllotDetail detail in details)
            {
                result = cashInDAL.Get(user, detail.CashInId);
                if (result.ResultStatus != 0)
                    return result;

                Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                if (cashIn == null || cashIn.CashInId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记不存在";
                    return result;
                }

                if (cashIn.CashInStatus != StatusEnum.已生效)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记状态错误";
                    return result;
                }

                if (currencyId == 0)
                    currencyId = cashIn.CurrencyId;

                if (currencyId != cashIn.CurrencyId)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记币种不相同";
                    return result;
                }
            }

            //获取分配
            result = this.cashinallotDAL.Get(user, allot.AllotId);
            if (result.ResultStatus != 0)
                return result;

            Model.CashInAllot resultObj = result.ReturnValue as Model.CashInAllot;
            if (resultObj == null || resultObj.AllotId <= 0)
            {
                result.Message = "分配不存在,不能进行修改";
                result.ResultStatus = -1;
                return result;
            }

            //更新主表
            decimal sumBala = details.Sum(temp => temp.AllotBala);

            resultObj.AllotBala = sumBala;
            resultObj.Alloter = user.EmpId;
            resultObj.AllotTime = DateTime.Now;
            resultObj.CurrencyId = currencyId;

            result = this.cashinallotDAL.Update(user, resultObj);
            if (result.ResultStatus != 0)
                return result;

            //获取原有明细并作废
            DAL.CashInAllotDetailDAL detailDAL = new CashInAllotDetailDAL();
            result = detailDAL.Load(user, resultObj.AllotId);
            if (result.ResultStatus != 0)
                return result;

            List<Model.CashInAllotDetail> resultDetails = result.ReturnValue as List<Model.CashInAllotDetail>;
            if (resultDetails == null)
            {
                result.Message = "获取明细失败";
                result.ResultStatus = -1;
                return result;
            }

            foreach (Model.CashInAllotDetail detail in resultDetails)
            {
                if (detail.DetailStatus == StatusEnum.已生效)
                    detail.DetailStatus = StatusEnum.已录入;

                result = detailDAL.Invalid(user, detail);
                if (result.ResultStatus != 0)
                    return result;
            }

            foreach (Model.CashInAllotDetail detail in details)
            {
                int detailId = 0;

                detail.DetailStatus = StatusEnum.已生效;
                detail.AllotId = resultObj.AllotId;
                result = detailDAL.Insert(user, detail);
                if (result.ResultStatus != 0)
                    return result;

                if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailId))
                {
                    result.ResultStatus = -1;
                    result.Message = "收款分配明细新增失败";
                    return result;
                }

                detail.DetailId = detailId;
            }

            return result;
        }
Ejemplo n.º 5
0
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();
            DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
            DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();
            DAL.CashInStcokDAL cashInStcokDAL = new CashInStcokDAL();
            DAL.CashInDAL cashInDAL = new CashInDAL();
            DAL.FundsLogDAL fundsLogDAL = new FundsLogDAL();
            DAL.CashInInvoiceDAL cashInInvoiceDAL = new CashInInvoiceDAL();

            Model.CashIn cashIn = null;

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = cashinallotDAL.Get(user, dataSource.RowId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CashInAllot cashInAllot = result.ReturnValue as Model.CashInAllot;
                    if (cashInAllot == null || cashInAllot.AllotId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "收款分配不存在";
                        return result;
                    }

                    //审核,修改数据状态
                    result = cashinallotDAL.Audit(user, cashInAllot, isPass);
                    if (result.ResultStatus != 0)
                        return result;

                    //审核通过
                    if (isPass)
                    {
                        //获取已生效的收款分配至公司
                        result = cashInCorpDAL.Load(user, cashInAllot.AllotId, NFMT.Common.StatusEnum.已生效);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CashInCorp> cashInCorps = result.ReturnValue as List<Model.CashInCorp>;
                        if (cashInCorps == null || !cashInCorps.Any())
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取收款分配至公司失败";
                            return result;
                        }

                        Model.CashInCorp cashInCorp = cashInCorps.FirstOrDefault(a => a.RefId > 0);

                        //获取已生效的收款分配至合约
                        result = cashInContractDAL.LoadDetail(user, cashInAllot.AllotId, StatusEnum.已生效);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CashInContract> cashInContracts = result.ReturnValue as List<Model.CashInContract>;
                        if (cashInContracts == null || !cashInContracts.Any())
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取收款分配至合约失败";
                            return result;
                        }

                        Model.CashInContract cashInContract = cashInContracts.FirstOrDefault(a => a.RefId > 0);

                        //获取已生效的收款分配至库存
                        result = cashInStcokDAL.LoadByAllot(user, cashInAllot.AllotId, StatusEnum.已生效);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CashInStcok> cashInStcoks = result.ReturnValue as List<Model.CashInStcok>;
                        if (cashInStcoks == null || !cashInStcoks.Any())
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取收款分配至库存失败";
                            return result;
                        }

                        //获取已生效的收款分配至发票
                        List<Model.CashInInvoice> cashInInvoices = new List<CashInInvoice>();
                        result = cashInInvoiceDAL.LoadByAllot(user, cashInAllot.AllotId, StatusEnum.已生效);
                        if (result.ResultStatus == 0 && result.ReturnValue != null)
                        {
                            cashInInvoices = result.ReturnValue as List<Model.CashInInvoice>;
                            if (cashInInvoices == null || !cashInInvoices.Any())
                            {
                                result.ResultStatus = -1;
                                result.Message = "获取收款分配至发票失败";
                                return result;
                            }
                        }

                        //获取收款
                        result = cashInDAL.Get(user, cashInCorp.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取收款失败";
                            return result;
                        }

                        result = fundsLogDAL.Insert(user, new FundsLog()
                        {
                            //FundsLogId
                            ContractId = cashInContract.ContractId,
                            SubId = cashInContract.SubContractId,
                            //InvoiceId
                            LogDate = DateTime.Now,
                            InBlocId = cashIn.CashInBlocId,
                            InCorpId = cashIn.CashInCorpId,
                            InBankId = cashIn.CashInBank,
                            InAccountId = cashIn.CashInAccoontId,
                            OutBlocId = cashIn.PayBlocId,
                            OutCorpId = cashIn.PayCorpId,
                            OutBankId = cashIn.PayBankId,
                            OutBank = cashIn.PayBank,
                            OutAccountId = cashIn.PayAccountId,
                            OutAccount = cashIn.PayAccount,
                            FundsBala = cashInAllot.AllotBala,
                            //FundsType
                            CurrencyId = cashInAllot.CurrencyId,
                            LogDirection = (int)NFMT.WareHouse.LogDirectionEnum.In,
                            LogType = (int)NFMT.WareHouse.LogTypeEnum.收款,
                            //PayMode
                            //IsVirtualPay
                            FundsDesc = cashInAllot.AllotDesc,
                            OpPerson = user.EmpId,
                            LogSourceBase = "NFMT",
                            LogSource = "dbo.Fun_CashInAllot",
                            SourceId = dataSource.RowId,
                            LogStatus = StatusEnum.已生效
                        });
                        if (result.ResultStatus != 0)
                            return result;

                        int fundsLogId = (int)result.ReturnValue;

                        //反向更新流水ID
                        cashInCorp.FundsLogId = fundsLogId;
                        result = cashInCorpDAL.Update(user, cashInCorp);
                        if (result.ResultStatus != 0)
                            return result;

                        cashInContract.FundsLogId = fundsLogId;
                        result = cashInContractDAL.Update(user, cashInContract);
                        if (result.ResultStatus != 0)
                            return result;

                        foreach (Model.CashInStcok cashInStock in cashInStcoks)
                        {
                            cashInStock.FundsLogId = fundsLogId;
                            result = cashInStcokDAL.Update(user, cashInStock);
                            if (result.ResultStatus != 0)
                                return result;
                        }

                        if (cashInInvoices != null && cashInInvoices.Any())
                        {
                            foreach (Model.CashInInvoice cashInInvoice in cashInInvoices)
                            {
                                cashInInvoice.FundsLogId = fundsLogId;
                                result = cashInInvoiceDAL.Update(user, cashInInvoice);
                                if (result.ResultStatus != 0)
                                    return result;
                            }
                        }
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
                return result;
            }

            return result;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 创建分配公司关联表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rec"></param>
        /// <param name="details"></param>
        /// <param name="corpDetail"></param>
        /// <returns></returns>
        public ResultModel UpdateCorp(UserModel user, Model.CashInAllot allot, List<Model.CashInCorp> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInCorpDAL corpDAL = new CashInCorpDAL();
                NFMT.Funds.DAL.CashInDAL cashInDAL = new CashInDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    if (details.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "修改收款分配失败,未分配任何款项";
                        return result;
                    }

                    //获取分配
                    result = this.cashinallotDAL.Get(user, allot.AllotId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CashInAllot resultObj = result.ReturnValue as Model.CashInAllot;
                    if (resultObj == null || resultObj.AllotId <= 0)
                    {
                        result.Message = "分配不存在,不能进行修改";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //验证明细币种是否相同
                    int currencyId = 0;

                    foreach (Model.CashInCorp detail in details)
                    {
                        result = cashInDAL.Get(user, detail.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "分配的收款登记不存在";
                            return result;
                        }

                        if (cashIn.CashInStatus != StatusEnum.已生效)
                        {
                            result.ResultStatus = -1;
                            result.Message = "分配的收款登记状态错误";
                            return result;
                        }

                        if (currencyId == 0)
                            currencyId = cashIn.CurrencyId;

                        if (currencyId != cashIn.CurrencyId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "分配的收款登记币种不相同";
                            return result;
                        }
                    }

                    //更新主表
                    decimal sumBala = details.Sum(temp => temp.AllotBala);

                    resultObj.AllotBala = sumBala;
                    resultObj.Alloter = user.EmpId;
                    resultObj.AllotTime = DateTime.Now;
                    resultObj.CurrencyId = currencyId;

                    result = this.cashinallotDAL.Update(user, resultObj);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取原有明细并作废
                    result = corpDAL.Load(user, resultObj.AllotId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInCorp> resultDetails = result.ReturnValue as List<Model.CashInCorp>;
                    if (resultDetails == null)
                    {
                        result.Message = "获取明细失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.CashInCorp detail in resultDetails)
                    {
                        //验证公司款是否已分配至合约中
                        result = cashInContractDAL.LoadByCorpRefId(user, detail.RefId);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CashInContract> contracts = result.ReturnValue as List<Model.CashInContract>;
                        if (contracts != null && contracts.Count > 0)
                        {
                            result.Message = "公司款已全部或部分已分配至合约中,不能进行修改";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (detail.DetailStatus == StatusEnum.已生效)
                            detail.DetailStatus = StatusEnum.已录入;

                        result = corpDAL.Invalid(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //添加新明细
                    NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == resultDetails[0].CorpId);
                    if (corp == null || corp.CorpId <= 0)
                    {
                        result.Message = "公司不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.CashInCorp detail in details)
                    {
                        detail.AllotId = resultObj.AllotId;
                        detail.BlocId = corp.ParentId;
                        detail.CorpId = corp.CorpId;
                        detail.DetailStatus = StatusEnum.已生效;

                        result = corpDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 创建分配主表和明细表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rec"></param>
        /// <param name="details"></param>
        /// <returns></returns>
        public ResultModel CreateMain(UserModel user, ref Model.CashInAllot allot, ref List<Model.CashInAllotDetail> details)
        {
            ResultModel result = new ResultModel();

            if (details.Count == 0)
            {
                result.ResultStatus = -1;
                result.Message = "新增收款分配失败,未分配任何款项";
                return result;
            }

            //验证明细币种是否相同
            int currencyId = 0;
            NFMT.Funds.DAL.CashInDAL cashInDAL = new CashInDAL();
            foreach (Model.CashInAllotDetail detail in details)
            {
                result = cashInDAL.Get(user, detail.CashInId);
                if (result.ResultStatus != 0)
                    return result;

                Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                if (cashIn == null || cashIn.CashInId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记不存在";
                    return result;
                }

                if (cashIn.CashInStatus != StatusEnum.已生效)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记状态错误";
                    return result;
                }

                if (currencyId == 0)
                    currencyId = cashIn.CurrencyId;

                if (currencyId != cashIn.CurrencyId)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记币种不相同";
                    return result;
                }
            }

            decimal sumBala = details.Sum(temp => temp.AllotBala);

            allot.AllotBala = sumBala;
            allot.AllotStatus = StatusEnum.已录入;
            allot.Alloter = user.EmpId;
            allot.AllotTime = DateTime.Now;
            allot.CurrencyId = currencyId;

            result = this.cashinallotDAL.Insert(user, allot);
            if (result.ResultStatus != 0)
                return result;

            int allotId = 0;
            if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out allotId))
            {
                result.ResultStatus = -1;
                result.Message = "收款分配失败";
                return result;
            }

            DAL.CashInAllotDetailDAL detailDAL = new CashInAllotDetailDAL();
            foreach (Model.CashInAllotDetail detail in details)
            {
                int detailId = 0;

                detail.DetailStatus = StatusEnum.已生效;
                detail.AllotId = allotId;
                result = detailDAL.Insert(user, detail);
                if (result.ResultStatus != 0)
                    return result;

                if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailId))
                {
                    result.ResultStatus = -1;
                    result.Message = "收款分配明细新增失败";
                    return result;
                }

                detail.DetailId = detailId;
            }

            return result;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 创建分配公司关联表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rec"></param>
        /// <param name="details"></param>
        /// <param name="corpDetail"></param>
        /// <returns></returns>
        public ResultModel CreateCorp(UserModel user, Model.CashInAllot allot, List<Model.CashInCorp> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInCorpDAL corpDAL = new CashInCorpDAL();
                NFMT.Funds.DAL.CashInDAL cashInDAL = new CashInDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    if (details.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "新增收款分配失败,未分配任何款项";
                        return result;
                    }

                    //验证明细币种是否相同
                    int currencyId = 0;

                    foreach (Model.CashInCorp detail in details)
                    {
                        result = cashInDAL.Get(user, detail.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "分配的收款登记不存在";
                            return result;
                        }

                        if (cashIn.CashInStatus != StatusEnum.已生效)
                        {
                            result.ResultStatus = -1;
                            result.Message = "分配的收款登记状态错误";
                            return result;
                        }

                        if (currencyId == 0)
                            currencyId = cashIn.CurrencyId;

                        if (currencyId != cashIn.CurrencyId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "分配的收款登记币种不相同";
                            return result;
                        }
                    }

                    decimal sumBala = details.Sum(temp => temp.AllotBala);

                    allot.AllotBala = sumBala;
                    allot.AllotStatus = StatusEnum.已录入;
                    allot.Alloter = user.EmpId;
                    allot.AllotTime = DateTime.Now;
                    allot.CurrencyId = currencyId;
                    allot.AllotType = (int)CashInAllotTypeEnum.Corp;

                    result = this.cashinallotDAL.Insert(user, allot);
                    if (result.ResultStatus != 0)
                        return result;

                    int allotId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out allotId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "收款分配失败";
                        return result;
                    }

                    NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == details[0].CorpId);
                    if (corp == null || corp.CorpId <= 0)
                    {
                        result.Message = "公司不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.CashInCorp detail in details)
                    {
                        detail.AllotId = allotId;
                        detail.BlocId = corp.ParentId;
                        detail.CorpId = corp.CorpId;
                        detail.DetailStatus = StatusEnum.已生效;

                        result = corpDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Ejemplo n.º 9
0
        public ResultModel CreateDirectContract(UserModel user, CashInAllot allot, List<CashInContractDirect> directs, int subId)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInDAL cashInDAL = new CashInDAL();
                DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取子合约
                    result = subDAL.Get(user, subId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约不存在,不能进行收款分配";
                        return result;
                    }

                    //判断合约状态

                    //获取合约对方抬头
                    result = subDAL.GetContractOutCorp(user, sub.SubId);
                    if (result.ResultStatus != 0)
                        return result;

                    DataTable outCorpTable = result.ReturnValue as DataTable;

                    if (outCorpTable == null || outCorpTable.Rows.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约对方抬头不存在,收款分配失败";
                        return result;
                    }

                    List<int> outCorpIds = new List<int>();
                    foreach (DataRow dr in outCorpTable.Rows)
                    {
                        int outCorpId = 0;
                        if (dr["CorpId"] == DBNull.Value || !int.TryParse(dr["CorpId"].ToString(), out outCorpId) || outCorpId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "合约对方抬头获取失败";
                            return result;
                        }

                        outCorpIds.Add(outCorpId);
                    }

                    List<Model.CashInCorp> cashCorps = new List<CashInCorp>();

                    foreach (CashInContractDirect direct in directs)
                    {
                        //判断收款分配到的对方抬头是否包含在合约抬头中
                        if (!outCorpIds.Contains(direct.AllotCorpId))
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款分配选择的分配公司不在该合约对方抬头中,收款分配失败";
                            return result;
                        }

                        //判断收款登记的币种是否和合约币种相同
                        result = cashInDAL.Get(user, direct.CashInId);
                        if (result.ResultStatus != 0)
                            return result;
                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款登记不存在";
                            return result;
                        }

                        if (cashIn.CashInStatus != StatusEnum.已生效)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款登记状态错误,不能进行分配";
                            return result;
                        }

                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款登记币种与合约币种不相同,分配错误";
                            return result;
                        }

                        CashInCorp cashCorp = new CashInCorp();

                        NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == direct.AllotCorpId);
                        if (corp == null || corp.CorpId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款分配选择的分配公司不存在,分配失败";
                            return result;
                        }

                        cashCorp.AllotBala = direct.AllotBala;
                        cashCorp.BlocId = corp.ParentId;
                        cashCorp.CashInId = direct.CashInId;
                        cashCorp.CorpId = corp.CorpId;
                        cashCorp.DetailStatus = StatusEnum.已生效;
                        cashCorp.IsShare = false;
                        cashCorp.AllotId = 0;

                        cashCorps.Add(cashCorp);

                    }

                    decimal sumBala = directs.Sum(temp => temp.AllotBala);

                    allot.AllotBala = sumBala;
                    allot.Alloter = user.EmpId;
                    allot.AllotStatus = StatusEnum.已录入;
                    allot.AllotTime = DateTime.Now;
                    allot.AllotType = (int)NFMT.Funds.CashInAllotTypeEnum.Contract;
                    allot.CurrencyId = sub.SettleCurrency;

                    //新增主分配
                    result = cashInAllotDAL.Insert(user, allot);
                    if (result.ResultStatus != 0)
                        return result;

                    int allotId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out allotId) || allotId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "收款分配新增失败";
                        return result;
                    }

                    //新增公司收款分配
                    foreach (Model.CashInCorp cd in cashCorps)
                    {
                        cd.AllotId = allotId;
                        result = cashInCorpDAL.Insert(user, cd);
                        if (result.ResultStatus != 0)
                            return result;

                        int refId = 0;
                        if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out refId) || refId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "公司收款分配新增失败";
                            return result;
                        }

                        CashInContract cashContract = new CashInContract();

                        cashContract.AllotBala = cd.AllotBala;
                        cashContract.AllotId = cd.AllotId;
                        cashContract.CashInId = cd.CashInId;
                        cashContract.ContractId = sub.ContractId;
                        cashContract.CorpRefId = refId;
                        cashContract.DetailStatus = StatusEnum.已生效;
                        cashContract.SubContractId = sub.SubId;

                        result = this.cashincontractDAL.Insert(user, cashContract);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Ejemplo n.º 10
0
        public ResultModel UpdateContract(UserModel user, List<CashInContract> details, int subId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInDAL cashInDAL = new CashInDAL();
                DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInStcokDAL cashInStockDAL = new CashInStcokDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取子合约
                    result = subDAL.Get(user, subId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.Message = "子合约不存在,不能进行修改";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //获取当前合约下的有效明细
                    result = this.cashincontractDAL.Load(user, sub.SubId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInContract> resultDetails = result.ReturnValue as List<Model.CashInContract>;

                    if (resultDetails == null)
                    {
                        result.Message = "获取明细失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //作废现有有效明细
                    foreach (Model.CashInContract nd in resultDetails)
                    {
                        //验证当前合约明细是否已分配至库存中
                        result = cashInStockDAL.LoadByContractRefId(user, nd.RefId);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CashInStcok> stocks = result.ReturnValue as List<Model.CashInStcok>;
                        if (stocks != null && stocks.Count > 0)
                        {
                            result.Message = "合约款已全部或部分配款至库存,不能进行修改";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (nd.DetailStatus == StatusEnum.已生效)
                            nd.DetailStatus = StatusEnum.已录入;

                        result = this.cashincontractDAL.Invalid(user, nd);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //新增明细
                    foreach (Model.CashInContract det in details)
                    {
                        //获取公司分配
                        result = cashInCorpDAL.Get(user, det.CorpRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInCorp cashInCrop = result.ReturnValue as Model.CashInCorp;
                        if (cashInCrop == null || cashInCrop.RefId <= 0)
                        {
                            result.Message = "修改失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //获取分配
                        result = cashInAllotDAL.Get(user, cashInCrop.AllotId);
                        if (result.ResultStatus != 0)
                            return result;

                        NFMT.Funds.Model.CashInAllot allot = result.ReturnValue as NFMT.Funds.Model.CashInAllot;
                        if (allot == null || allot.AllotId <= 0)
                        {
                            result.Message = "收款分配不存在,不能进行修改";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //获取收款登记
                        result = cashInDAL.Get(user, cashInCrop.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.Message = "修改失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.Message = "修改失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        det.AllotId = cashInCrop.AllotId;
                        det.CorpRefId = cashInCrop.RefId;
                        det.ContractId = sub.ContractId;
                        det.CashInId = cashIn.CashInId;
                        det.CorpRefId = cashInCrop.RefId;
                        det.DetailStatus = StatusEnum.已生效;
                        det.SubContractId = sub.SubId;

                        result = this.cashincontractDAL.Insert(user, det);

                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }

            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }