| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using Microsoft.AspNetCore.Identity; |
| | | 3 | | using Microsoft.AspNetCore.Mvc; |
| | | 4 | | using Microsoft.EntityFrameworkCore; |
| | | 5 | | using OzonDomains.Models; |
| | | 6 | | using OzonDomains.Models.AccessControl; |
| | | 7 | | using OzonOrdersWeb.ViewModels.UserViewModels; |
| | | 8 | | using OzonRepositories.Context; |
| | | 9 | | using OzonRepositories.Context.Identity; |
| | | 10 | | using Services.CacheServices.Cache.UserCacheService; |
| | | 11 | | |
| | | 12 | | namespace OzonOrdersWeb.Controllers |
| | | 13 | | { |
| | | 14 | | [Authorize] |
| | | 15 | | [Area("Studio2")] |
| | | 16 | | public class ProfileController : Controller |
| | | 17 | | { |
| | | 18 | | private readonly UserManager<CustomIdentityUser> _userManager; |
| | | 19 | | private readonly IUserCacheService _userCacheService; |
| | | 20 | | private readonly ApplicationDbContext _context; |
| | | 21 | | |
| | 0 | 22 | | public ProfileController( |
| | 0 | 23 | | UserManager<CustomIdentityUser> userManager, |
| | 0 | 24 | | IUserCacheService userCacheService, |
| | 0 | 25 | | ApplicationDbContext context) |
| | | 26 | | { |
| | 0 | 27 | | _userManager = userManager; |
| | 0 | 28 | | _userCacheService = userCacheService; |
| | 0 | 29 | | _context = context; |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | public async Task<IActionResult> Index() |
| | | 33 | | { |
| | 0 | 34 | | var user = await _userCacheService.GetCachedUserAsync(User); |
| | 0 | 35 | | if (user == null) |
| | | 36 | | { |
| | 0 | 37 | | return NotFound(); |
| | | 38 | | } |
| | | 39 | | |
| | 0 | 40 | | var roles = await _userManager.GetRolesAsync(user); |
| | | 41 | | |
| | 0 | 42 | | AccessProfile? accessProfile = null; |
| | 0 | 43 | | if (user.AccessProfileId.HasValue) |
| | | 44 | | { |
| | 0 | 45 | | accessProfile = await _context.AccessProfiles |
| | 0 | 46 | | .Include(ap => ap.DataScopeSets) |
| | 0 | 47 | | .ThenInclude(s => s.Items) |
| | 0 | 48 | | .AsSplitQuery() |
| | 0 | 49 | | .FirstOrDefaultAsync(ap => ap.Id == user.AccessProfileId.Value); |
| | | 50 | | } |
| | | 51 | | |
| | 0 | 52 | | var appStatuses = await _context.AppStatuses.ToListAsync(); |
| | 0 | 53 | | var suppliers = await _context.Suppliers.ToListAsync(); |
| | 0 | 54 | | var ozonClients = await _context.OzonClients.ToListAsync(); |
| | 0 | 55 | | var warehouses = await _context.Warehouses.ToListAsync(); |
| | 0 | 56 | | var deliveryProviders = await _context.DeliveryProviders.ToListAsync(); |
| | | 57 | | |
| | 0 | 58 | | var viewModel = new UserProfileViewModel |
| | 0 | 59 | | { |
| | 0 | 60 | | User = user, |
| | 0 | 61 | | Roles = roles.ToList(), |
| | 0 | 62 | | AccessProfile = accessProfile, |
| | 0 | 63 | | AvailableOrderColumns = accessProfile?.AvailableOrderColumns ?? new List<string>(), |
| | 0 | 64 | | ScopeItems = accessProfile?.ScopeItems?.ToList() ?? new List<DataScopeSetItem>(), |
| | 0 | 65 | | AppStatuses = appStatuses, |
| | 0 | 66 | | Suppliers = suppliers, |
| | 0 | 67 | | OzonClients = ozonClients, |
| | 0 | 68 | | Warehouses = warehouses, |
| | 0 | 69 | | DeliveryProviders = deliveryProviders |
| | 0 | 70 | | }; |
| | | 71 | | |
| | 0 | 72 | | return View(viewModel); |
| | 0 | 73 | | } |
| | | 74 | | } |
| | | 75 | | } |