public ResultModel Create(UserModel user, Model.CashInAllot cashInAllot, Model.CashInCorp cashInCorp, Model.CashInContract cashInContract, List<Model.CashInStcok> cashInStocks, List<NFMT.Funds.Model.CashInInvoice> cashInInvoices) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = cashinallotDAL.Insert(user, cashInAllot); if (result.ResultStatus != 0) return result; int cashInAllotId = (int)result.ReturnValue; cashInCorp.AllotId = cashInAllotId; DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL(); result = cashInCorpDAL.Insert(user, cashInCorp); if (result.ResultStatus != 0) return result; int corpRefId = (int)result.ReturnValue; int cashInContractCId = 0; if (cashInContract.SubContractId > 0) { NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); result = contractDAL.Get(user, cashInContract.SubContractId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract; if (contract == null || contract.ContractId <= 0) { result.ResultStatus = -1; result.Message = "获取合约失败"; return result; } cashInContractCId = contract.ContractId; } cashInContract.CorpRefId = corpRefId; cashInContract.AllotId = cashInAllotId; cashInContract.ContractId = cashInContractCId; DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL(); result = cashInContractDAL.Insert(user, cashInContract); if (result.ResultStatus != 0) return result; int contractRefId = (int)result.ReturnValue; if (cashInStocks != null && cashInStocks.Any()) { DAL.CashInStcokDAL cashInStcokDAL = new CashInStcokDAL(); foreach (Model.CashInStcok cashInStcok in cashInStocks) { cashInStcok.CashInId = cashInCorp.CashInId; cashInStcok.AllotId = cashInAllotId; cashInStcok.CorpRefId = corpRefId; cashInStcok.ContractRefId = contractRefId; result = cashInStcokDAL.Insert(user, cashInStcok); if (result.ResultStatus != 0) return result; } } if (cashInInvoices != null && cashInInvoices.Any()) { DAL.CashInInvoiceDAL cashInInvoiceDAL = new CashInInvoiceDAL(); foreach (Model.CashInInvoice cashInInvoice in cashInInvoices) { cashInInvoice.CashInId = cashInCorp.CashInId; cashInInvoice.AllotId = cashInAllotId; cashInInvoice.CorpRefId = corpRefId; cashInInvoice.ContractRefId = contractRefId; result = cashInInvoiceDAL.Insert(user, cashInInvoice); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.Message = ex.Message; result.ResultStatus = -1; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }
public ResultModel Update(UserModel user, Model.CashInAllot cashInAllot, Model.CashInCorp cashInCorp, Model.CashInContract cashInContract, List<Model.CashInStcok> cashInStocks, List<NFMT.Funds.Model.CashInInvoice> cashInInvoices) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = cashinallotDAL.Get(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; Model.CashInAllot cashInAllotres = result.ReturnValue as Model.CashInAllot; if (cashInAllotres == null) { result.ResultStatus = -1; result.Message = "获取收款分配失败"; return result; } cashInAllotres.Alloter = user.EmpId; cashInAllotres.AllotTime = DateTime.Now; cashInAllotres.AllotBala = cashInAllot.AllotBala; cashInAllotres.AllotType = cashInAllot.AllotType; cashInAllotres.CurrencyId = cashInAllot.CurrencyId; cashInAllotres.AllotDesc = cashInAllot.AllotDesc; result = cashinallotDAL.Update(user, cashInAllotres); if (result.ResultStatus != 0) return result; //作废收款分配至公司 DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL(); result = cashInCorpDAL.InvalidAll(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; result = cashInCorpDAL.Insert(user, cashInCorp); if (result.ResultStatus != 0) return result; int corpRefId = (int)result.ReturnValue; //作废收款分配至合同 DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL(); result = cashInContractDAL.InvalidAll(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; cashInContract.CorpRefId = corpRefId; result = cashInContractDAL.Insert(user, cashInContract); if (result.ResultStatus != 0) return result; int contractRefId = (int)result.ReturnValue; if (cashInStocks != null && cashInStocks.Any()) { DAL.CashInStcokDAL cashInStcokDAL = new CashInStcokDAL(); result = cashInStcokDAL.InvalidAll(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; foreach (Model.CashInStcok cashInStcok in cashInStocks) { cashInStcok.CashInId = cashInCorp.CashInId; cashInStcok.AllotId = cashInAllot.AllotId; cashInStcok.CorpRefId = corpRefId; cashInStcok.ContractRefId = contractRefId; result = cashInStcokDAL.Insert(user, cashInStcok); if (result.ResultStatus != 0) return result; } } if (cashInInvoices != null && cashInInvoices.Any()) { DAL.CashInInvoiceDAL cashInInvoiceDAL = new CashInInvoiceDAL(); result = cashInInvoiceDAL.InvalidAll(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; foreach (Model.CashInInvoice cashInInvoice in cashInInvoices) { cashInInvoice.CashInId = cashInCorp.CashInId; cashInInvoice.AllotId = cashInAllot.AllotId; cashInInvoice.CorpRefId = corpRefId; cashInInvoice.ContractRefId = contractRefId; result = cashInInvoiceDAL.Insert(user, cashInInvoice); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.Message = ex.Message; result.ResultStatus = -1; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }