コード例 #1
0
        public async Task <IActionResult> Create(GlobalTransactionCreateBindingModel model)
        {
            var userId = await this.userService.GetUserIdByUsernameAsync(this.User.Identity.Name);

            model.SenderName = await this.userService.GetAccountOwnerFullNameAsync(userId);

            if (!this.TryValidateModel(model))
            {
                model.OwnAccounts = await this.GetAllAccountsAsync(userId);

                return(this.View(model));
            }

            var account = await this.bankAccountService.GetByIdAsync <BankAccountDetailsServiceModel>(model.AccountId);

            if (account == null || account.UserUserName != this.User.Identity.Name)
            {
                return(this.Forbid());
            }

            if (string.Equals(account.UniqueId, model.DestinationBank.Account.UniqueId,
                              StringComparison.InvariantCulture))
            {
                this.ShowErrorMessage(NotificationMessages.SameAccountsError);
                model.OwnAccounts = await this.GetAllAccountsAsync(userId);

                return(this.View(model));
            }

            var serviceModel = Mapper.Map <GlobalTransactionDto>(model);

            serviceModel.SourceAccountId = model.AccountId;
            serviceModel.RecipientName   = model.DestinationBank.Account.UserFullName;

            var result = await this.globalTransactionHelper.TransactAsync(serviceModel);

            if (result != GlobalTransactionResult.Succeeded)
            {
                if (result == GlobalTransactionResult.InsufficientFunds)
                {
                    this.ShowErrorMessage(NotificationMessages.InsufficientFunds);
                    model.OwnAccounts = await this.GetAllAccountsAsync(userId);

                    return(this.View(model));
                }

                this.ShowErrorMessage(NotificationMessages.TryAgainLaterError);
                return(this.RedirectToHome());
            }

            this.ShowSuccessMessage(NotificationMessages.SuccessfulTransaction);
            return(this.RedirectToHome());
        }
コード例 #2
0
        public async Task <IActionResult> Create()
        {
            var userId = await this.userService.GetUserIdByUsernameAsync(this.User.Identity.Name);

            var userAccounts = await this.GetAllAccountsAsync(userId);

            if (!userAccounts.Any())
            {
                this.ShowErrorMessage(NotificationMessages.NoAccountsError);

                return(this.RedirectToHome());
            }

            var model = new GlobalTransactionCreateBindingModel
            {
                OwnAccounts = userAccounts,
                SenderName  = await this.userService.GetAccountOwnerFullNameAsync(userId)
            };

            return(this.View(model));
        }