Esempio n. 1
0
        public async Task <ActionResult <autopayment> > Frozen([FromBody] int id, [FromHeader] string apiToken)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(apiToken);

            var client = ActionResult as OkObjectResult;

            if (client != null)
            {
                int userId      = (int)client.Value;
                var autopayment = await _context.autopayment.Where(x => x.sender_id == userId && x.id_autopayment == id).FirstOrDefaultAsync();

                if (autopayment == null)
                {
                    return(null);
                }

                autopayment.freezing = true;

                autopayment.comm = "Автоплатеж заморожен по желанию пользователя. Дата - " + DateTime.Today.ToString("g");

                //нужно, чтобы было состояние "редактируется"

                _context.Entry(autopayment).State = EntityState.Modified;

                await _context.SaveChangesAsync();

                return(Ok("Операция заморозки карты "));
            }
            else
            {
                return(NotFound("Данный пользователь недоступен"));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult <request> > PostrequestAdd([FromBody] RequestAdd ra, [FromHeader] string api_token)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(api_token);

            var OkObjectResult = ActionResult as OkObjectResult;

            int userId = (int)OkObjectResult.Value;

            if (_context.client.Any(x => x.id_client == userId))
            {
                request new_request = new request {
                    income            = ra.income,
                    place_job         = ra.place_job,
                    client_id         = userId,
                    status_request_id = 3,
                    type_acc_id       = ra.type_account_id
                };

                _context.request.Add(new_request);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("Getrequest", new { id = new_request.id_request }, new_request));
            }
            else
            {
                return(NotFound());
            }
        }
Esempio n. 3
0
        public async Task <ActionResult <autopayment> > Deleteautopayment(int id, [FromHeader] string apiToken)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(apiToken);

            var client = ActionResult as OkObjectResult;

            if (client != null)
            {
                var autopayment = await _context.autopayment.Where(x => x.id_autopayment == id && x.sender_id == (int)client.Value).FirstAsync();

                if (autopayment == null)
                {
                    return(NotFound());
                }

                _context.autopayment.Remove(autopayment);
                await _context.SaveChangesAsync();

                return(autopayment);
            }
            else
            {
                return(NotFound("Авторизуйтесь, чтобы внести изменения"));
            }
        }
Esempio n. 4
0
        public async Task <ActionResult <request> > PostrequestApproval([FromBody] RequestApproval ra, [FromHeader] string api_token)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(api_token);

            var OkObjectResult = ActionResult as OkObjectResult;

            int userId = (int)OkObjectResult.Value;

            int?credit_rate = null;

            if (_context.request.Any(x => x.id_request == ra.id))
            {
                var app_request = _context.request.Where(x => x.id_request == ra.id).ToList();
                if (app_request[0].status_request_id == 1)
                {
                    return(Ok());
                }
                else
                {
                    app_request[0].status_request_id = ra.s_r_id;
                    await _context.SaveChangesAsync();

                    var UpdatedApp = await _context.request.FindAsync(ra.id);                           //1-accepted 2-rejected 3-approval

                    if (ra.s_r_id == 1)
                    {
                        AccsController Acc = new AccsController(_context);
                        if (app_request[0].type_acc_id == 3)
                        {
                            credit_rate = 2;
                        }
                        Acc new_acc = new Acc
                        {
                            balance_acc    = credit_rate == 2 ? _context.credit_rate.Where(x => x.id_credit_rate == 2).ToList()[0].credit_limit:0,
                            credit_rate_id = credit_rate,
                            client_id      = app_request[0].client_id,
                            date_open_acc  = DateTime.Now,
                            date_close_acc = DateTime.Now.AddYears(4),
                            status_acc_id  = 1,                                                           //1-open 2-frozen 3-closed
                            type_acc_id    = app_request[0].type_acc_id
                        };
                        await Acc.PostAcc(new_acc);
                    }
                    return(UpdatedApp);
                }
            }
            else
            {
                return(NotFound());
            }
        }
