using System.Security.Claims; using DrinkRateAPI.ApiModels.UserProfile; using DrinkRateAPI.Contexts; using DrinkRateAPI.DbEntities; using DrinkRateAPI.DbEntities; using DrinkRateAPI.Exceptions; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace DrinkRateAPI.Services; public class UserProfileService(ApplicationDbContext context, ApplicationUserService applicationUserService) { private ApplicationDbContext _context = context; private ApplicationUserService _applicationUserService = applicationUserService; public bool IsUserProfileAdmin(DbUserProfile userProfile) { return userProfile.IsAdmin; } public async Task ChangeUserAdminStatusAsync(string userId, bool changeStatusTo) { var userProfile = GetUserProfileById(userId); userProfile.IsAdmin = changeStatusTo; _context.UserProfiles.Update(userProfile); await _context.SaveChangesAsync(); return userProfile; } public async Task PutUserProfileAsync(UserProfilePut userProfile, ClaimsPrincipal identity) { var profile = _applicationUserService.UserProfileByApplicationUserAsync(identity); return new(); } public DbUserProfile GetUserProfileById(string userId) { var userProfile = _context.UserProfiles.FirstOrDefault(x => x.Id.ToString() == userId); return userProfile ?? throw new NotFoundException(); } }