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