// 購買 public OperationResult <OperationRecordViewModel> Purchase(OperationMD Data, AuthModel Operator) { OperationResult <OperationRecordViewModel> result = new OperationResult <OperationRecordViewModel>(); RepositoryIssueRecord repoIssueRecord = new RepositoryIssueRecord(); RepositoryMember repoMember = new RepositoryMember(); DateTime processTime = DateTime.Now; OperationResult resultIssueRecord, resultMember, resultOperationRecord; using (clsDBDapper db = new clsDBDapper()) { try { // 開啟交易 db.TransactionStart(string.Format("Operation_Purchase_{0}_{1}", Data.MemberID, Operator.ID)); // 建立發行紀錄 IssueRecord dataIssueRecord = new IssueRecord { OperationType = IssueRecord_OperationType.Export, Integration = Data.Integration, Category = IssueRecord_Category.Purchase, UpdateTime = processTime, OperatorID = Operator.ID }; resultIssueRecord = repoIssueRecord.Create(db, dataIssueRecord); if (!resultIssueRecord.Status) { throw new Exception(resultIssueRecord.Message); } // 更新會員餘額 BalanceOperationInfo dataBalaceOperationInfo = new BalanceOperationInfo { MemberID = Data.MemberID, MemberPwd = string.Empty, Integration = Data.Integration, UpdateTime = processTime, OperatorID = Operator.ID, OperationType = BalanceOperationInfo_OperationType.Import, ValidationType = BalanceOperationInfo_ValidationType.None, UpdateConsumptionDate = true }; resultMember = repoMember.UpdateBalance(db, dataBalaceOperationInfo); if (!resultMember.Status) { throw new Exception(resultMember.Message); } // 更新操作紀錄 OperationRecord dataOperationRecord = new OperationRecord { MemberID = Data.MemberID, OperationType = OperationRecord_OperationType.Purchase, Integration = Data.Integration, Note = null, UpdateTime = processTime, OperatorID = Operator.ID }; resultOperationRecord = Create(db, dataOperationRecord); if (!resultOperationRecord.Status) { throw new Exception(resultOperationRecord.Message); } // 確認及關閉交易 db.TransactionCommit(); db.TransactionDispose(); // 製作回傳結果 result.Type = "Purchase"; result.Status = true; result.Message = "購買成功"; result.Data.Add(GetOperationRecordViewModel(dataOperationRecord)); } catch (Exception ex) { // 回復資料 db.TransactionRollBack(); result.Status = false; result.Message = "購買失敗 : " + ex.Message; result.Data = null; } } return(result); }
// 轉移 public OperationResult <OperationRecordViewModel> Transfer(OperationMD Data, AuthModel Operator) { OperationResult <OperationRecordViewModel> result = new OperationResult <OperationRecordViewModel>(); RepositoryMember repoMember = new RepositoryMember(); DateTime processTime = DateTime.Now; OperationResult resultMemberExport, resultMemberImport, resultOperationRecord; MemberViewModel memberImport = repoMember.GetMemberViewModel(Data.TargetMemberID); // 驗證管理者密碼 if (!Data.AdministratorPwd.Equals(ConfigurationManager.AppSettings["AdministratorPwd"].Trim())) { result.Status = false; result.Message = "轉移失敗 : 管理者密碼錯誤"; result.Data = null; return(result); } // 驗證轉入與轉出會員 if (Data.MemberID == Data.TargetMemberID) { result.Status = false; result.Message = "轉移失敗 : 轉入會員與轉出會員相同"; result.Data = null; return(result); } using (clsDBDapper db = new clsDBDapper()) { try { // 開啟交易 db.TransactionStart(string.Format("Operation_Transfer_{0}_{1}", Data.MemberID, Operator.ID)); // 更新會員餘額 (轉出) BalanceOperationInfo dataBalaceOperationInfoExport = new BalanceOperationInfo { MemberID = Data.MemberID, MemberPwd = Data.MemberPwd, Integration = Data.Integration, UpdateTime = processTime, OperatorID = Operator.ID, OperationType = BalanceOperationInfo_OperationType.Export, ValidationType = BalanceOperationInfo_ValidationType.Force, UpdateConsumptionDate = true }; resultMemberExport = repoMember.UpdateBalance(db, dataBalaceOperationInfoExport); if (!resultMemberExport.Status) { throw new Exception(resultMemberExport.Message); } // 更新會員餘額 (轉入) BalanceOperationInfo dataBalaceOperationInfoImport = new BalanceOperationInfo { MemberID = Data.TargetMemberID, MemberPwd = string.Empty, Integration = Data.Integration, UpdateTime = processTime, OperatorID = Operator.ID, OperationType = BalanceOperationInfo_OperationType.Import, ValidationType = BalanceOperationInfo_ValidationType.None, UpdateConsumptionDate = false }; resultMemberImport = repoMember.UpdateBalance(db, dataBalaceOperationInfoImport); if (!resultMemberImport.Status) { throw new Exception(resultMemberImport.Message); } // 更新操作紀錄 OperationRecord dataOperationRecord = new OperationRecord { MemberID = Data.MemberID, OperationType = OperationRecord_OperationType.Transfer, Integration = Data.Integration, Note = memberImport.Name, UpdateTime = processTime, OperatorID = Operator.ID }; resultOperationRecord = Create(db, dataOperationRecord); if (!resultOperationRecord.Status) { throw new Exception(resultOperationRecord.Message); } // 確認及關閉交易 db.TransactionCommit(); db.TransactionDispose(); // 製作回傳結果 result.Type = "Transfer"; result.Status = true; result.Message = "轉移成功"; result.Data.Add(GetOperationRecordViewModel(dataOperationRecord)); } catch (Exception ex) { // 回復資料 db.TransactionRollBack(); result.Status = false; result.Message = "轉移失敗 : " + ex.Message; result.Data = null; } } return(result); }