diff --git a/src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoriesListQuery.cs b/src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoriesListQuery.cs new file mode 100644 index 0000000..8585c1d --- /dev/null +++ b/src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoriesListQuery.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Codidact.Core.Application.Common.Contracts; +using Codidact.Core.Application.Common.Interfaces; +using Codidact.Core.Domain.Entities; +using Microsoft.Extensions.Logging; + +namespace Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery +{ + /// + /// Returns a list of categories with minimal data + /// + public class ShortCategoriesListQuery : IRequestHandler> + { + private readonly IApplicationDbContext _context; + private readonly ILogger _logger; + + public ShortCategoriesListQuery(IApplicationDbContext context, ILogger logger) + { + _context = context; + _logger = logger; + } + + public Task> Handle(ShortCategoriesListRequest message) + { + _logger.LogInformation($"{DateTime.UtcNow.ToString("u")} - Starting to handle request for Questions List"); + + return Task.FromResult(_context.Categories.Select(MapCategoryToShortCategory).AsEnumerable()); + } + + private ShortCategoryResult MapCategoryToShortCategory(Category category) + { + return new ShortCategoryResult + { + Name = category.DisplayName + }; + } + } +} diff --git a/src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoriesListRequest.cs b/src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoriesListRequest.cs new file mode 100644 index 0000000..b9897f0 --- /dev/null +++ b/src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoriesListRequest.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; +using Codidact.Core.Application.Common.Contracts; + +namespace Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery +{ + public class ShortCategoriesListRequest : IRequest> + { + } +} diff --git a/src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoryResult.cs b/src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoryResult.cs new file mode 100644 index 0000000..79ba0b8 --- /dev/null +++ b/src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoryResult.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery +{ + public class ShortCategoryResult + { + public string Name { get; set; } + } +} diff --git a/src/Application/DependencyInjection.cs b/src/Application/DependencyInjection.cs index db1c570..0a5269b 100644 --- a/src/Application/DependencyInjection.cs +++ b/src/Application/DependencyInjection.cs @@ -3,6 +3,7 @@ using Codidact.Core.Application.Questions.Queries.QuestionsQuery; using Microsoft.Extensions.DependencyInjection; using FluentValidation; +using Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery; namespace Codidact.Core.Application { @@ -23,6 +24,7 @@ public static IServiceCollection AddApplication(this IServiceCollection services services.AddScoped(); services.AddScoped(); + services.AddScoped(); return services; } diff --git a/src/WebApp/Pages/Questions.cshtml b/src/WebApp/Pages/Questions.cshtml index 40411e2..97c3b9e 100644 --- a/src/WebApp/Pages/Questions.cshtml +++ b/src/WebApp/Pages/Questions.cshtml @@ -16,9 +16,6 @@

@Model.Result.Category.DisplayName @localizer["Questions_title"]

@Model.Result.Category.ShortExplanation

-
@localizer["Best_sort"] diff --git a/src/WebApp/Pages/Shared/CategoryHeader.cshtml b/src/WebApp/Pages/Shared/CategoryHeader.cshtml new file mode 100644 index 0000000..893ec6a --- /dev/null +++ b/src/WebApp/Pages/Shared/CategoryHeader.cshtml @@ -0,0 +1,37 @@ +@using Microsoft.AspNetCore.Mvc.Localization +@using Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery +@inject IViewLocalizer LayoutLocalizer +@inject ShortCategoriesListQuery query +@{ + var results = await query.Handle(new ShortCategoriesListRequest()); + string activeCategory; + var routeValue = ViewContext.RouteData.Values["category"]; + if (routeValue != null) + { + activeCategory = routeValue.ToString(); + } + else + { + activeCategory = results.Select(cat => cat.Name).FirstOrDefault(); + } +} +
+
+
+ @foreach (var category in results) + { + @category.Name + } +
+
+ +
diff --git a/src/WebApp/Pages/Shared/_Header.cshtml b/src/WebApp/Pages/Shared/_Header.cshtml new file mode 100644 index 0000000..f902c91 --- /dev/null +++ b/src/WebApp/Pages/Shared/_Header.cshtml @@ -0,0 +1,45 @@ +@using Microsoft.AspNetCore.Mvc.Localization +@inject IViewLocalizer LayoutLocalizer + +
+
+
+ Codidact +
+
+
+ @if (!User.Identity.IsAuthenticated) + { + @LayoutLocalizer["Sign_in_button"] + } + else + { +
+ +
+ } + @LayoutLocalizer["On_github_button"] + + + + + + + +
+
+
+ + + diff --git a/src/WebApp/Pages/Shared/_Layout.cshtml b/src/WebApp/Pages/Shared/_Layout.cshtml index 71829bc..9895469 100644 --- a/src/WebApp/Pages/Shared/_Layout.cshtml +++ b/src/WebApp/Pages/Shared/_Layout.cshtml @@ -7,56 +7,12 @@ Codidact - @ViewData["Title"] - + -
-
-
- Codidact -
-
- @LayoutLocalizer["Questions_title"] - @LayoutLocalizer["Tags_title"] - @LayoutLocalizer["Users_title"] -
- @if (!User.Identity.IsAuthenticated) - { - @LayoutLocalizer["Sign_in_button"] - } - else - { -
- -
- } - @LayoutLocalizer["On_github_button"] - - - - - - - -
-
-
- + +
@RenderBody()
diff --git a/src/WebApp/Resources/Pages/QuestionsModel.en.resx b/src/WebApp/Resources/Pages/QuestionsModel.en.resx index 285fd9e..908d455 100644 --- a/src/WebApp/Resources/Pages/QuestionsModel.en.resx +++ b/src/WebApp/Resources/Pages/QuestionsModel.en.resx @@ -129,10 +129,6 @@ best Sort of type Best - - New question - The new question button - oldest Sort of type oldest diff --git a/src/WebApp/Resources/Pages/Shared/CategoryHeader.en.resx b/src/WebApp/Resources/Pages/Shared/CategoryHeader.en.resx new file mode 100644 index 0000000..bd7a15e --- /dev/null +++ b/src/WebApp/Resources/Pages/Shared/CategoryHeader.en.resx @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + New question + The new question button + + + on GitHub + The button for github on the layout header + + + Questions + The questions button on the header of the layout + + + Sign In + The sign in button in the layout header + + + Sign Out + The sign out button in the layout header + + + Tags + The tags button on the title of the header in the layout + + + Users + The users button on the title of the header in the layout + + \ No newline at end of file diff --git a/src/WebApp/Resources/Pages/Shared/_Header.en.resx b/src/WebApp/Resources/Pages/Shared/_Header.en.resx new file mode 100644 index 0000000..e704f23 --- /dev/null +++ b/src/WebApp/Resources/Pages/Shared/_Header.en.resx @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + on GitHub + The button for github on the layout header + + + Questions + The questions button on the header of the layout + + + Sign In + The sign in button in the layout header + + + Sign Out + The sign out button in the layout header + + + Tags + The tags button on the title of the header in the layout + + + Users + The users button on the title of the header in the layout + + \ No newline at end of file diff --git a/src/WebApp/Resources/Pages/Shared/_Layout.en.resx b/src/WebApp/Resources/Pages/Shared/_Layout.en.resx index c3c4d6d..4f47000 100644 --- a/src/WebApp/Resources/Pages/Shared/_Layout.en.resx +++ b/src/WebApp/Resources/Pages/Shared/_Layout.en.resx @@ -117,32 +117,8 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - on GitHub - The button for github on the layout header - Privacy The footer privacy button on the layout - - Questions - The questions button on the header of the layout - - - Sign In - The sign in button in the layout header - - - Sign Out - The sign out button in the layout header - - - Tags - The tags button on the title of the header in the layout - - - Users - The users button on the title of the header in the layout - \ No newline at end of file diff --git a/src/WebApp/WebApp.csproj b/src/WebApp/WebApp.csproj index 50e5362..6b5cb3e 100644 --- a/src/WebApp/WebApp.csproj +++ b/src/WebApp/WebApp.csproj @@ -30,6 +30,12 @@ PublicResXFileCodeGenerator + + PublicResXFileCodeGenerator + + + PublicResXFileCodeGenerator + PublicResXFileCodeGenerator diff --git a/src/WebApp/wwwroot/css/site.css b/src/WebApp/wwwroot/css/site.css index 5f28270..535dc74 100644 --- a/src/WebApp/wwwroot/css/site.css +++ b/src/WebApp/wwwroot/css/site.css @@ -1 +1,3 @@ - \ No newline at end of file +.header{ + margin-bottom:0px; +} \ No newline at end of file