public async Task <IActionResult> Unregister(string id) { var dbContext = new sirmotoContext(); var usr = await GetCurrentUserAsync(); var usrId = usr.Id; var device = await dbContext.SirmotoDevices.Where(z => z.Id == Int32.Parse(id)).ToListAsync(); if (device.Count == 0) { return(NotFound("[WARN] Device not found")); } else if (device[0].UserId != usr.Id) { return(Forbid("[ERRO] Access denied")); } else { dbContext.Remove(device[0]); await dbContext.SaveChangesAsync(); } return(new ObjectResult("[INFO] Unregistered devie no " + id)); }
public async Task <IActionResult> DeleteTrans(string id) { var dbContext = new sirmotoContext(); var usr = await GetCurrentUserAsync(); var usrId = usr.Id; var transactions = await dbContext.Transactions.Where(z => z.Id == Int32.Parse(id)).ToListAsync(); if (transactions[0] == null) { return(NotFound("Transaction not found")); } else if (transactions[0].State != "DONE" || transactions[0].State != "FINAL") { dbContext.Remove(transactions[0]); await dbContext.SaveChangesAsync(); return(new ObjectResult("Cancelled transaction id " + id)); } else { return(Forbid("Transaction cannot be cancelled, id " + id)); } }