From 1a5fa1b42c6ae6fac7967379071b9c38f2f7d37c Mon Sep 17 00:00:00 2001 From: berkansasmaz Date: Thu, 16 Dec 2021 18:33:32 +0300 Subject: [PATCH] feat: add ability to preview event and refactor --- .../Events/IEventAppService.cs | 2 +- .../Events/EventAppService.cs | 30 ++- .../Controllers/Events/EventController.cs | 6 +- .../Controllers/EventController.cs | 2 - .../Controllers/OrganizationController.cs | 4 +- .../OrganizationMembershipController.cs | 1 - .../CreateEventAreaViewComponent.cs | 38 ++- .../Components/CreateEventArea/Default.cshtml | 3 + .../CreateEventArea/_addSessionSection.cshtml | 28 ++- .../CreateEventArea/_addTrackSection.cshtml | 2 +- .../CreateEventArea/_newEventSection.cshtml | 32 +-- .../CreateEventArea/_previewSection.cshtml | 218 ++++++++++++++++++ .../CreateEventArea/create-event-area.js | 3 +- src/EventHub.Web/Pages/Events/New.cshtml.cs | 2 +- 14 files changed, 319 insertions(+), 52 deletions(-) create mode 100644 src/EventHub.Web/Pages/Events/Components/CreateEventArea/_previewSection.cshtml diff --git a/src/EventHub.Application.Contracts/Events/IEventAppService.cs b/src/EventHub.Application.Contracts/Events/IEventAppService.cs index ecff16d..c2fd720 100644 --- a/src/EventHub.Application.Contracts/Events/IEventAppService.cs +++ b/src/EventHub.Application.Contracts/Events/IEventAppService.cs @@ -13,7 +13,7 @@ namespace EventHub.Events Task> GetListAsync(EventListFilterDto input); - Task> GetDraftEventsByUserId(Guid userId); + Task> GetDraftEventsByCurrentUser(); Task GetByUrlCodeAsync(string urlCode); diff --git a/src/EventHub.Application/Events/EventAppService.cs b/src/EventHub.Application/Events/EventAppService.cs index 9eed81e..3d08249 100644 --- a/src/EventHub.Application/Events/EventAppService.cs +++ b/src/EventHub.Application/Events/EventAppService.cs @@ -13,7 +13,6 @@ using Volo.Abp.Authorization; using Volo.Abp.BlobStoring; using Volo.Abp.Content; using Volo.Abp.Domain.Repositories; -using Volo.Abp.Identity; using Volo.Abp.Users; namespace EventHub.Events @@ -159,11 +158,12 @@ namespace EventHub.Events } [Authorize] - public async Task> GetDraftEventsByUserId(Guid userId) + public async Task> GetDraftEventsByCurrentUser() { var eventQueryable = await _eventRepository.GetQueryableAsync(); var organizationQueryable = await _organizationRepository.GetQueryableAsync(); + var userId = CurrentUser.GetId(); var query = from @event in eventQueryable join organization in organizationQueryable on @event.OrganizationId equals organization.Id where organization.OwnerUserId == userId && @event.IsDraft @@ -177,6 +177,16 @@ namespace EventHub.Events public async Task GetByUrlCodeAsync(string urlCode) { var @event = await _eventRepository.GetAsync(x => x.UrlCode == urlCode, true); + if (@event.IsDraft) + { + if (!CurrentUser.Id.HasValue) + { + throw new AbpAuthorizationException(); + } + + await CheckIfValidOwnerAsync(@event); + } + var organization = await _organizationRepository.GetAsync(@event.OrganizationId); var dto = ObjectMapper.Map(@event); @@ -254,7 +264,7 @@ namespace EventHub.Events public async Task UpdateAsync(Guid id, UpdateEventDto input) { var @event = await _eventRepository.GetAsync(id); - await CheckIfValidOwner(@event); + await CheckIfValidOwnerAsync(@event); await _eventManager.SetLocationAsync(@event, input.IsOnline, input.OnlineLink, input.CountryId, input.City); @event.SetTitle(input.Title); @@ -275,7 +285,7 @@ namespace EventHub.Events public async Task AddTrackAsync(Guid id, AddTractDto input) { var @event = await _eventRepository.GetAsync(id, true); - await CheckIfValidOwner(@event); + await CheckIfValidOwnerAsync(@event); @event.AddTract( GuidGenerator.Create(), @@ -289,7 +299,7 @@ namespace EventHub.Events public async Task UpdateTrackAsync(Guid id, Guid trackId, UpdateTrackDto input) { var @event = await _eventRepository.GetAsync(id, true); - await CheckIfValidOwner(@event); + await CheckIfValidOwnerAsync(@event); @event.UpdateTrack( trackId, @@ -303,7 +313,7 @@ namespace EventHub.Events public async Task DeleteTrackAsync(Guid id, Guid trackId) { var @event = await _eventRepository.GetAsync(id, true); - await CheckIfValidOwner(@event); + await CheckIfValidOwnerAsync(@event); @event.RemoveTrack(trackId); } @@ -313,7 +323,7 @@ namespace EventHub.Events { await CheckIfValidUserNamesAsync(input.SpeakerUserNames); var @event = await _eventRepository.GetAsync(id); - await CheckIfValidOwner(@event); + await CheckIfValidOwnerAsync(@event); @event.AddSession( input.TrackId, @@ -334,7 +344,7 @@ namespace EventHub.Events { await CheckIfValidUserNamesAsync(input.SpeakerUserNames); var @event = await _eventRepository.GetAsync(id); - await CheckIfValidOwner(@event); + await CheckIfValidOwnerAsync(@event); @event.UpdateSession( trackId, @@ -354,7 +364,7 @@ namespace EventHub.Events public async Task DeleteSessionAsync(Guid id, Guid trackId, Guid sessionId) { var @event = await _eventRepository.GetAsync(id, true); - await CheckIfValidOwner(@event); + await CheckIfValidOwnerAsync(@event); @event.RemoveSession(trackId, sessionId); } @@ -391,7 +401,7 @@ namespace EventHub.Events return await AsyncExecuter.ToListAsync(query); } - private async Task CheckIfValidOwner(Event @event) + private async Task CheckIfValidOwnerAsync(Event @event) { var organization = await _organizationRepository.GetAsync(@event.OrganizationId); diff --git a/src/EventHub.HttpApi/Controllers/Events/EventController.cs b/src/EventHub.HttpApi/Controllers/Events/EventController.cs index 6f4c41e..b46f2c5 100644 --- a/src/EventHub.HttpApi/Controllers/Events/EventController.cs +++ b/src/EventHub.HttpApi/Controllers/Events/EventController.cs @@ -41,10 +41,10 @@ namespace EventHub.Controllers.Events } [HttpGet] - [Route("draft-events-by-user-id/{userId}")] - public async Task> GetDraftEventsByUserId(Guid userId) + [Route("draft-events-by-user-id")] + public async Task> GetDraftEventsByCurrentUser() { - return await _eventAppService.GetDraftEventsByUserId(userId); + return await _eventAppService.GetDraftEventsByCurrentUser(); } [HttpGet] diff --git a/src/EventHub.Web/Controllers/EventController.cs b/src/EventHub.Web/Controllers/EventController.cs index d87b047..8ee5d4c 100644 --- a/src/EventHub.Web/Controllers/EventController.cs +++ b/src/EventHub.Web/Controllers/EventController.cs @@ -6,7 +6,6 @@ using Volo.Abp.AspNetCore.Mvc; namespace EventHub.Web.Controllers { - [Route("api/event")] public class EventController : AbpController { private readonly IEventAppService _eventAppService; @@ -17,7 +16,6 @@ namespace EventHub.Web.Controllers } [HttpGet] - [Route("get-list")] public async Task GetList(EventListFilterDto input) { ViewData.Model = (await _eventAppService.GetListAsync(input)).Items.ToList(); diff --git a/src/EventHub.Web/Controllers/OrganizationController.cs b/src/EventHub.Web/Controllers/OrganizationController.cs index 1ac5474..a536a81 100644 --- a/src/EventHub.Web/Controllers/OrganizationController.cs +++ b/src/EventHub.Web/Controllers/OrganizationController.cs @@ -6,7 +6,6 @@ using Volo.Abp.AspNetCore.Mvc; namespace EventHub.Web.Controllers { - [Route("api/organization")] public class OrganizationController : AbpController { private readonly IOrganizationAppService _organizationAppService; @@ -17,7 +16,6 @@ namespace EventHub.Web.Controllers } [HttpGet] - [Route("get-list")] public async Task GetList(OrganizationListFilterDto input) { ViewData.Model = (await _organizationAppService.GetListAsync(input)).Items.ToList(); @@ -29,4 +27,4 @@ namespace EventHub.Web.Controllers }; } } -} \ No newline at end of file +} diff --git a/src/EventHub.Web/Controllers/OrganizationMembershipController.cs b/src/EventHub.Web/Controllers/OrganizationMembershipController.cs index 2f95118..9cd12ef 100644 --- a/src/EventHub.Web/Controllers/OrganizationMembershipController.cs +++ b/src/EventHub.Web/Controllers/OrganizationMembershipController.cs @@ -17,7 +17,6 @@ namespace EventHub.Web.Controllers } [HttpGet] - [Route("get-list")] public async Task GetList(OrganizationMemberListFilterDto input) { ViewData.Model = (await _organizationMembershipAppService.GetMembersAsync(input)).Items.ToList(); diff --git a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/CreateEventAreaViewComponent.cs b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/CreateEventAreaViewComponent.cs index 27dbc4c..a74ffdb 100644 --- a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/CreateEventAreaViewComponent.cs +++ b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/CreateEventAreaViewComponent.cs @@ -63,13 +63,35 @@ public class CreateEventAreaViewComponent : AbpViewComponent }; ViewData["StepType"] = stepType.ToString(); - ViewData["Organizations"] = await GetOrganizationsSelectItemAsync(); - ViewData["Countries"] = await GetCountriesSelectItemAsync(); - ViewData["Languages"] = GetLanguagesSelectItem(); + switch (stepType) + { + case ProgressStepType.NewEvent: + ViewData["Organizations"] = await GetOrganizationsSelectItemAsync(); + ViewData["Countries"] = await GetCountriesSelectItemAsync(); + ViewData["Languages"] = GetLanguagesSelectItem(); + break; + case ProgressStepType.NewSession: + ViewData["Languages"] = GetLanguagesSelectItem(); + break; + case ProgressStepType.Preview: + ViewData["OrganizationName"] = await GetOrganizationNameAsync(model.OrganizationId); + if (model.CountryId is not null) + { + ViewData["CountryName"] = await GetCountryNameAsync(model.CountryId!.Value); + } + break; + } return View("~/Pages/Events/Components/CreateEventArea/Default.cshtml", model); } + private async Task GetOrganizationNameAsync(Guid organizationId) + { + var organizationList = (await _organizationAppService.GetOrganizationsByUserIdAsync(_currentUser.GetId())).Items; + + return organizationList.Single(x => x.Id == organizationId).Name; + } + private async Task> GetOrganizationsSelectItemAsync() { var result = await _organizationAppService.GetOrganizationsByUserIdAsync(_currentUser.GetId()); @@ -83,6 +105,13 @@ public class CreateEventAreaViewComponent : AbpViewComponent ).ToList(); } + private async Task GetCountryNameAsync(Guid countryId) + { + var countries = await _eventAppService.GetCountriesLookupAsync(); + + return countries.Single(x => x.Id == countryId).Name; + } + private async Task> GetCountriesSelectItemAsync() { var result = await _eventAppService.GetCountriesLookupAsync(); @@ -175,6 +204,7 @@ public class CreateEventAreaViewComponent : AbpViewComponent { NewEvent = 0, NewTrack, - NewSession + NewSession, + Preview } } diff --git a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/Default.cshtml b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/Default.cshtml index 7b21f38..c56adad 100644 --- a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/Default.cshtml +++ b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/Default.cshtml @@ -27,6 +27,9 @@
+
+ +
diff --git a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addSessionSection.cshtml b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addSessionSection.cshtml index 8fc2e79..f486dd8 100644 --- a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addSessionSection.cshtml +++ b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addSessionSection.cshtml @@ -5,19 +5,23 @@ @model List @{ - var languages = ViewData["Languages"] as IList; - if (languages is null || !languages.Any()) + var languages = new List(); + @if (ViewData["StepType"]!.ToString() == CreateEventAreaViewComponent.ProgressStepType.NewSession.ToString()) { - throw new BadHttpRequestException("There is no language"); - } - languages = languages.Select(l => - { - if (l.Value == "en") + languages = ViewData["Languages"] as List; + if (languages is null || !languages.Any()) { - l.Selected = true; + throw new BadHttpRequestException("There is no language"); } - return l; - }).ToList(); + languages = languages.Select(l => + { + if (l.Value == "en") + { + l.Selected = true; + } + return l; + }).ToList(); + } } @@ -55,7 +59,7 @@ x.UserName)).EnsureEndsWith(',').EnsureEndsWith(' ') : "")"/>
- @session.Title + @session.Title.TruncateWithPostfix(25) @EventDateHelper.GetTimeRangeText(TimeOnly.FromDateTime(session.StartTime), TimeOnly.FromDateTime(session.EndTime)) | @session.Language @foreach (var speaker in session.Speakers) { @@ -97,7 +101,7 @@ Step
- +
diff --git a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml index f7eef3d..6949117 100644 --- a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml +++ b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml @@ -42,7 +42,7 @@
- Skip This Step +
diff --git a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_newEventSection.cshtml b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_newEventSection.cshtml index ae85ed3..45ced9d 100644 --- a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_newEventSection.cshtml +++ b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_newEventSection.cshtml @@ -3,22 +3,28 @@ @model EventHub.Web.Pages.Events.Components.CreateEventArea.CreateEventAreaViewComponent.NewEventViewModel @{ - var organizations = ViewData["Organizations"] as IList; - if (organizations is null || !organizations.Any()) + var organizations = new List(); + var countries = new List(); + var languages = new List(); + @if (ViewData["StepType"]!.ToString() == CreateEventAreaViewComponent.ProgressStepType.NewEvent.ToString()) { - throw new BadHttpRequestException("There is no organization"); - } + organizations = ViewData["Organizations"] as List; + if (organizations is null || !organizations.Any()) + { + throw new BadHttpRequestException("There is no organization"); + } - var countries = ViewData["Countries"] as IList; - if (countries is null || !countries.Any()) - { - throw new BadHttpRequestException("There is no country"); - } + countries = ViewData["Countries"] as List; + if (countries is null || !countries.Any()) + { + throw new BadHttpRequestException("There is no country"); + } - var languages = ViewData["Languages"] as IList; - if (languages is null || !languages.Any()) - { - throw new BadHttpRequestException("There is no language"); + languages = ViewData["Languages"] as List; + if (languages is null || !languages.Any()) + { + throw new BadHttpRequestException("There is no language"); + } } } diff --git a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_previewSection.cshtml b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_previewSection.cshtml new file mode 100644 index 0000000..208d046 --- /dev/null +++ b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/_previewSection.cshtml @@ -0,0 +1,218 @@ +@using EventHub.Web.Pages.Events +@using EventHub.Web.Pages.Events.Components.CreateEventArea +@using Microsoft.AspNetCore.Http +@model EventHub.Web.Pages.Events.Components.CreateEventArea.CreateEventAreaViewComponent.NewEventViewModel + +@{ + var organizationName = ""; + var countryName = ""; + @if (ViewData["StepType"]!.ToString() == CreateEventAreaViewComponent.ProgressStepType.Preview.ToString()) + { + organizationName = ViewData["OrganizationName"] as string; + if (organizationName.IsNullOrWhiteSpace()) + { + throw new BadHttpRequestException("Organization name cannot be empty!"); + } + + countryName = ViewData["CountryName"] as string; + if (Model is {CountryId: { } } && countryName.IsNullOrWhiteSpace()) + { + throw new BadHttpRequestException("Country name cannot be empty when CountryId exists!"); + } + } +} + +@if (Model is not null) +{ +
+
+
+
+

Event Preview

+
+
+ Organization Name: +
+
+ @organizationName +
+
+
+
+ Title: +
+
+ @Model.Title +
+
+
+
+ Start Date: +
+
+ @Model.StartTime.ToShortDateString() - @Model.StartTime.ToShortTimeString() +
+
+
+
+ End Date: +
+
+ @Model.EndTime.ToShortDateString() - @Model.EndTime.ToShortTimeString() +
+
+
+
+ Event’s Explanation: +
+
+

@Model.Description

+
+
+
+
+ Cover Image: +
+
+ +
+
+ @if (Model.IsOnline != null && Model.IsOnline!.Value) + { +
+
+ Event Type: +
+
+ Online +
+
+ @if (!Model.OnlineLink.IsNullOrWhiteSpace()) + { +
+
+ Url: +
+
+ @Model.OnlineLink +
+
+ } + } + else if (Model.CountryId.HasValue && !Model.City.IsNullOrEmpty()) + { +
+
+ Country: +
+
+ @countryName +
+
+
+
+ City: +
+
+ @Model.City +
+
+ } + @if (!Model.Language.IsNullOrWhiteSpace()) + { +
+
+ Language: +
+
+ @Model.Language +
+
+ } + @if (Model.Capacity.HasValue) + { +
+
+ Capacity: +
+
+ @Model.Capacity +
+
+ } + @if (Model.Tracks.Any()) + { +
+
+ Tracks: +
+
+ @Model.Tracks.Count +
+
+
+
+ Sessions: +
+
+ + + + @foreach (var track in Model.Tracks) + { + + } + + + + + @foreach (var track in Model.Tracks) + { + + } + + +
@track.Name
+ @if (track.Sessions.Any()) + { + @foreach (var session in track.Sessions) + { +
+ @session.Title.TruncateWithPostfix(25) + @EventDateHelper.GetTimeRangeText(TimeOnly.FromDateTime(session.StartTime), TimeOnly.FromDateTime(session.EndTime)) | @session.Language + @foreach (var speaker in session.Speakers) + { + @speaker.UserName + } +
+ } + } + else + { +
+ There is no session! + Please add session. +
+ } +
+ } +
+ +
+
+
+} +else +{ + +} + diff --git a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/create-event-area.js b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/create-event-area.js index 35893f6..b14c15f 100644 --- a/src/EventHub.Web/Pages/Events/Components/CreateEventArea/create-event-area.js +++ b/src/EventHub.Web/Pages/Events/Components/CreateEventArea/create-event-area.js @@ -6,7 +6,8 @@ var stepType = { "NewEvent": "NewEvent", "NewTrack": "NewTrack", - "NewSession": "NewSession" + "NewSession": "NewSession", + "Preview": "Preview" } var widgetManager = $wrapper.data('abp-widget-manager'); diff --git a/src/EventHub.Web/Pages/Events/New.cshtml.cs b/src/EventHub.Web/Pages/Events/New.cshtml.cs index 8e89c1b..37896b1 100644 --- a/src/EventHub.Web/Pages/Events/New.cshtml.cs +++ b/src/EventHub.Web/Pages/Events/New.cshtml.cs @@ -45,7 +45,7 @@ namespace EventHub.Web.Pages.Events if (IsHasOrganizations && !IsCreateNew) { - DraftEventList = await _eventAppService.GetDraftEventsByUserId(CurrentUser.GetId()); + DraftEventList = await _eventAppService.GetDraftEventsByCurrentUser(); } } }