Browse Source

Refactor add track section and added session section

pull/79/head
berkansasmaz 5 years ago
parent
commit
137497944d
No known key found for this signature in database GPG Key ID: 884D815C3F32BE00
  1. 2
      src/EventHub.Application.Contracts/Events/IEventAppService.cs
  2. 27
      src/EventHub.Application.Contracts/Events/SessionDto.cs
  3. 13
      src/EventHub.Application.Contracts/Events/SpeakerDto.cs
  4. 8
      src/EventHub.Application.Contracts/Events/TrackDto.cs
  5. 10
      src/EventHub.Application.Contracts/Events/UpdateTrackDto.cs
  6. 9
      src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs
  7. 18
      src/EventHub.Application/Events/EventAppService.cs
  8. 19
      src/EventHub.Domain/Events/Event.cs
  9. 66
      src/EventHub.EntityFrameworkCore/EntityFrameworkCore/Events/EventRepository.cs
  10. 9
      src/EventHub.HttpApi/Controllers/Events/EventController.cs
  11. 3
      src/EventHub.Web/Pages/Events/Components/CreateEventArea/Default.cshtml
  12. 65
      src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addSessionSection.cshtml
  13. 4
      src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml
  14. 12
      src/EventHub.Web/Pages/Events/Components/CreateEventArea/create-event-area.js
  15. 4
      src/EventHub.Web/Pages/Events/Components/EventsArea/_eventListSection.cshtml
  16. 11
      src/EventHub.Web/Pages/Events/EventDateHelper.cs

2
src/EventHub.Application.Contracts/Events/IEventAppService.cs

@ -26,6 +26,8 @@ namespace EventHub.Events
Task UpdateAsync(Guid id, UpdateEventDto input); Task UpdateAsync(Guid id, UpdateEventDto input);
Task AddTrackAsync(Guid id, AddTractDto input); Task AddTrackAsync(Guid id, AddTractDto input);
Task UpdateTrackAsync(Guid id, Guid trackId, UpdateTrackDto input);
Task DeleteTrackAsync(Guid id, Guid trackId); Task DeleteTrackAsync(Guid id, Guid trackId);

