Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Mvc.Rendering;
  7. using Microsoft.EntityFrameworkCore;
  8. using Microsoft.AspNetCore.Authorization;
  9. using Microsoft.AspNetCore.Identity;
  10. using Microsoft.Extensions.DependencyInjection;
  11.  
  12. public class ExampleController : Controller
  13. {
  14. private readonly ApplicationDbContext _context;
  15. private readonly IServiceProvider _serviceProvider;
  16.  
  17. public ExampleController(ApplicationDbContext context, IServiceProvider serviceProvider)
  18. {
  19. _context = context;
  20. _serviceProvider = serviceProvider;
  21. }
  22.  
  23. // GET: Items
  24. public async Task<IActionResult> Index()
  25. {
  26. var RoleManager = _serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
  27. var UserManager = _serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
  28. var userId = await UserManager.FindByEmailAsync(User.Identity.Name);
  29.  
  30. var applicationDbContext = _context.Items
  31. .Where(x => x.ApplicationUserId == userId.Id );
  32.  
  33. return View(await applicationDbContext.ToListAsync());
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement