Skip to content

Commit

Permalink
Merge pull request #161
Browse files Browse the repository at this point in the history
tuananh
  • Loading branch information
anhnmt authored Aug 27, 2021
2 parents c646ab8 + e185d44 commit 0037c5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
7 changes: 2 additions & 5 deletions Backend/Areas/Admin/Controllers/ChequesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,8 @@ public ActionResult ChequeExec(ChequesExecViewModel chequeExec)
var newNotifications = CreateNotifications(newTransaction);

transaction.Commit();

// using (var chatHub = new ChatHub())
// {
// chatHub.SendNotifications(newNotifications);
// }

ChatHub.Instance().SendNotifications(newNotifications);

return Json(new
{
Expand Down
13 changes: 9 additions & 4 deletions Backend/Controllers/TransactionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private JsonResult HandlerTransfer()
{
goto PlusMoney;
}

var minusError1 = MinusMoney(tran, sourceBankAccount, errors);
if (minusError1 != null)
{
Expand All @@ -134,7 +135,7 @@ private JsonResult HandlerTransfer()

// Plus money
PlusMoney:

receiverBankAccount = _context.BankAccounts.FirstOrDefault(x => x.Name == tran.ToId);

var plusError = PlusMoney(tran, receiverBankAccount, errors);
Expand All @@ -150,15 +151,17 @@ private JsonResult HandlerTransfer()
var newNotifications = CreateNotifications(newTransaction);

transaction.Commit();


ChatHub.Instance().SendNotifications(newNotifications);

return Json(new
{
data = "Successful transfer",
message = "Success",
statusCode = 200
});
}
catch (Exception)
catch (Exception ex)
{
transaction.Rollback();
}
Expand Down Expand Up @@ -198,9 +201,10 @@ private JsonResult CheckTransactionRequestModels(TransactionRequestModels tran,
statusCode = 404
}, JsonRequestBehavior.AllowGet);
}

var sourceBankAccount = bankAccounts.Get(x => x.Name == tran.FromId).FirstOrDefault();
var receiverBankAccount = bankAccounts.Get(x => x.Name == tran.ToId).FirstOrDefault();


if (tran.Amount <= 0)
{
Expand Down Expand Up @@ -246,6 +250,7 @@ private JsonResult CheckTransactionRequestModels(TransactionRequestModels tran,
statusCode = 404
}, JsonRequestBehavior.AllowGet);
}

if (sourceBankAccount.BankAccountId == receiverBankAccount.BankAccountId)
{
errors.Add("ToId", "The number of the receiving account and the sending account is the same");
Expand Down
21 changes: 12 additions & 9 deletions Backend/Hubs/ChatHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,24 @@ public string ReadNotification(int notificationId)
}
}

public async Task SendNotifications(List<Notifications> notifications)
public void SendNotifications(List<Notifications> notifications)
{
try
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
notifications.ForEach(async x =>
var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();

notifications.ForEach(x =>
{
var pkObject = transactionDetailRepo
.Get().FirstOrDefault(y => y.TransactionDetailId == x.PkId);
var pkObject = transactionDetailRepo.Get()
.FirstOrDefault(y => y.TransactionDetailId == x.PkId);

await context.Clients.Group("user-" + x.AccountId)
context.Clients.Group("user-" + x.AccountId)
.newNotification(new NotificationViewModel(x, pkObject));
// await context.Clients.Group("user-" + x.AccountId)
// .historyNotifications(GetNotificationsHistory(GetIntegerAccountId()));
});
await context.Clients.All.reloadChatData();
}
catch (Exception)
catch (Exception ex)
{
Clients.Caller.onError("Notification can't not send!");
}
Expand Down Expand Up @@ -239,7 +241,8 @@ public override Task OnConnected()
userViewModel.CurrentChannelId = channel.ChannelId;
Groups.Add(connectionId, "channel-" + channel.ChannelId);
Clients.Client(connectionId).historyMessages(GetMessageHistory(channel.ChannelId));
Clients.Client(connectionId).historyNotifications(GetNotificationsHistory(GetIntegerAccountId()));
Clients.Client(connectionId)
.historyNotifications(GetNotificationsHistory(GetIntegerAccountId()));
}

var tempAccount = Connections.FirstOrDefault(u => u.AccountId == accountId);
Expand Down
4 changes: 2 additions & 2 deletions Backend/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
</assemblyBinding>
</runtime>
<connectionStrings>
<!--<add name="DBConnectionString" connectionString="server=.;database=OnlineBanking;uid=sa;pwd=123456aA@;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />-->
<add name="DBConnectionString" connectionString="server=14.231.185.26;database=OnlineBanking;uid=sa;pwd=123456aA@;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
<add name="DBConnectionString" connectionString="server=.;database=OnlineBanking;uid=sa;pwd=123456aA@;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
<!-- <add name="DBConnectionString" connectionString="server=14.231.185.26;database=OnlineBanking;uid=sa;pwd=123456aA@;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" /> -->
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
Expand Down

0 comments on commit 0037c5d

Please sign in to comment.