27
src/EventHub.Application.Contracts/Events/SessionDto.cs

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
namespace EventHub.Events;
public class SessionDto : EntityDto<Guid>
{
public Guid TrackId { get; set; }
public string Title { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string Description { get; set; }
public string Language { get; set; }
public List<SpeakerDto> Speakers { get; set; }
public SessionDto()
{
Speakers = new List<SpeakerDto>();
}
}

13
src/EventHub.Application.Contracts/Events/SpeakerDto.cs

@ -0,0 +1,13 @@
using System;
using Volo.Abp.Application.Dtos;
namespace EventHub.Events;
public class SpeakerDto : EntityDto<Guid>
{
public Guid SessionId { get; set; }
public Guid UserId { get; set; }
public string UserName { get; set; }
}

8
src/EventHub.Application.Contracts/Events/TrackDto.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
namespace EventHub.Events; namespace EventHub.Events;
@ -6,4 +7,11 @@ namespace EventHub.Events;
public class TrackDto : EntityDto<Guid> public class TrackDto : EntityDto<Guid>
{ {
public string Name { get; set; } public string Name { get; set; }
public List<SessionDto> Sessions { get; set; }
public TrackDto()
{
Sessions = new List<SessionDto>();
}
} }

10
src/EventHub.Application.Contracts/Events/UpdateTrackDto.cs

@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;
namespace EventHub.Events;
public class UpdateTrackDto
{
[Required]
[StringLength(TrackConsts.MaxNameLength)]
public string Name { get; set; }
}

9
src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs

@ -32,7 +32,14 @@ namespace EventHub
.Ignore(x => x.OrganizationName) .Ignore(x => x.OrganizationName)
.Ignore(x => x.OrganizationDisplayName); .Ignore(x => x.OrganizationDisplayName);
CreateMap<Track, TrackDto>(); CreateMap<Track, TrackDto>()
.ForMember(x => x.Sessions, memberOptions => memberOptions.MapFrom(m => m.Sessions));
CreateMap<Session, SessionDto>()
.ForMember(x => x.Speakers, memberOptions => memberOptions.MapFrom(m => m.Speakers));
CreateMap<Speaker, SpeakerDto>()
.Ignore(x => x.UserName);
CreateMap<IdentityUser, EventAttendeeDto>(); CreateMap<IdentityUser, EventAttendeeDto>();

18
src/EventHub.Application/Events/EventAppService.cs

@ -187,6 +187,11 @@ namespace EventHub.Events
dto.OwnerUserName = user.UserName; dto.OwnerUserName = user.UserName;
dto.OwnerEmail = user.Email; dto.OwnerEmail = user.Email;
foreach (var speaker in from track in dto.Tracks from session in track.Sessions from speaker in session.Speakers select speaker)
{
speaker.UserName = (await _userRepository.GetAsync(speaker.UserId)).UserName;
}
return dto; return dto;
} }
@ -270,6 +275,19 @@ namespace EventHub.Events
await _eventRepository.UpdateAsync(@event); await _eventRepository.UpdateAsync(@event);
} }
public async Task UpdateTrackAsync(Guid id, Guid trackId, UpdateTrackDto input)
{
var @event = await _eventRepository.GetAsync(id, true);
await CheckOwnerControlAsync(@event);
@event.UpdateTrack(
trackId,
input.Name
);
await _eventRepository.UpdateAsync(@event);
}
public async Task DeleteTrackAsync(Guid id, Guid trackId) public async Task DeleteTrackAsync(Guid id, Guid trackId)
{ {
var @event = await _eventRepository.GetAsync(id, true); var @event = await _eventRepository.GetAsync(id, true);

19
src/EventHub.Domain/Events/Event.cs

@ -140,6 +140,25 @@ namespace EventHub.Events
return this; return this;
} }
public Event UpdateTrack(Guid trackId, string name)
{
if (Tracks.Any(x => x.Name == name))
{
throw new BusinessException(EventHubErrorCodes.TrackNameAlreadyExist)
.WithData("Name", name);
}
var track = Tracks.SingleOrDefault(x => x.Id == trackId);
if (track is null)
{
throw new BusinessException(EventHubErrorCodes.TrackNotFound);
}
track.SetName(name);
return this;
}
public Event RemoveTrack(Guid trackId) public Event RemoveTrack(Guid trackId)
{ {
var track = Tracks.SingleOrDefault(x => x.Id == trackId); var track = Tracks.SingleOrDefault(x => x.Id == trackId);

66
src/EventHub.EntityFrameworkCore/EntityFrameworkCore/Events/EventRepository.cs

@ -20,12 +20,12 @@ namespace EventHub.EntityFrameworkCore.Events
} }
public async Task<int> GetCountAsync( public async Task<int> GetCountAsync(
string title = null, string title = null,
string organizationDisplayName = null, string organizationDisplayName = null,
int? minAttendeeCount = null, int? minAttendeeCount = null,
int? maxAttendeeCount = null, int? maxAttendeeCount = null,
DateTime? minStartTime = null, DateTime? minStartTime = null,
DateTime? maxStartTime = null, DateTime? maxStartTime = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
@ -36,35 +36,36 @@ namespace EventHub.EntityFrameworkCore.Events
var organizationQueryable = dbContext.Set<Organization>().AsQueryable(); var organizationQueryable = dbContext.Set<Organization>().AsQueryable();
var query = (from @event in eventQueryable var query = (from @event in eventQueryable
join organization in organizationQueryable on @event.OrganizationId equals organization.Id join organization in organizationQueryable on @event.OrganizationId equals organization.Id
select new select new
{ {
Event = @event, Event = @event,
Organization = organization, Organization = organization,
AttendeeCount = (from eventRegistration in eventRegistrationQueryable AttendeeCount = (from eventRegistration in eventRegistrationQueryable
where eventRegistration.EventId == @event.Id where eventRegistration.EventId == @event.Id
select @eventRegistration).Count() select @eventRegistration).Count()
}) })
.WhereIf(!string.IsNullOrWhiteSpace(title), x => x.Event.Title.ToLower().Contains(title.ToLower())) .WhereIf(!string.IsNullOrWhiteSpace(title), x => x.Event.Title.ToLower().Contains(title.ToLower()))
.WhereIf(!string.IsNullOrWhiteSpace(organizationDisplayName), x => x.Organization.DisplayName.ToLower().Contains(organizationDisplayName.ToLower())) .WhereIf(!string.IsNullOrWhiteSpace(organizationDisplayName),
.WhereIf(minStartTime.HasValue, x => x.Event.StartTime >= minStartTime) x => x.Organization.DisplayName.ToLower().Contains(organizationDisplayName.ToLower()))
.WhereIf(maxStartTime.HasValue, x => x.Event.StartTime <= maxStartTime) .WhereIf(minStartTime.HasValue, x => x.Event.StartTime >= minStartTime)
.WhereIf(minAttendeeCount.HasValue, x => x.AttendeeCount >= minAttendeeCount) .WhereIf(maxStartTime.HasValue, x => x.Event.StartTime <= maxStartTime)
.WhereIf(maxAttendeeCount.HasValue, x => x.AttendeeCount <= maxAttendeeCount); .WhereIf(minAttendeeCount.HasValue, x => x.AttendeeCount >= minAttendeeCount)
.WhereIf(maxAttendeeCount.HasValue, x => x.AttendeeCount <= maxAttendeeCount);
return await query.CountAsync(GetCancellationToken(cancellationToken)); return await query.CountAsync(GetCancellationToken(cancellationToken));
} }
public async Task<List<EventWithDetails>> GetListAsync( public async Task<List<EventWithDetails>> GetListAsync(
string sorting = null, string sorting = null,
int skipCount = 0, int skipCount = 0,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
string title = null, string title = null,
string organizationDisplayName = null, string organizationDisplayName = null,
int? minAttendeeCount = null, int? minAttendeeCount = null,
int? maxAttendeeCount = null, int? maxAttendeeCount = null,
DateTime? minStartTime = null, DateTime? minStartTime = null,
DateTime? maxStartTime = null, DateTime? maxStartTime = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
@ -98,10 +99,13 @@ namespace EventHub.EntityFrameworkCore.Events
return await query.ToListAsync(GetCancellationToken(cancellationToken)); return await query.ToListAsync(GetCancellationToken(cancellationToken));
} }
public override async Task<IQueryable<Event>> WithDetailsAsync() public override async Task<IQueryable<Event>> WithDetailsAsync()
{ {
return (await GetQueryableAsync()).Include(x => x.Tracks).ThenInclude(x => x.Sessions); return (await GetQueryableAsync())
.Include(e => e.Tracks)
.ThenInclude(t => t.Sessions)
.ThenInclude(s => s.Speakers);
} }
} }
} }

