diff --git a/Backend/Areas/Admin/Controllers/ChequesController.cs b/Backend/Areas/Admin/Controllers/ChequesController.cs index 63d2f72..81e5d85 100644 --- a/Backend/Areas/Admin/Controllers/ChequesController.cs +++ b/Backend/Areas/Admin/Controllers/ChequesController.cs @@ -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 { diff --git a/Backend/Controllers/TransactionsController.cs b/Backend/Controllers/TransactionsController.cs index 2137135..0a6ec92 100644 --- a/Backend/Controllers/TransactionsController.cs +++ b/Backend/Controllers/TransactionsController.cs @@ -110,6 +110,7 @@ private JsonResult HandlerTransfer() { goto PlusMoney; } + var minusError1 = MinusMoney(tran, sourceBankAccount, errors); if (minusError1 != null) { @@ -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); @@ -150,7 +151,9 @@ private JsonResult HandlerTransfer() var newNotifications = CreateNotifications(newTransaction); transaction.Commit(); - + + ChatHub.Instance().SendNotifications(newNotifications); + return Json(new { data = "Successful transfer", @@ -158,7 +161,7 @@ private JsonResult HandlerTransfer() statusCode = 200 }); } - catch (Exception) + catch (Exception ex) { transaction.Rollback(); } @@ -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) { @@ -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"); diff --git a/Backend/Hubs/ChatHub.cs b/Backend/Hubs/ChatHub.cs index c1e4869..b87424f 100644 --- a/Backend/Hubs/ChatHub.cs +++ b/Backend/Hubs/ChatHub.cs @@ -187,22 +187,24 @@ public string ReadNotification(int notificationId) } } - public async Task SendNotifications(List notifications) + public void SendNotifications(List notifications) { try { - IHubContext context = GlobalHost.ConnectionManager.GetHubContext(); - notifications.ForEach(async x => + var context = GlobalHost.ConnectionManager.GetHubContext(); + + 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!"); } @@ -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); diff --git a/Backend/Web.config b/Backend/Web.config index 18ff9c5..6badf91 100644 --- a/Backend/Web.config +++ b/Backend/Web.config @@ -63,8 +63,8 @@ - - + +