Example #1
0
 private async Task generateRequestNotification(RequestTransaction request)
 {
     var notification = NotificationFactory.CreateNewRequestTransactionNotification(
         Guid.NewGuid().ToString(), request.Data.ReceiverAccountId,
         request.Data.SenderAccountId, request.Data.Amount,
         false, DateTime.Now);
     await notifications.AddObject(notification);
 }
Example #2
0
        public void CreateNewRequestTransactionNotificationTest()
        {
            var r = GetRandom.Object <NewRequestTransactionNotificationData>();

            r.Message = "has requested a transaction in the amount of";
            var o = NotificationFactory.CreateNewRequestTransactionNotification(r.ID, r.SenderId, r.ReceiverId, r.Amount, r.IsSeen, r.ValidFrom, r.ValidTo);

            Assert.IsInstanceOfType(o, typeof(NewRequestTransactionNotification));
            testVariables(o.Data, r.ID, r.Message, r.ValidFrom, r.ValidTo, r.IsSeen, r.SenderId, r.ReceiverId);
            Assert.AreEqual(r.Amount, o.Data.Amount);
        }
        public async Task <IActionResult> ChangeSeenStatus(string notificationId, bool?seenStatus = null)
        {
            var notification = await notifications.GetObject(notificationId);

            switch (notification)
            {
            case WelcomeNotification wel:
                var welcome =
                    NotificationFactory.CreateWelcomeNotification(wel.Data?.ID,
                                                                  wel.Data?.SenderId, wel.Data?.ReceiverId, seenStatus ?? !wel.Data?.IsSeen,
                                                                  wel.Data?.ValidFrom, wel.Data?.ValidTo);
                await notifications.UpdateObject(welcome);

                break;

            case NewTransactionNotification tra:
                var transaction =
                    NotificationFactory.CreateNewTransactionNotification(tra.Data?.ID,
                                                                         tra.Data?.SenderId, tra.Data?.ReceiverId, tra.Data?.Amount, seenStatus ?? !tra.Data?.IsSeen,
                                                                         tra.Data?.ValidFrom, tra.Data?.ValidTo);
                await notifications.UpdateObject(transaction);

                break;

            case RequestStatusNotification reqStatus:
                var requestStatus =
                    NotificationFactory.CreateRequestStatusNotification(reqStatus.Data?.ID,
                                                                        reqStatus.Data?.SenderId, reqStatus.Data?.ReceiverId, reqStatus.Data?.Amount, reqStatus.Data?.Status ?? TransactionStatus.Pending,
                                                                        seenStatus ?? !reqStatus.Data?.IsSeen, reqStatus.Data?.ValidFrom, reqStatus.Data?.ValidTo);
                await notifications.UpdateObject(requestStatus);

                break;

            case NewRequestTransactionNotification req:
                var request =
                    NotificationFactory.CreateNewRequestTransactionNotification(req.Data?.ID,
                                                                                req.Data?.SenderId, req.Data?.ReceiverId, req.Data?.Amount,
                                                                                seenStatus ?? !req.Data?.IsSeen, req.Data?.ValidFrom, req.Data?.ValidTo);
                await notifications.UpdateObject(request);

                break;

            case NewInsuranceNotification ins:
                var insurance =
                    NotificationFactory.CreateNewInsuranceNotification(
                        ins.Data?.ID, ins.Data?.SenderId, ins.Data?.ReceiverId, ins.Data?.InsuranceType,
                        seenStatus ?? !ins.Data?.IsSeen, ins.Data?.ValidFrom, ins.Data?.ValidTo);
                await notifications.UpdateObject(insurance);

                break;
            }
            return(new EmptyResult());
        }