diff --git a/Library.Encyclopedia.API/Controllers/EncylopediaController.cs b/Library.Encyclopedia.API/Controllers/EncylopediaController.cs index 143c547..1338864 100644 --- a/Library.Encyclopedia.API/Controllers/EncylopediaController.cs +++ b/Library.Encyclopedia.API/Controllers/EncylopediaController.cs @@ -4,12 +4,14 @@ using Library.Encyclopedia.Entity.Interfaces; using Library.Encyclopedia.Entity.Models; using Library.Encyclopedia.Entity.Models.External; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; +using System.DirectoryServices.AccountManagement; using System.Threading.Tasks; namespace Library.Encyclopedia.Controllers @@ -35,6 +37,25 @@ public EncylopediaController(ILogger logger, IApplication this.mainDataAccess = new MainDataAccess(dbContext, configuration); } + [HttpGet("Login")] + [Authorize(Roles = @"EncyclopediaAdministrators")] + public IActionResult Login() + { + try + { + using (var context = new PrincipalContext(ContextType.Domain | ContextType.Machine)) + { + var usr = UserPrincipal.FindByIdentity(context, this.HttpContext.User.Identity.Name); + return Ok(usr.DisplayName); + } + } + catch (Exception ex) + { + _logger.LogError(ex, $"an error has occured {ex.Message}"); + throw; + } + } + /// /// Get all items based on search query /// @@ -86,7 +107,7 @@ public async Task GetByCategory(string category, { try { - var response = await mainDataAccess.GetByCategoryAsync(category, offset, limit,previewSize, asc); + var response = await mainDataAccess.GetByCategoryAsync(category, offset, limit, previewSize, asc); if (response == null) { @@ -120,7 +141,7 @@ public async Task GetByStartingAlphabet(char alphabet, { try { - var response = await mainDataAccess.GetByAlphabetAsync(alphabet, offset, limit,previewSize, asc); + var response = await mainDataAccess.GetByAlphabetAsync(alphabet, offset, limit, previewSize, asc); if (response == null) { diff --git a/Library.Encyclopedia.API/Library.Encyclopedia.API.csproj b/Library.Encyclopedia.API/Library.Encyclopedia.API.csproj index 5216164..37b1980 100644 --- a/Library.Encyclopedia.API/Library.Encyclopedia.API.csproj +++ b/Library.Encyclopedia.API/Library.Encyclopedia.API.csproj @@ -4,6 +4,10 @@ netcoreapp3.1 + + + + diff --git a/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs b/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs index 3f7d650..20fa987 100644 --- a/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs +++ b/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs @@ -178,6 +178,7 @@ public async Task CreateAsync(Main model) // assign a random id model.Id = Guid.NewGuid(); + model.Category = model.Category == string.Empty ? null : model.Category; model = ReplaceInternalLinks(model); model = ReplaceLineBreaks(model); @@ -329,7 +330,7 @@ public async Task
UpdateAsync(Guid id, MainUpdateModel model) entry.RawDescription = StripHTML(entry.RawDescription); } - entry.Category = model.Category ?? entry.Category; + entry.Category = model.Category == null ? entry.Category : model.Category == string.Empty ? null : model.Category; _dbcontext.Main.Update(entry); await _dbcontext.SaveChanges();