Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.Rendering;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Identity;
- using Microsoft.Extensions.DependencyInjection;
- public class ExampleController : Controller
- {
- private readonly ApplicationDbContext _context;
- private readonly IServiceProvider _serviceProvider;
- public ExampleController(ApplicationDbContext context, IServiceProvider serviceProvider)
- {
- _context = context;
- _serviceProvider = serviceProvider;
- }
- // GET: Items
- public async Task<IActionResult> Index()
- {
- var RoleManager = _serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
- var UserManager = _serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
- var userId = await UserManager.FindByEmailAsync(User.Identity.Name);
- var applicationDbContext = _context.Items
- .Where(x => x.ApplicationUserId == userId.Id );
- return View(await applicationDbContext.ToListAsync());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement