mirror of https://github.com/abpframework/eventhub
24 changed files with 2681 additions and 28 deletions
@ -0,0 +1,30 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public class EventDetailDto : EntityDto<Guid> |
|||
{ |
|||
public string OrganizationName { get; set; } |
|||
|
|||
public string OrganizationDisplayName { get; set; } |
|||
|
|||
public string Title { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
|
|||
public DateTime StartTime { get; set; } |
|||
|
|||
public DateTime EndTime { get; set; } |
|||
|
|||
public bool IsOnline { get; set; } |
|||
|
|||
public bool IsLive { get; set; } |
|||
|
|||
public string UrlCode { get; set; } |
|||
|
|||
public string Url { get; set; } |
|||
|
|||
public int? Capacity { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
using Volo.Abp; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public static class EventUrlCodeHelper |
|||
{ |
|||
public static string GetCodeFromUrl(string url) |
|||
{ |
|||
Check.NotNullOrEmpty(url, nameof(url), minLength: EventConsts.UrlCodeLength); |
|||
|
|||
return url.Right(EventConsts.UrlCodeLength); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
using System; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public class EventUrlCodeGenerator : ITransientDependency |
|||
{ |
|||
private static string UrlCodeChars = "abcdefghijklmnopqrstuvwxyz0123456789"; |
|||
|
|||
private readonly IRepository<Event, Guid> _eventRepository; |
|||
|
|||
public EventUrlCodeGenerator(IRepository<Event, Guid> eventRepository) |
|||
{ |
|||
_eventRepository = eventRepository; |
|||
} |
|||
|
|||
public async Task<string> GenerateAsync() |
|||
{ |
|||
string urlCode; |
|||
|
|||
do |
|||
{ |
|||
urlCode = GenerateRandomCodeAsync(); |
|||
} while (await _eventRepository.AnyAsync(x => x.UrlCode == urlCode)); |
|||
|
|||
return urlCode; |
|||
} |
|||
|
|||
private string GenerateRandomCodeAsync() |
|||
{ |
|||
var sb = new StringBuilder(); |
|||
|
|||
for (var i = 0; i < EventConsts.UrlCodeLength; i++) |
|||
{ |
|||
sb.Append(UrlCodeChars[RandomHelper.GetRandom(0, UrlCodeChars.Length)]); |
|||
} |
|||
|
|||
return sb.ToString(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System; |
|||
using System.Text; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
internal static class EventUrlHelper |
|||
{ |
|||
private static string AllowedUrlChars = "abcdefghijklmnopqrstuvwxyz0123456789"; |
|||
|
|||
public static string ConvertTitleToUrlPart(string title) |
|||
{ |
|||
var normalizedTitle = title |
|||
.Replace(' ', '-') |
|||
.ToKebabCase() |
|||
.ToLowerInvariant(); |
|||
|
|||
var urlPartBuilder = new StringBuilder(); |
|||
|
|||
foreach (var c in normalizedTitle) |
|||
{ |
|||
if (AllowedUrlChars.Contains(c)) |
|||
{ |
|||
urlPartBuilder.Append(c); |
|||
} |
|||
|
|||
if (urlPartBuilder.Length >= EventConsts.MaxTitleInUrlLength) |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return urlPartBuilder.ToString(); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,46 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace EventHub.Migrations |
|||
{ |
|||
public partial class Added_Url_To_Event : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AddColumn<string>( |
|||
name: "Url", |
|||
table: "AppEvents", |
|||
type: "nvarchar(69)", |
|||
maxLength: 69, |
|||
nullable: false, |
|||
defaultValue: ""); |
|||
|
|||
migrationBuilder.AddColumn<string>( |
|||
name: "UrlCode", |
|||
table: "AppEvents", |
|||
type: "nvarchar(8)", |
|||
maxLength: 8, |
|||
nullable: false, |
|||
defaultValue: ""); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AppEvents_UrlCode", |
|||
table: "AppEvents", |
|||
column: "UrlCode"); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropIndex( |
|||
name: "IX_AppEvents_UrlCode", |
|||
table: "AppEvents"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "Url", |
|||
table: "AppEvents"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "UrlCode", |
|||
table: "AppEvents"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
@page "/events/{url}" |
|||
@model EventHub.Web.Pages.Events.Detail |
|||
<h1>@Model.Event.Title</h1> |
|||
<p> |
|||
@Model.Event.Description |
|||
</p> |
|||
@ -0,0 +1,29 @@ |
|||
using System.Threading.Tasks; |
|||
using EventHub.Events; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.RazorPages; |
|||
|
|||
namespace EventHub.Web.Pages.Events |
|||
{ |
|||
public class Detail : PageModel |
|||
{ |
|||
[BindProperty(SupportsGet = true)] |
|||
public string Url { get; set; } |
|||
|
|||
public EventDetailDto Event { get; set; } |
|||
|
|||
private readonly IEventAppService _eventAppService; |
|||
|
|||
public Detail(IEventAppService eventAppService) |
|||
{ |
|||
_eventAppService = eventAppService; |
|||
} |
|||
|
|||
public async Task OnGetAsync() |
|||
{ |
|||
var urlCode = EventUrlCodeHelper.GetCodeFromUrl(Url); |
|||
|
|||
Event = await _eventAppService.GetByUrlCodeAsync(urlCode); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue