コード例 #1
0
        public async Task <IActionResult> MicroKolSubstractMoney(long money_number, string txt_note, int caid)
        {
            var filter          = new CampaignAccountByIdSpecification(caid);
            var campaignaccount = _ICampaignAccountRepository.GetSingleBySpec(filter);

            //caid = campaignaccount id
            if (campaignaccount != null)
            {
                try
                {
                    int senderid = await _IWalletRepository.GetWalletId(EntityType.Account, campaignaccount.AccountId);

                    int recieverid = await _IWalletRepository.GetWalletId(EntityType.Agency, campaignaccount.Campaign.AgencyId);

                    int campaignid = campaignaccount.Campaign.Id;
                    //check xem đã trừ tiền chưa?
                    if (_ITransactionBusiness.CheckExist(senderid, recieverid, TransactionType.CampaignAccountRefundAgency, campaignid))
                    {
                        TempData["MessageError"] = "You was Refund money!";
                    }
                    else
                    {
                        int transactionid = await _ITransactionRepository.CreateTransaction(senderid, recieverid, money_number, TransactionType.CampaignAccountRefundAgency, txt_note, string.Format("Campaign ID = {0}", campaignid), HttpContext.User.Identity.Name, campaignid);

                        if (transactionid > 0)
                        {
                            int retValue = await _ITransactionBusiness.CalculateBalance(transactionid, money_number, senderid, recieverid, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency]", HttpContext.User.Identity.Name);

                            /*
                             * 09: success
                             * 10: wallet do not exist
                             * 11: wallet balance sender or receiver less then zero or amount could be abstract
                             *
                             */

                            try
                            {
                                switch (retValue)
                                {
                                case 9:
                                    TempData["MessageSuccess"]       = "Success Refund Money";
                                    campaignaccount.IsRefundToAgency = true;
                                    await _ICampaignAccountRepository.UpdateAsync(campaignaccount);

                                    await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Completed, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency] Success", HttpContext.User.Identity.Name);    // delete transaction if case error

                                    //############# send notification to agency ############################################

                                    string message = string.Format("Tiền \"{0}\" trả cho Influencer \"{1}\" từ chiến dịch \"{2}\" đã được thu hồi về ví của bạn, do không thực hiện thành công.",
                                                                   money_number.ToPriceText(), campaignaccount.Account.Name, campaignaccount.Campaign.Title);


                                    await _INotificationService.CreateNotification(campaignaccount.CampaignId, EntityType.Agency, campaignaccount.Campaign.AgencyId, NotificationType.TransactionAccountRefundToAgency, message, "");

                                    //######################################################################################

                                    break;

                                case 10:
                                    TempData["MessageError"] = "Wallet do not exist";
                                    await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Error, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency] Wallet do not exist", HttpContext.User.Identity.Name);    // delete transaction if case error

                                    break;

                                case 11:
                                    TempData["MessageError"] = "Wallet balance sender or receiver less then zero or amount could be abstract";
                                    await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Error, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency] Wallet balance sender or receiver less then zero or amount could be abstract", HttpContext.User.Identity.Name);    // delete transaction if case error

                                    break;

                                case 12:
                                    TempData["MessageError"] = "Wallet balance sender do not enought balance";
                                    await _ITransactionRepository.UpdateTransactionStatus(transactionid, TransactionStatus.Error, "[Hoàn lại tiền Agency từ người dùng tham gia chiến dịch][CampaignAccountRefundAgency] Wallet balance sender do not enought balance", HttpContext.User.Identity.Name);    // delete transaction if case error

                                    break;
                                }
                            }
                            catch (Exception ex) {
                                TempData["MessageError"] = ex.Message;
                            }
                        }
                        else
                        {
                            TempData["MessageError"] = "Can't created transaction!";
                        }
                    }
                }
                catch (Exception ex)
                {
                    TempData["MessageError"] = ex.Message;
                }
            }
            else
            {
                TempData["MessageError"] = "Campaign Account NULL!";
            }



            return(RedirectToAction("MicroKolSubstractMoney", "MicroKol", new { caid = caid }));
        }