Пример #1
0
        private TransactionResponseModel Deposit(DepositViewModel model, IUnitOfWork unit)
        {
            var failureResponse = new TransactionResponseModel
            {
                IsSuccessful = false
            };

            var account = unit.Repository <Account>().Get().SingleOrDefault(a => a.AccountNumber == model.AccountNumber);

            if (account != null)
            {
                if (model.Amount < decimal.MaxValue - account.Balance)
                {
                    account.Balance += model.Amount;
                    var entity = unit.Repository <Account>().Attach(account);
                    return(new TransactionResponseModel
                    {
                        IsSuccessful = true,
                        CurrentBalance = entity.Balance,
                        Message = Message.SuccessfulTracsaction
                    });
                }
                failureResponse.Message = Message.SystemError;
                return(failureResponse);
            }

            failureResponse.Message = Message.AccountIsInvalid;
            return(failureResponse);
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] DepositViewModel model)
        {
            Deposit deposit = _mapper.Map <DepositViewModel, Deposit>(model);

            deposit.Ativo = false;
            if (model.UserWallet != null)
            {
                Wallet wallet = await _appWalletService.GetWalletByGuidAsync(model.Guid);

                deposit.WalletId = wallet.Id;
                deposit.BankId   = null;
            }
            else
            {
                deposit.BankId = model.BankId;
            }

            try
            {
                await _appDepositService.InsertAsync(deposit);
            }
            catch (Exception e)
            {
                throw;
            }


            return(Ok());
        }
Пример #3
0
        public ActionResult Index(DepositSearchModel depositSearchModel)
        {
            try
            {
                DepositViewModel dvm = new DepositViewModel();
                if (depositSearchModel.StartDateString != null && depositSearchModel.StartDateString != "")
                {
                    depositSearchModel.StartDate = DateTime.ParseExact(depositSearchModel.StartDateString, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                    //depositSearchModel.StartDate = Convert.ToDateTime(depositSearchModel.EndDate).AddDays(1).AddMilliseconds(-1);
                }
                if (depositSearchModel.EndDateString != null && depositSearchModel.EndDateString != "")
                {
                    depositSearchModel.EndDate = DateTime.ParseExact(depositSearchModel.EndDateString, "dd-MM-yyyy", CultureInfo.InvariantCulture).AddDays(1).AddMilliseconds(-1);
                    //depositSearchModel.EndDate = Convert.ToDateTime(depositSearchModel.EndDate).AddDays(1).AddMilliseconds(-1);
                }
                dvm.DepositModelList = dal.GetDeposits(depositSearchModel);

                var bankAccount = dal.GetBanks();
                ViewBag.BankAccount = new SelectList(bankAccount, "Id", "BankName");

                var gameType = dal.GetGameTypes();
                ViewBag.GameType = new SelectList(gameType, "Id", "GameType");

                var status = from Status s in Enum.GetValues(typeof(Status)) select new { ID = (int)s, Name = s.ToString() };
                ViewBag.Status = new SelectList(status, "ID", "Name");

                return(View(dvm));
            }
            catch
            {
                Session["message"]       = "Unable to perform this request";
                Session["requestStatus"] = "Error";
                return(RedirectToAction("Index", "Deposit"));
            }
        }
        /*  DEPOSIT  */
        // Skapar upp Vy-modellen och redirectar
        public IActionResult MakeDeposit(int accountId)
        {
            DepositViewModel model = new DepositViewModel();

            model.Account = accountId;
            return(View(model));
        }
        public async Task <IActionResult> Deposit(DepositViewModel model)
        {
            TransactionStatusViewModel transactionStatus = new TransactionStatusViewModel();

            try
            {
                var response = await _transactionProvider.Deposit(model);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var jsoncontent = await response.Content.ReadAsStringAsync();

                    transactionStatus = JsonConvert.DeserializeObject <TransactionStatusViewModel>(jsoncontent);
                    return(View("TransactionStatus", transactionStatus));
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    ModelState.AddModelError("", "Having server issue while adding record");
                    return(View(model));
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
                {
                    ViewBag.Message = "Internal Server Error! Please try again later";
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Exceptions occured due to " + ex.Message);
            }
            ModelState.AddModelError("", "Having some unexpected error while processing transaction");
            return(View(model));
        }
Пример #6
0
        public async Task <IActionResult> Deposit([FromBody] DepositViewModel depositViewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("DepositViewModelInvalid", "Informe um modelo válido");
                    return(BadRequest(ModelState));
                }

                var account = await _accountAppService.GetByAccountNumberAndAgencyAsync(depositViewModel.AccountNumber, depositViewModel.Agency);

                if (account == null)
                {
                    return(NotFound("Conta não encontrada"));
                }

                await _accountAppService.Deposit(account, depositViewModel.Value);

                var result = _mapper.Map <AccountListViewModel>(account);

                return(Ok(result));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro ao realizar depósito. {ex.Message}"));
            }
        }
