public async Task OnGet([FromServices] IdentityWebContext identity) { Items = await identity.Items .Include(e => e.Barangay) .AsNoTracking() .ToListAsync(); }
public async Task <IActionResult> OnGet([FromServices] IdentityWebContext dbContext, string id) { Id = id; if (!string.IsNullOrWhiteSpace(id)) { var data = await dbContext.Items.FirstOrDefaultAsync(e => e.ItemId == id); if (data == null) { return(NotFound("Item not found.")); } // get allowed barangays for current User var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var barangays = await dbContext.BarangayUserRoles.Where(e => e.UserId == userId).Select(e => e.BarangayId).ToListAsync(); if (!barangays.Contains(data.BarangayId)) { return(RedirectToPage("/NotAuthorizedToEditDevice")); } } return(Page()); }
public ItemController(IdentityWebContext dbContext, IOptions <ApiBehaviorOptions> apiBehaviorOptions) : base(apiBehaviorOptions) { _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); }