Esempio n. 5
0
        public async Task <ActionResult <payment> > Postpayment([FromBody] payment payment, [FromHeader] string api_token)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(api_token);

            var OkObjectResult = ActionResult as OkObjectResult;

            int    status           = 0;
            string rejection_reason = null;

            int UserId = (int)OkObjectResult.Value;

            //при проведении платежа добавить его в истроию
            //если на счету не хватает декнег отменяем платеж и меняем статус
            //если хватает списываем деньги, добавляем деньги и меняем статус платежа
            _context.payment.Add(payment);
            await _context.SaveChangesAsync();

            if (_context.Acc.Any(x => x.id_acc == payment.sender_id && x.balance_acc >= payment.sum))
            {
                status = 1;
                //Списать
                var AccSenderBalanceUpdate = _context.Acc.Where(x => x.id_acc == payment.sender_id).ToList();
                AccSenderBalanceUpdate[0].balance_acc -= payment.sum;
                await _context.SaveChangesAsync();

                //добавить
                var AccRecipientBalanceUpdate = _context.Acc.Where(x => x.id_acc == payment.recipient_id).ToList();
                AccRecipientBalanceUpdate[0].balance_acc += payment.sum;
                await _context.SaveChangesAsync();
            }
            else
            {
                status           = 2;
                rejection_reason = "Недостаточно средств на счету!";
            }

            payment_historyController PaymentHistory = new payment_historyController(_context);
            payment_history           new_payment    = new payment_history
            {
                payment_id        = payment.id_payment,
                status_payment_id = status,
                date_check        = DateTime.Now,
                rejection         = rejection_reason
            };
            await PaymentHistory.Postpayment_history(new_payment);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("Getpayment", new { id = payment.id_payment }, payment));
        }
Esempio n. 6
0
        public async Task <ActionResult <IEnumerable <Acc> > > GetAcc([FromHeader] string api_token)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(api_token);

            var OkObjectResult = ActionResult as OkObjectResult;


            return(await _context.Acc
                   .Include(x => x.client_)
                   .Include(x => x.credit_rate_)
                   .Include(x => x.status_acc_)
                   .Include(x => x.type_acc_)
                   .Where(x => x.client_id == (int)OkObjectResult.Value)
                   .ToListAsync());
        }
Esempio n. 7
0
        public async Task <IActionResult> Putautopayment(int id, [FromBody] autopayment autopayment, [FromHeader] string apiToken)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(apiToken);

            var client = ActionResult as OkObjectResult;

            if (client != null)
            {
                if (id != autopayment.id_autopayment)
                {
                    return(BadRequest());
                }

                _context.Entry(autopayment).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!autopaymentExists(id, (int)client.Value))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(NoContent());
            }
            else
            {
                return(NotFound("Авторизуйтесь, чтобы внести изменения"));
            }
        }
Esempio n. 8
0
        public async Task <ActionResult <autopayment> > Getautopayment(int id, [FromHeader] string apiToken)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(apiToken);

            var client = ActionResult as OkObjectResult;

            if (client != null)
            {
                int userId      = (int)client.Value;
                var autopayment = await _context.autopayment.Where(x => x.sender_id == userId && x.id_autopayment == id).FirstOrDefaultAsync();

                if (autopayment == null)
                {
                    return(null);
                }
                return(autopayment);
            }
            else
            {
                return(NotFound("Данный пользователь недоступен"));
            }
        }
Esempio n. 9
0
        public async Task <ActionResult <IEnumerable <autopayment> > > getMyAutoPayments([FromHeader] string apiToken)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(apiToken);

            var client = ActionResult as OkObjectResult;

            if (client != null)
            {
                int userId       = (int)client.Value;
                var autopayments = await _context.autopayment.Where(x => x.sender_id == userId).FirstAsync();

                if (autopayments == null)
                {
                    return(null);
                }
                return(Ok(autopayments));
            }
            else
            {
                return(NotFound("Пользователя с таким токеном нет"));
            }
        }
Esempio n. 10
0
        public async Task <ActionResult <autopayment> > Postautopayment([FromBody] autopayment autopayment, [FromHeader] string apiToken)
        {
            AuthController newAuth      = new AuthController(_context);
            var            ActionResult = await newAuth.getId(apiToken);

            var client = ActionResult as OkObjectResult;

            if (client != null)
            {
                var acc = await _context.Acc.Where(x => x.client_id == (int)client.Value).FirstAsync();

                if (acc != null)
                {
                    if ((acc.balance_acc - autopayment.sum) >= acc.balance_acc)
                    {
                        _context.autopayment.Add(autopayment);
                        await _context.SaveChangesAsync();

                        return(CreatedAtAction("Getautopayment", new { id = autopayment.id_autopayment }, autopayment));
                    }
                    else
                    {
                        NotFound("На счету не достаточно средств, чтобы добавить автоплатеж");
                    }
                }
                else
                {
                    NotFound("Такого счета нет");
                }
            }
            else
            {
                return(NotFound("Авторизуйтесь, чтобы внести изменения"));
            }
            return(NoContent());
        }