From 1cdb50aba081e51d7bd8c002f40802e4a42b7f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 25 Jan 2021 18:03:03 +0300 Subject: [PATCH] Show events of the organization. --- .../Events/EventListFilterDto.cs | 4 +- .../Events/EventAppService.cs | 9 ++- .../Localization/EventHub/en.json | 3 +- .../EventHub.Web/Pages/Events/Detail.cshtml | 8 ++- .../Pages/Events/EventDateHelper.cs | 26 ++++++++ eventhub/src/EventHub.Web/Pages/Index.cshtml | 8 ++- .../Pages/Organizations/Profile.cshtml | 60 +++++++++++++++---- .../Pages/Organizations/Profile.cshtml.cs | 24 ++++++-- 8 files changed, 116 insertions(+), 26 deletions(-) create mode 100644 eventhub/src/EventHub.Web/Pages/Events/EventDateHelper.cs diff --git a/eventhub/src/EventHub.Application.Contracts/Events/EventListFilterDto.cs b/eventhub/src/EventHub.Application.Contracts/Events/EventListFilterDto.cs index 8c71887..693c850 100644 --- a/eventhub/src/EventHub.Application.Contracts/Events/EventListFilterDto.cs +++ b/eventhub/src/EventHub.Application.Contracts/Events/EventListFilterDto.cs @@ -9,9 +9,11 @@ namespace EventHub.Events public DateTime? MaxDate { get; set; } + public Guid? OrganizationId { get; set; } + public EventListFilterDto() { MaxResultCount = 20; } } -} \ No newline at end of file +} diff --git a/eventhub/src/EventHub.Application/Events/EventAppService.cs b/eventhub/src/EventHub.Application/Events/EventAppService.cs index 5fd3d84..37b7e1e 100644 --- a/eventhub/src/EventHub.Application/Events/EventAppService.cs +++ b/eventhub/src/EventHub.Application/Events/EventAppService.cs @@ -64,12 +64,17 @@ namespace EventHub.Events if (input.MinDate.HasValue) { - query = query.Where(i => i.@event.EndTime >= input.MinDate); + query = query.Where(i => i.@event.EndTime >= input.MinDate.Value); } if (input.MaxDate.HasValue) { - query = query.Where(i => i.@event.EndTime <= input.MaxDate); + query = query.Where(i => i.@event.EndTime <= input.MaxDate.Value); + } + + if (input.OrganizationId.HasValue) + { + query = query.Where(i => i.@event.OrganizationId == input.OrganizationId.Value); } var totalCount = await AsyncExecuter.CountAsync(query); diff --git a/eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json b/eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json index ac8cccf..c627ce8 100644 --- a/eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json +++ b/eventhub/src/EventHub.Domain.Shared/Localization/EventHub/en.json @@ -32,6 +32,7 @@ "EventRegisterSuccessMessageTitle": "Thanks for registering!", "EventRegisterSuccessMessage": "We will send a reminder email before the event.", "EventRegistrationCancelledMessage": "Your event registration has been cancelled.", - "OrganizedBy": "Organized by" + "OrganizedBy": "Organized by", + "NoEventOrganizedByThisOrganizationYet": "No event organized by this organization yet!" } } diff --git a/eventhub/src/EventHub.Web/Pages/Events/Detail.cshtml b/eventhub/src/EventHub.Web/Pages/Events/Detail.cshtml index 5eff7ed..6e25c2f 100644 --- a/eventhub/src/EventHub.Web/Pages/Events/Detail.cshtml +++ b/eventhub/src/EventHub.Web/Pages/Events/Detail.cshtml @@ -1,6 +1,7 @@ @page "/events/{url}" @inject IHtmlLocalizer L @using EventHub.Localization +@using EventHub.Web.Pages.Events @using EventHub.Web.Pages.Events.Components.AttendeesArea @using EventHub.Web.Pages.Events.Components.RegistrationArea @using Microsoft.AspNetCore.Mvc.Localization @@ -10,10 +11,11 @@ @Model.Event.Title - @Model.Event.Title + +

@Model.Event.Title