Пример #7
0
 public SearchForStore(DepositViewModel viewModel)
 {
     InitializeComponent();
     DataContext = viewModel;
     _viewModel  = viewModel;
     _viewModel.StoreList.Clear();
 }
Пример #8
0
 public SearchBankDeposit(DepositViewModel viewModel)
 {
     InitializeComponent();
     DataContext = viewModel;
     _viewModel  = viewModel;
     _viewModel.MainRowList.Clear();
 }
Пример #9
0
        public async Task <IActionResult> PutTransaction(Guid CommonCode, DepositViewModel transaction)
        {
            if (CommonCode != transaction.CommonCode)
            {
                return(BadRequest());
            }
            var existingTransaction = await _context.Transactions.Where(x => x.CommonCode == CommonCode).ToListAsync();

            if (existingTransaction.Count > 0)
            {
                var existingAccount = await _context.Accounts.ToListAsync();

                var updateableTransaction = existingTransaction.Where(x => x.AccountId == x.AccountId).ToList();
                updateableTransaction.ForEach(x => x.Amount = x.Account.AccountPercent * x.Amount / 100);
                await _context.SaveChangesAsync();


                foreach (var item in existingTransaction)
                {
                    if (existingAccount.Any(x => x.AccountId == item.AccountId))
                    {
                        _context.Entry(item).State = EntityState.Modified;
                        await _context.SaveChangesAsync();
                    }
                }
            }
            else
            {
                return(NotFound());
            }

            return(NoContent());
        }
Пример #10
0
        public IActionResult Deposit(DepositViewModel model)
        {
            if (ModelState.IsValid)
            {
                var command = new DepositCommand()
                {
                    AccountId = model.AccountId,
                    Amount    = model.Amount
                };

                var query = new DepositHandler().Handler(command);
                if (query.IsCompletedSuccessfully)
                {
                    TempData["Success"] = $"{model.Amount.ToString("C")} deposited to account";
                    return(View());
                }
                else
                {
                    TempData["Error"] = $"Deposit failed";
                    return(View());
                }
            }
            else
            {
                return(NotFound());
            }
        }
Пример #11
0
        public async Task <IActionResult> MakeADeposit(DepositViewModel deposit)
        {
            Customer customer = new Customer();

            customer = await _context.customers.FirstOrDefaultAsync(c => c.FirstName == deposit.ClientFirstName && c.LastName == deposit.ClientLastName);

            if (customer == null)
            {
                return(NotFound());
            }
            var accounts = await _context.accounts.ToListAsync();

            bool transaction_success = false;

            foreach (var client_account in accounts)
            {
                if (client_account.Id.Equals(deposit.AccountId))
                {
                    transaction_success             = true;
                    client_account.Account_Balance += deposit.Amount;
                    break;
                }
            }
            if (transaction_success)
            {
                await _context.SaveChangesAsync();

                return(View("Success"));
            }
            return(View("Failed"));
        }
