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 })); }
public async Task UpdateCampaignAccountExpired(int campaignid = 0, int agencyid = 0) { if (campaignid == 0) { var campaigns = await _campaignRepository.ListAsync(new CampaignExpiredFeedbackTimeSpecification()); foreach (var campaign in campaigns) { BackgroundJob.Enqueue <ICampaignService>(m => m.UpdateCampaignAccountExpired(campaign.Id, campaign.AgencyId)); } } else { var username = "******"; var campaignAccounts = await _campaignAccountRepository.ListAsync(new CampaignAccountByAgencySpecification(campaignid, CampaignAccountStatus.AgencyRequest)); foreach (var campaignAccount in campaignAccounts) { campaignAccount.Status = CampaignAccountStatus.Canceled; campaignAccount.DateModified = DateTime.Now; campaignAccount.UserModified = username; await _campaignAccountRepository.UpdateAsync(campaignAccount); var notifType = NotificationType.AccountDeclineJoinCampaign; await _notificationRepository.AddAsync(new Notification() { Type = notifType, DataId = campaignid, Data = string.Empty, DateCreated = DateTime.Now, EntityType = EntityType.Agency, EntityId = agencyid, Message = notifType.GetMessageText(username, campaignid.ToString()), Status = NotificationStatus.Created }); } } }