9
src/EventHub.HttpApi/Controllers/Events/EventController.cs

@ -88,7 +88,14 @@ namespace EventHub.Controllers.Events
await _eventAppService.AddTrackAsync(id, input); await _eventAppService.AddTrackAsync(id, input);
} }
[HttpPost] [HttpPut]
[Route("{id}/tracks/{trackId}")]
public async Task UpdateTrackAsync(Guid id, Guid trackId, UpdateTrackDto input)
{
await _eventAppService.UpdateTrackAsync(id, trackId, input);
}
[HttpDelete]
[Route("{id}/tracks/{trackId}")] [Route("{id}/tracks/{trackId}")]
public async Task DeleteTrackAsync(Guid id, Guid trackId) public async Task DeleteTrackAsync(Guid id, Guid trackId)
{ {

3
src/EventHub.Web/Pages/Events/Components/CreateEventArea/Default.cshtml

@ -24,6 +24,9 @@
<div id="CreateTrackContainer" style="@(stepType != CreateEventAreaViewComponent.ProgressStepType.NewTrack ? "display: none" : "")"> <div id="CreateTrackContainer" style="@(stepType != CreateEventAreaViewComponent.ProgressStepType.NewTrack ? "display: none" : "")">
<partial name="_addTrackSection.cshtml" model="@Model.Tracks"/> <partial name="_addTrackSection.cshtml" model="@Model.Tracks"/>
</div> </div>
<div id="CreateSessionContainer" style="@(stepType != CreateEventAreaViewComponent.ProgressStepType.NewSession ? "display: none" : "")">
<partial name="_addSessionSection.cshtml" model="@Model.Tracks"/>
</div>
<input type="hidden" id="EventId" value="@eventId"/> <input type="hidden" id="EventId" value="@eventId"/>
<input type="hidden" id="EventUrlCode" value="@eventUrlCode"/> <input type="hidden" id="EventUrlCode" value="@eventUrlCode"/>

65
src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addSessionSection.cshtml

@ -0,0 +1,65 @@
@using EventHub.Web.Pages.Events
@using EventHub.Web.Pages.Events.Components.CreateEventArea
@model List<EventHub.Events.TrackDto>
<partial name="_progressSection.cshtml" model="@CreateEventAreaViewComponent.ProgressStepType.NewSession"/>
@if (Model is not null)
{
<div class="row">
<div class="col-md-10 mx-auto">
<div class="card">
<div class="card-body profile-content p-5" style="min-height: 480px;">
<h2 class="mb-4">Add Session</h2>
<table class="table">
<thead>
<tr>
@foreach (var track in Model)
{
<th class="text-center" width="25%">@track.Name</th>
}
</tr>
</thead>
<tbody>
<tr>
@foreach (var track in Model)
{
<td>
@foreach (var session in track.Sessions)
{
<div class="track-item">
<span class="track-name">@session.Title</span>
<small class="text-primary d-block my-2">@EventDateHelper.GetTimeRangeText(TimeOnly.FromDateTime(session.StartTime), TimeOnly.FromDateTime(session.EndTime)) | @session.Language</small>
@foreach (var speaker in session.Speakers)
{
<span class="d-block mb-2">@speaker.UserName</span>
}
<a href="javascript:;" data-bs-toggle="modal" data-bs-target="#editSessionModal" class="mt-3 d-block text-info">
<small><i class="fa fa-edit me-1"></i>Edit</small>
</a>
</div>
}
<div class="big-square-btn text-center">
<a href="javascript:;" data-bs-toggle="modal" data-bs-target="#addSessionModal" class="btn btn-outline-secondary d-block px-2 py-5"><i class="fa fa-plus mb-3"></i><br>Add New Session</a>
</div>
</td>
}
</tr>
</tbody>
</table>
</div>
<div class="card-footer bg-white border-0 p-5 pt-1">
<div class="row">
<div class="col-6">
<button id="PreviousStepButtonInSessionSection" data-target-step="@CreateEventAreaViewComponent.ProgressStepType.NewTrack" class="btn btn-secondary step-transition"><i class="fa fa-arrow-left me-2"></i> Previous Step </button>
</div>
<div class="col-6 text-end">
<button href="#" class="btn btn-success">Publish <i class="fa fa-arrow-right ms-2"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
}

4
src/EventHub.Web/Pages/Events/Components/CreateEventArea/_addTrackSection.cshtml

@ -38,11 +38,11 @@
<div class="card-footer bg-white border-0 p-5 pt-1"> <div class="card-footer bg-white border-0 p-5 pt-1">
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<button id="PreviousStepButtonInTrackSession" data-target-step="@CreateEventAreaViewComponent.ProgressStepType.NewEvent" class="btn btn-secondary step-transition"><i class="fa fa-arrow-left me-2"></i> Previous Step </button> <button id="PreviousStepButtonInTrackSection" data-target-step="@CreateEventAreaViewComponent.ProgressStepType.NewEvent" class="btn btn-secondary step-transition"><i class="fa fa-arrow-left me-2"></i> Previous Step </button>
</div> </div>
<div class="col-6 text-end"> <div class="col-6 text-end">
<a href="#" class="btn btn-link">Skip This Step</a> <a href="#" class="btn btn-link">Skip This Step</a>
<a href="#" class="btn btn-primary">Next Step <i class="fa fa-arrow-right ms-2"></i></a> <button id="NextStepButtonInTrackSection" data-target-step="@CreateEventAreaViewComponent.ProgressStepType.NewSession" class="btn btn-primary step-transition">Next Step <i class="fa fa-arrow-right ms-2"></i></button>
</div> </div>
</div> </div>
</div> </div>

12
src/EventHub.Web/Pages/Events/Components/CreateEventArea/create-event-area.js

@ -106,13 +106,11 @@
abp.notify.error('Track name must be different from the previous name.'); abp.notify.error('Track name must be different from the previous name.');
return; return;
} }
eventApiService.deleteTrack(eventIdInput.val(), trackId).then(function () { eventApiService.updateTrack(eventIdInput.val(), trackId, { name: trackName}).then(function () {
eventApiService.addTrack(eventIdInput.val(), {name: trackName}).then(function () { $('#EditTrackModal').modal('hide');
$('#EditTrackModal').modal('hide'); abp.notify.success('Updated the track');
abp.notify.success('Updated the track'); FillFilter(stepType.NewTrack)
FillFilter(stepType.NewTrack) widgetManager.refresh();
widgetManager.refresh();
});
}); });
}); });
} }