Пример #12
0
        //Deposit adds money to current user state
        public static bool Deposit(DepositViewModel deposit)
        {
            bool flag = false;

            if (deposit.Amount <= 0)
            {
                flag = false;
            }
            else
            {
                flag = true;
                using (NmoorEntity db = new NmoorEntity())
                {
                    Transaction transaction = new Transaction();
                    var         amount      = db.User.Where(u => u.username.Equals(deposit.Username)).FirstOrDefault();
                    amount.balance += deposit.Amount;

                    transaction.username          = deposit.Username;
                    transaction.transactionType   = "Deposit";
                    transaction.amount            = deposit.Amount;
                    transaction.dateOfTransaction = DateTime.Now;
                    transaction.timeOfTransaction = TimeSpan.FromSeconds(60);
                    transaction.status            = "Success";
                    db.Transaction.Add(transaction);

                    db.Entry(amount).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            return(flag);
        }
Пример #13
0
        public async Task <ActionResult> Create(AllDepositViewModel model)
        {
            try
            {
                DepositViewModel deposit = new DepositViewModel()
                {
                    UserId     = Convert.ToInt32(HttpContext.Session.GetInt32("IdUser")),
                    Ativo      = false,
                    Value      = model.ValorDeposito,
                    CurrencyId = model.Moedas,
                    UserWallet = model.WalletGuid,
                    Guid       = model.WalletGuid,
                    BankId     = model.SelectBancos
                };

                string json = JsonConvert.SerializeObject(deposit);

                var resp = await ApiClient.PostAsync(GetUri("deposit"), Headers(json));

                if (resp.IsSuccessStatusCode)
                {
                    Success("Deposito realizado com sucesso");
                    return(RedirectToAction("Index", "Account"));
                }
            }
            catch
            {
            }

            Warning("Houve um problema, por favor tente novamente");
            return(View(model));
        }
Пример #14
0
        public async Task Deposit_Given_InvalidAccount_Then_ReturnNotFound()
        {
            // Arrange
            var mockService = new Mock <IAccountAppService>();

            var invalidDepositViewModel = new DepositViewModel()
            {
                AccountNumber = 0,
                Agency        = 0
            };

            var sourceAccount = invalidDepositViewModel.AccountNumber;

            mockService.Setup(service => service.GetByAccountNumberAndAgencyAsync(
                                  invalidDepositViewModel.AccountNumber,
                                  invalidDepositViewModel.Agency
                                  )).ReturnsAsync((Account)null);

            var controller = new AccountController(mockService.Object);

            // Act
            var result = await controller.Deposit(invalidDepositViewModel);

            // Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }
Пример #15
0
        public async Task <bool> CreateDepositAsync(DepositViewModel model, AppUserViewModel user)
        {
            try
            {
                if (model.Amount < 0)
                {
                    return(false);
                }

                var transaction = await _transactionService.CreateTransactionAsync(user.Id, model.Amount, TransactionType.Deposit);

                if (transaction)
                {
                    var deposit = _mapper.Map <DepositViewModel, Deposit>(model);
                    deposit.UserId    = user.Id;
                    deposit.CreatedAt = DateTime.Now;
                    user.Balance     += model.Amount;
                    await Add(deposit);

                    var us = _mapper.Map <AppUserViewModel, AppUser>(user);
                    DbContext.Users.Attach(us);
                    DbContext.Entry(us).State = EntityState.Modified;
                    return(await _unitOfWork.Commit());
                }
            }
            catch (Exception e)
            {
            }

            return(false);
        }
Пример #16
0
        public ActionResult NewDeposit(int ContributorId)
        {
            DepositViewModel dvm = new DepositViewModel();

            dvm.ContributorId = ContributorId;
            return(View(dvm));
        }
Пример #17
0
        public ActionResult Reports()
        {
            if (Session["userName"] != null)
            {
                DepositViewModel dvm = new DepositViewModel();
                dvm.DepositModelList = dal.GetTodayDeposits();

                var bankAccount = dal.GetBanks();
                ViewBag.BankAccount = new SelectList(bankAccount, "Id", "BankName");

                var gameType = dal.GetGameTypes();
                ViewBag.GameType = new SelectList(gameType, "Id", "GameType");

                var status = from Status s in Enum.GetValues(typeof(Status)) select new { ID = (int)s, Name = s.ToString() };
                ViewBag.Status = new SelectList(status, "ID", "Name");

                dvm.Message       = Session["message"] != null ? Session["message"].ToString() : null;
                dvm.RequestStatus = Session["requestStatus"] != null ? Session["requestStatus"].ToString() : null;
                Session.Remove("message");
                Session.Remove("requestStatus");

                return(View(dvm));
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }
Пример #18
0
        public async Task ReturnsViewResult_WhenCalled()
        {
            // Arrange
            var cardServiceMock        = new Mock <ICardService>();
            var userBalServiceMock     = new Mock <IUserBalanceService>();
            var transactionServiceMock = new Mock <ITransactionService>();
            var userManagerMock        = SetupUserManagerMock();

            var controller = SetupController(cardServiceMock, userBalServiceMock, transactionServiceMock, userManagerMock);

            var model = new DepositViewModel()
            {
                Currency = Currency.BGN
            };

            var user    = controller.User;
            var appUser = new User()
            {
                UserName = "******"
            };

            userManagerMock
            .Setup(u => u.GetUserAsync(user))
            .ReturnsAsync(appUser);

            // Act
            var result = await controller.Index();

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Пример #19
0
        public IActionResult Post([FromBody] DepositViewModel deposit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var transaction = new Transaction()
            {
                AccountId   = _accountId,
                Date        = DateTime.Now,
                Description = "Deposit",
                Amount      = deposit.Amount,
                Type        = TransactionType.SameAccount,
                Status      = TransactionStatus.Authorized,
            };

            _logger.LogInformation($"Someone asked for a deposit");

            _repos.Transactions.Add(transaction);
            _repos.SaveAndApply();

            _dispatcher.Enqueue(transaction.TransactionId);

            var receipt = new DepositReceiptViewModel()
            {
                TransactionId = transaction.TransactionId,
                Amount        = transaction.Amount
            };

            return(Ok(receipt));
        }
Пример #20
0
        public ActionResult Index()
        {
            ContentManagementController cmc = new ContentManagementController();

            ViewBag.Contents = cmc.GetContentsByType(ContentType.DEPOSITTEXT).Contents;

            DepositViewModel dvm = new DepositViewModel();

            dvm.DepositModel         = new DepositModel();
            dvm.DepositModelList     = dal.GetLatestDeposits();
            dvm.WithdrawalModelList  = dal.GetLatestWithdrawals();
            dvm.BankDepositModelList = dal.GetBankDepositList();

            ViewBag.TogelText  = dal.GetContentsByType(ContentType.TOGELTEXT).Contents;
            ViewBag.TogelDate  = dal.GetContentsByType(ContentType.TOGELDATE).Contents;
            ViewBag.TogelTime  = dal.GetContentsByType(ContentType.TOGELTIME).Contents;
            ViewBag.TogelTitle = dal.GetContentsByType(ContentType.TOGELTITLE).Contents;

            var bankAccount = dal.GetBanks();

            ViewBag.BankAccount = new SelectList(bankAccount, "Id", "BankName");

            var gameType = dal.GetGameTypes();

            ViewBag.GameType = new SelectList(gameType, "Id", "GameType");

            return(View(dvm));
        }
Пример #21
0
        public IActionResult Deposit(DepositViewModel viewModel, int id, decimal amount)
        {
            if (ModelState.IsValid && amount > 0 && amount < 100001)
            {
                var dbTransaction = new Transactions();
                _dbContext.Transactions.Add(dbTransaction);

                var account        = _dbContext.Accounts.FirstOrDefault(r => r.AccountId == id);
                var currentBalance = account.Balance;

                dbTransaction.AccountId = id;
                dbTransaction.Amount    = amount;
                dbTransaction.Date      = DateTime.Now;
                dbTransaction.Balance   = currentBalance + amount;
                dbTransaction.Operation = "Deposit";
                dbTransaction.Type      = "Credit";
                account.Balance         = currentBalance + amount;
                _dbContext.SaveChanges();
                return(RedirectToAction("AccountIndex", "Account"));
            }

            var accounts = _dbContext.Accounts.FirstOrDefault(r => r.AccountId == id);

            viewModel.Balance = accounts.Balance;
            ModelState.AddModelError("Error", "Invalid amount");
            return(View(viewModel));
        }
Пример #22
0
        public ActionResult Deposit(DepositViewModel vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var db = ApplicationDbContext.Create();
                    var checkingAccount = db.CheckingAccounts.Where(ac => ac.AccountNumber == vm.AccountNumber).FirstOrDefault();
                    if (checkingAccount == null)
                    {
                        throw new Exception("Invalid Account!!");
                    }
                    db.Transactions.Add(new Transaction {
                        Amount = vm.Amount, TimeStamp = DateTime.Now, CheckingAccountId = checkingAccount.ID
                    });
                    checkingAccount.Balance += vm.Amount;

                    db.SaveChanges();
                    //return RedirectToAction("Index");
                    /////

                    var checkAcc = db.CheckingAccounts.Where(a => a.AccountNumber == vm.AccountNumber).FirstOrDefault();

                    /////
                    return(RedirectToAction("Index", "Banking"));
                }
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.ToString();
                return(View());
            }
        }
Пример #23
0
 public TransactionResponseModel Deposit(DepositViewModel model)
 {
     using (var unit = _unitOfWorkFactory.Create())
     {
         var result = Deposit(model, unit);
         unit.Save();
         return(result);
     }
 }
Пример #24
0
        public ActionResult Edit([Bind(Include = "Id,AccountId,Date,PayerType,Amount,MethodId,PayerId,Description")] DepositViewModel deposit, int?id)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }

                    if (!_db.TransactionsInfos.Any(x => x.Id == id))
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }

                    if (!ModelState.IsValid)
                    {
                        return(View(deposit));
                    }
                    var count = _db.TransactionsInfos
                                .Where(x => x.Id == id)
                                .Update(u => new TransactionsInfo
                    {
                        Date        = deposit.Date,
                        AccountTo   = deposit.AccountId,
                        PayerType   = deposit.PayerType,
                        PayerId     = deposit.PayerId,
                        Amount      = deposit.Amount,
                        MethodId    = deposit.MethodId,
                        Description = deposit.Description
                    });
                    if (count > 0)
                    {
                        _db.UpdateBalance(_db.BankAccounts.Find(deposit.AccountId), (double)deposit.Amount);
                    }
                    dbTransaction.Commit();
                    TempData["Toastr"] = Toastr.Updated;

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
                finally
                {
                    ViewBag.Accounts       = new SelectList(_db.BankAccounts.ToList(), "Id", "AccountName", deposit.AccountId);
                    ViewBag.PayerTypes     = Common.ToSelectList <PayerType>(deposit.PayerType);
                    ViewBag.PaymentMethods = new SelectList(_db.PaymentMethods.ToList(), "Id", "MethodName", deposit.MethodId);
                }
            }
        }
