From 4b0b366c7e2f4b978efc2e93aacc78e00eea5c7d Mon Sep 17 00:00:00 2001 From: Misha Tarnortusky Date: Tue, 14 Apr 2020 15:38:32 -0400 Subject: [PATCH 1/4] Add cat header --- .../ShortCategoriesListQuery.cs | 41 ++++++++++++++++ .../ShortCategoriesListRequest.cs | 9 ++++ .../ShortCategoryResult.cs | 11 +++++ src/Application/DependencyInjection.cs | 2 + src/WebApp/Pages/Shared/CategoryHeader.cshtml | 13 +++++ .../Pages/Shared/CategoryHeader.cshtml.cs | 27 +++++++++++ src/WebApp/Pages/Shared/_Header.cshtml | 48 +++++++++++++++++++ src/WebApp/Pages/Shared/_Layout.cshtml | 47 +----------------- 8 files changed, 152 insertions(+), 46 deletions(-) create mode 100644 src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoriesListQuery.cs create mode 100644 src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoriesListRequest.cs create mode 100644 src/Application/Categories/Queries/ShortCategoriesListQuery/ShortCategoryResult.cs create mode 100644 src/WebApp/Pages/Shared/CategoryHeader.cshtml create mode 100644 src/WebApp/Pages/Shared/CategoryHeader.cshtml.cs create mode 100644 src/WebApp/Pages/Shared/_Header.cshtml 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/Shared/CategoryHeader.cshtml b/src/WebApp/Pages/Shared/CategoryHeader.cshtml new file mode 100644 index 0000000..491d394 --- /dev/null +++ b/src/WebApp/Pages/Shared/CategoryHeader.cshtml @@ -0,0 +1,13 @@ +@model Codidact.Core.WebApp.Pages.Shared.CategoryHeaderModel + +
+
+
+ @foreach (var category in Model.Categories) + { + @category.Name + } +
+
+
+
\ No newline at end of file diff --git a/src/WebApp/Pages/Shared/CategoryHeader.cshtml.cs b/src/WebApp/Pages/Shared/CategoryHeader.cshtml.cs new file mode 100644 index 0000000..782c21b --- /dev/null +++ b/src/WebApp/Pages/Shared/CategoryHeader.cshtml.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.Extensions.Logging; + +namespace Codidact.Core.WebApp.Pages.Shared +{ + public class CategoryHeaderModel : PageModel + { + private readonly ShortCategoriesListQuery _categoriesQuery; + private readonly ILogger _logger; + + public CategoryHeaderModel(ShortCategoriesListQuery categoriesQuery, ILogger logger) + { + _categoriesQuery = categoriesQuery; + _logger = logger; + } + + public IEnumerable Categories { get; set; } + + public async Task OnGetAsync(ShortCategoriesListRequest request) + { + Categories = await _categoriesQuery.Handle(new ShortCategoriesListRequest()); + } + } +} diff --git a/src/WebApp/Pages/Shared/_Header.cshtml b/src/WebApp/Pages/Shared/_Header.cshtml new file mode 100644 index 0000000..1d6ccc2 --- /dev/null +++ b/src/WebApp/Pages/Shared/_Header.cshtml @@ -0,0 +1,48 @@ +
+
+
+ Codidact +
+
+ Place holder 1 + Place holder 2 + Place holder 3 +
+ @if (!User.Identity.IsAuthenticated) + { + Sign In + } + else + { +
+ +
+ } + on GitHub + + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/src/WebApp/Pages/Shared/_Layout.cshtml b/src/WebApp/Pages/Shared/_Layout.cshtml index 73790ea..c8412c4 100644 --- a/src/WebApp/Pages/Shared/_Layout.cshtml +++ b/src/WebApp/Pages/Shared/_Layout.cshtml @@ -8,52 +8,7 @@ -
-
-
- Codidact -
-
- Place holder 1 - Place holder 2 - Place holder 3 -
- @if (!User.Identity.IsAuthenticated) - { - Sign In - } - else - { -
- -
- } - on GitHub - - - - - - - -
-
-
- +
@RenderBody()
From 055dd21030625a321a6ad6681f8ccce6e0ab5a5d Mon Sep 17 00:00:00 2001 From: Misha Tarnortusky Date: Wed, 15 Apr 2020 08:39:04 -0400 Subject: [PATCH 2/4] Fix partialview to display categories --- src/WebApp/Pages/Shared/CategoryHeader.cshtml | 11 +++++--- .../Pages/Shared/CategoryHeader.cshtml.cs | 27 ------------------- 2 files changed, 8 insertions(+), 30 deletions(-) delete mode 100644 src/WebApp/Pages/Shared/CategoryHeader.cshtml.cs diff --git a/src/WebApp/Pages/Shared/CategoryHeader.cshtml b/src/WebApp/Pages/Shared/CategoryHeader.cshtml index 491d394..bf6da67 100644 --- a/src/WebApp/Pages/Shared/CategoryHeader.cshtml +++ b/src/WebApp/Pages/Shared/CategoryHeader.cshtml @@ -1,11 +1,16 @@ -@model Codidact.Core.WebApp.Pages.Shared.CategoryHeaderModel +@using Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery +@inject ShortCategoriesListQuery query + +@{ + var results = await query.Handle(new ShortCategoriesListRequest()); +}
- @foreach (var category in Model.Categories) + @foreach (var category in results) { - @category.Name + @category.Name }
diff --git a/src/WebApp/Pages/Shared/CategoryHeader.cshtml.cs b/src/WebApp/Pages/Shared/CategoryHeader.cshtml.cs deleted file mode 100644 index 782c21b..0000000 --- a/src/WebApp/Pages/Shared/CategoryHeader.cshtml.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; - -namespace Codidact.Core.WebApp.Pages.Shared -{ - public class CategoryHeaderModel : PageModel - { - private readonly ShortCategoriesListQuery _categoriesQuery; - private readonly ILogger _logger; - - public CategoryHeaderModel(ShortCategoriesListQuery categoriesQuery, ILogger logger) - { - _categoriesQuery = categoriesQuery; - _logger = logger; - } - - public IEnumerable Categories { get; set; } - - public async Task OnGetAsync(ShortCategoriesListRequest request) - { - Categories = await _categoriesQuery.Handle(new ShortCategoriesListRequest()); - } - } -} From 5d95582e354695959dce86d0de328d3dee4d7c3c Mon Sep 17 00:00:00 2001 From: Misha Tarnortusky Date: Thu, 16 Apr 2020 19:30:31 -0400 Subject: [PATCH 3/4] Switched to category header --- src/WebApp/Pages/Shared/CategoryHeader.cshtml | 18 ----- src/WebApp/Pages/Shared/_Header.cshtml | 71 +++++++++---------- src/WebApp/Pages/Shared/_Layout.cshtml | 2 +- 3 files changed, 36 insertions(+), 55 deletions(-) delete mode 100644 src/WebApp/Pages/Shared/CategoryHeader.cshtml diff --git a/src/WebApp/Pages/Shared/CategoryHeader.cshtml b/src/WebApp/Pages/Shared/CategoryHeader.cshtml deleted file mode 100644 index bf6da67..0000000 --- a/src/WebApp/Pages/Shared/CategoryHeader.cshtml +++ /dev/null @@ -1,18 +0,0 @@ -@using Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery -@inject ShortCategoriesListQuery query - -@{ - var results = await query.Handle(new ShortCategoriesListRequest()); -} - -
-
-
- @foreach (var category in results) - { - @category.Name - } -
-
-
-
\ No newline at end of file diff --git a/src/WebApp/Pages/Shared/_Header.cshtml b/src/WebApp/Pages/Shared/_Header.cshtml index e54b737..30de687 100644 --- a/src/WebApp/Pages/Shared/_Header.cshtml +++ b/src/WebApp/Pages/Shared/_Header.cshtml @@ -1,50 +1,49 @@ @using Microsoft.AspNetCore.Mvc.Localization +@using Codidact.Core.Application.Categories.Queries.ShortCategoriesListQuery @inject IViewLocalizer LayoutLocalizer -
-
-
- Codidact +@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(); + } +} +
+
- - - \ No newline at end of file diff --git a/src/WebApp/Pages/Shared/_Layout.cshtml b/src/WebApp/Pages/Shared/_Layout.cshtml index 5813227..9895469 100644 --- a/src/WebApp/Pages/Shared/_Layout.cshtml +++ b/src/WebApp/Pages/Shared/_Layout.cshtml @@ -7,7 +7,7 @@ Codidact - @ViewData["Title"] - + From 4feb2b727eeefb7bb4b8c1f39ad664561bb05893 Mon Sep 17 00:00:00 2001 From: Misha Tarnortusky Date: Fri, 17 Apr 2020 15:02:17 -0400 Subject: [PATCH 4/4] Bring back header to layout --- src/WebApp/Pages/Questions.cshtml | 3 - src/WebApp/Pages/Shared/CategoryHeader.cshtml | 37 +++++ src/WebApp/Pages/Shared/_Header.cshtml | 66 ++++---- .../Resources/Pages/QuestionsModel.en.resx | 4 - .../Pages/Shared/CategoryHeader.en.resx | 148 ++++++++++++++++++ src/WebApp/WebApp.csproj | 3 + src/WebApp/wwwroot/css/site.css | 4 +- 7 files changed, 222 insertions(+), 43 deletions(-) create mode 100644 src/WebApp/Pages/Shared/CategoryHeader.cshtml create mode 100644 src/WebApp/Resources/Pages/Shared/CategoryHeader.en.resx 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 index 30de687..f902c91 100644 --- a/src/WebApp/Pages/Shared/_Header.cshtml +++ b/src/WebApp/Pages/Shared/_Header.cshtml @@ -1,49 +1,45 @@ @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 - } -
-
-
-
Q&A
-
- @LayoutLocalizer["Questions_title"] - @LayoutLocalizer["Tags_title"] - @LayoutLocalizer["Users_title"] - -
+
+
+
+ Codidact +
+
+
@if (!User.Identity.IsAuthenticated) { - @LayoutLocalizer["Sign_in_button"] + @LayoutLocalizer["Sign_in_button"] } else {
- +
} - @LayoutLocalizer["On_github_button"] + @LayoutLocalizer["On_github_button"] + + + + + + +
+ + + 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/WebApp.csproj b/src/WebApp/WebApp.csproj index 1a709bc..6b5cb3e 100644 --- a/src/WebApp/WebApp.csproj +++ b/src/WebApp/WebApp.csproj @@ -30,6 +30,9 @@ 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