4
src/EventHub.Web/Pages/Events/Components/EventsArea/_eventListSection.cshtml

@ -23,7 +23,7 @@
<div class="col-9"> <div class="col-9">
<div class="event-info"> <div class="event-info">
<h5>@eventDto.Title</h5> <h5>@eventDto.Title</h5>
<small>@eventDto.StartTime.ToString("hh tt", CultureInfo.InvariantCulture) - @eventDto.EndTime.ToString("hh tt", CultureInfo.InvariantCulture) | @EventDateHelper.GetLocationInfo(eventDto)</small> <small>@EventDateHelper.GetTimeRangeText(TimeOnly.FromDateTime(eventDto.StartTime), TimeOnly.FromDateTime(eventDto.EndTime)) | @EventDateHelper.GetLocationInfo(eventDto)</small>
<p>@eventDto.Description</p> <p>@eventDto.Description</p>
</div> </div>
<a href="@Url.Page("/Events/Detail", new { url = eventDto.Url })" class="btn btn-link p-0">Learn More <img src="/assets/more-btn.svg"></a> <a href="@Url.Page("/Events/Detail", new { url = eventDto.Url })" class="btn btn-link p-0">Learn More <img src="/assets/more-btn.svg"></a>
@ -33,4 +33,4 @@
</div> </div>
</div> </div>
</div> </div>
} }

11
src/EventHub.Web/Pages/Events/EventDateHelper.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Globalization;
using System.Text; using System.Text;
using EventHub.Events; using EventHub.Events;
@ -24,6 +25,16 @@ namespace EventHub.Web.Pages.Events
return sb.ToString(); return sb.ToString();
} }
public static string GetTimeRangeText(TimeOnly startTime, TimeOnly endTime)
{
var sb = new StringBuilder();
sb.Append(startTime.ToString("hh tt", CultureInfo.InvariantCulture));
sb.Append(" - ");
sb.Append(endTime.ToString("hh tt", CultureInfo.InvariantCulture));
return sb.ToString();
}
public static string GetLocationInfo(EventInListDto eventItem) public static string GetLocationInfo(EventInListDto eventItem)
{ {
if (eventItem.IsOnline) if (eventItem.IsOnline)

Loading…
Cancel
Save