Пример #25
0
        public IActionResult Deposit([FromRoute] int id)
        {
            var viewModel = new DepositViewModel();
            var account   = _dbContext.Accounts.FirstOrDefault(r => r.AccountId == id);

            viewModel.Balance = account.Balance;

            return(View(viewModel));
        }
Пример #26
0
        public ActionResult Deposit(int accountId)
        {
            var model = new DepositViewModel()
            {
                AccountID = accountId
            };

            return(View(model));
        }
Пример #27
0
        public async Task <IActionResult> Deposit([FromBody] DepositViewModel model)
        {
            string id   = User.FindFirst("id").Value;
            User   user = await UserManager.FindByIdAsync(id);

            if (user == null)
            {
                return(Unauthorized());
            }

            PaymentResult result = null;

            switch (model.PaymentChannel)
            {
            case ChannelType.Paystack:
                if (!Env.IsDevelopment())
                {
                    string baseUrl = new Uri(HttpContext.Request.GetEncodedUrl()).GetBaseUrl();
                    Core.ONLINE_BASE_ADDRESS = baseUrl;
                }

                result = await PaymentService.UsePaystack(user, model.Amount);

                break;

            case ChannelType.Bank:
                BankAccount account = user.BankAccounts.FirstOrDefault(b => b.IsActive && b.Id == model.UserBankAccountId);

                // if (account == null) return NotFound("Invalid User Account Id");

                BankAccount platformAccount = DataContext.PlatformAccount.BankAccounts.FirstOrDefault(b => b.IsActive && b.Id == model.PlatformBankAccountId);

                if (platformAccount == null)
                {
                    return(NotFound("Invalid Platform Account Id"));
                }

                result = await PaymentService.UseBank(user, model.Amount, model.Date, account, platformAccount, model.Description);

                break;
            }

            switch (result.Status)
            {
            case PaymentStatus.Redirected:
                return(Accepted(result.Message, result.Message));

            case PaymentStatus.Success:
                return(Ok());

            case PaymentStatus.Pending:
                return(Accepted());

            default: return(BadRequest(result.Message));
            }
        }
Пример #28
0
        public async Task <ActionResult> DepositMoney(DepositViewModel model, string userId)
        {
            var result = await _users.DepositMoney(model.Amount, userId);

            if (result.Succeeded)
            {
                return(RedirectToAction("UserInfo"));
            }
            return(RedirectToAction("DepositMoney", new { message = result.Message }));
        }
Пример #29
0
        public async Task <TransactionResponseModel> DepositAsync(DepositViewModel model)
        {
            using (var unit = _unitOfWorkFactory.Create())
            {
                var result = await DepositAsync(model, unit);

                var saveResult = unit.SaveAsync().Result;
                return(HandleSaving(saveResult, result, unit, model.AccountNumber));
            }
        }
Пример #30
0
        public async Task <IActionResult> DepositTransaction(DepositViewModel depositModel)
        {
            var response = await _httpClient.PostAsync <TransactionResponse>("api/Transaction/Deposit", depositModel);

            if (!response.IsSuccess)
            {
                var errorMessage = ErrorMessageResolver.GetErrorMessage(response.ErrorCode);
                return(RedirectToAction("Deposit", new { id = depositModel.AccountId, err = errorMessage }));
            }
            return(RedirectToAction("Detail", "Account", new { id = depositModel.AccountId }));
        }