Пример #1
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("Авторизуйтесь, чтобы внести изменения"));
            }
        }
Пример #2
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("Данный пользователь недоступен"));
            }
        }
Пример #3
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("Пользователя с таким токеном нет"));
            }
        }
Пример #4
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());
        }