Esempio n. 1
0
        // 轉移
        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);
        }
Esempio n. 2
0
        // 購買
        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);
        }
Esempio n. 3
0
        // 會員積分操作
        public OperationResult UpdateBalance(clsDBDapper DB, BalanceOperationInfo Data)
        {
            OperationResult   result = new OperationResult();
            DynamicParameters pars   = new DynamicParameters();
            MemberViewModel   member = GetMemberViewModel(Data.MemberID);
            long balance             = 0;

            // 驗證會員是否存在
            if (member == null)
            {
                result.Status  = false;
                result.Message = "無法取得會員資料";
                return(result);
            }

            // 驗證密碼
            switch (Data.ValidationType)
            {
            case BalanceOperationInfo_ValidationType.None:
                break;

            case BalanceOperationInfo_ValidationType.Force:
                if (!Data.MemberPwd.Equals(member.MemberPwd))
                {
                    result.Status  = false;
                    result.Message = "會員密碼錯誤";
                    return(result);
                }
                break;

            case BalanceOperationInfo_ValidationType.Auto:
                if (Data.Integration > member.FreeChangingAmount)
                {
                    if (!Data.MemberPwd.Equals(member.MemberPwd))
                    {
                        result.Status  = false;
                        result.Message = "會員密碼錯誤";
                        return(result);
                    }
                }
                break;

            default:
                result.Status  = false;
                result.Message = "驗證類型錯誤";
                return(result);
            }

            // 取得餘額
            switch (Data.OperationType)
            {
            case BalanceOperationInfo_OperationType.Import:
                balance = member.Integration + Data.Integration;
                break;

            case BalanceOperationInfo_OperationType.Export:
                balance = member.Integration - Data.Integration;
                break;

            default:
                result.Status  = false;
                result.Message = "操作類型錯誤";
                return(result);
            }

            // 驗證餘額
            if (balance < 0)
            {
                result.Status  = false;
                result.Message = "會員餘額不足";
                return(result);
            }

            sql  = "update [SpadesKing].[dbo].[Member] ";
            sql += "set UpdateTime = @UpdateTime, OperatorID = @OperatorID, Integration = @Integration, LastConsumptionDate = @LastConsumptionDate ";
            sql += "where RecordID = @RecordID ";

            pars.Add("@UpdateTime", Data.UpdateTime);
            pars.Add("@OperatorID", Data.OperatorID);
            pars.Add("@Integration", balance);
            pars.Add("@LastConsumptionDate", Data.UpdateConsumptionDate ? Data.UpdateTime : member.LastConsumptionDate);
            pars.Add("@RecordID", Data.MemberID);

            try
            {
                result.Status = DB.ToExecuteWithTran(sql, pars);
                if (!result.Status)
                {
                    throw new Exception("無法更新資料列 (會員),請聯絡系統管理員");
                }
                result.Message = "更新成功";
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
            }

            return(result);
        }