+
- @Model.Event.StartTime.ToLongDateString(), - @Model.Event.StartTime.ToString("hh:mm")
+ @EventDateHelper.GetDateRangeText(Model.Event.StartTime, Model.Event.EndTime)
@L["OrganizedBy"] @Model.Event.OrganizationDisplayName
diff --git a/eventhub/src/EventHub.Web/Pages/Events/EventDateHelper.cs b/eventhub/src/EventHub.Web/Pages/Events/EventDateHelper.cs new file mode 100644 index 0000000..5c4cb9b --- /dev/null +++ b/eventhub/src/EventHub.Web/Pages/Events/EventDateHelper.cs @@ -0,0 +1,26 @@ +using System; +using System.Text; + +namespace EventHub.Web.Pages.Events +{ + public static class EventDateHelper + { + public static string GetDateRangeText(DateTime startTime, DateTime endTime) + { + var sb = new StringBuilder(); + sb.Append(startTime.ToLongDateString()); + sb.Append(", "); + sb.Append(startTime.ToString("hh:mm")); + sb.Append(" - "); + if (startTime.Day != endTime.Day) + { + sb.Append(endTime.ToLongDateString()); + sb.Append(", "); + } + + sb.Append(endTime.ToString("hh:mm")); + + return sb.ToString(); + } + } +} diff --git a/eventhub/src/EventHub.Web/Pages/Index.cshtml b/eventhub/src/EventHub.Web/Pages/Index.cshtml index 6a08281..c75a1a6 100644 --- a/eventhub/src/EventHub.Web/Pages/Index.cshtml +++ b/eventhub/src/EventHub.Web/Pages/Index.cshtml @@ -2,6 +2,7 @@ @model EventHub.Web.Pages.IndexModel @using Microsoft.AspNetCore.Mvc.Localization @using EventHub.Localization +@using EventHub.Web.Pages.Events @inject IHtmlLocalizer L @section styles { @@ -26,8 +27,11 @@ @eventItem.Title @eventItem.Title - @eventItem.StartTime.ToLongDateString(), @eventItem.StartTime.ToString("hh:mm") - + + @EventDateHelper.GetDateRangeText(eventItem.StartTime, eventItem.EndTime)
+ @L["OrganizedBy"] @eventItem.OrganizationDisplayName +
+ @eventItem.Description.TruncateWithPostfix(100) @L["SeeEvent"] diff --git a/eventhub/src/EventHub.Web/Pages/Organizations/Profile.cshtml b/eventhub/src/EventHub.Web/Pages/Organizations/Profile.cshtml index fa9e8bc..96be27d 100644 --- a/eventhub/src/EventHub.Web/Pages/Organizations/Profile.cshtml +++ b/eventhub/src/EventHub.Web/Pages/Organizations/Profile.cshtml @@ -1,19 +1,53 @@ @page "/organizations/{name}" @inject IHtmlLocalizer L @using EventHub.Localization +@using EventHub.Web.Pages.Events @using Microsoft.AspNetCore.Mvc.Localization @model EventHub.Web.Pages.Organizations.ProfilePageModel -

@Model.Organization.DisplayName @Model.Organization.Name

- -

- @Model.Organization.Description -

+ + + + @Model.Organization.DisplayName + + +

@Model.Organization.DisplayName

+
+ + @Model.Organization.Description + +
+
+
+
- - - TODO - - - TODO - - +@if (Model.Events.Any()) +{ +

Upcoming Events

+ + + @foreach (var eventItem in Model.Events) + { + + + @eventItem.Title + + @eventItem.Title + + @EventDateHelper.GetDateRangeText(eventItem.StartTime, eventItem.EndTime) + + + @eventItem.Description.TruncateWithPostfix(100) + + @L["SeeEvent"] + + + + } + +} +else +{ + + @L["NoEventOrganizedByThisOrganizationYet"] + +} diff --git a/eventhub/src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs b/eventhub/src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs index 1136904..a62c4f0 100644 --- a/eventhub/src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs +++ b/eventhub/src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs @@ -1,27 +1,43 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; +using EventHub.Events; using EventHub.Organizations; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; namespace EventHub.Web.Pages.Organizations { - public class ProfilePageModel : PageModel + public class ProfilePageModel : EventHubPageModel { [BindProperty(SupportsGet = true)] public string Name { get; set; } public OrganizationProfileDto Organization { get; set; } + public IReadOnlyList Events { get; private set; } + private readonly IEventAppService _eventAppService; private readonly IOrganizationAppService _organizationAppService; - public ProfilePageModel(IOrganizationAppService organizationAppService) + public ProfilePageModel( + IOrganizationAppService organizationAppService, + IEventAppService eventAppService) { _organizationAppService = organizationAppService; + _eventAppService = eventAppService; } public async Task OnGetAsync() { Organization = await _organizationAppService.GetProfileAsync(Name); + + var result = await _eventAppService.GetListAsync( + new EventListFilterDto + { + MinDate = Clock.Now, + OrganizationId = Organization.Id + } + ); + + Events = result.Items; } } }