Пример #1
0
        public async Task <DepositMoneyResponse> DepositMoney(DepositMoneyRequest request)
        {
            //Check Amount
            var upperLimit = (await _paramService.FindById(GlobalParams.ParamDepositMoneyUpperLimit)).Value;
            var lowerLimit = (await _paramService.FindById(GlobalParams.ParamDepositMoneyLowerLimit)).Value;
            var step       = (await _paramService.FindById(GlobalParams.ParamDepositMoneyStep)).Value;

            if (request.Amount > upperLimit || request.Amount < lowerLimit || (request.Amount / step) > GlobalParams.AcceptableDecimalMistake)
            {
                throw new HttpStatusCodeException(HttpStatusCode.BadRequest, "amount must be between " + lowerLimit + " and " + upperLimit + " and must be multiple of " + step);
            }

            //Find student in database
            var student = await _studentService.FindById(request.StudentId);

            var originalBalance = student.AccountBalance;

            //Change student's balance
            student.AccountBalance += request.Amount;

            var resultBalance = student.AccountBalance;

            //Update information in database
            student = await _repoWrapper.Student.UpdateAsync(student, student.StudentId);

            //Create MoneyTransaction entity
            var moneyTransaction = DepositMoneyRequest.EntityFromRequest(originalBalance, resultBalance, request);

            //Create MoneyTransaction in database
            moneyTransaction = await _repoWrapper.MoneyTransaction.CreateAsync(moneyTransaction);

            //Return View Model
            return(DepositMoneyResponse.ResponseFromModel(moneyTransaction));
        }
Пример #2
0
        public async Task <ActionResult <DepositMoneyResponse> > DepositMoney(DepositMoneyRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(await _moneyTransactionService.DepositMoney(request));
        }