mirror of https://github.com/abpframework/eventhub
14 changed files with 230 additions and 12 deletions
@ -0,0 +1,27 @@ |
|||
using System; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public class CreateEventDto |
|||
{ |
|||
public Guid OrganizationId { get; set; } |
|||
|
|||
[Required] |
|||
[StringLength(EventConsts.MaxTitleLength, MinimumLength = EventConsts.MinTitleLength)] |
|||
public string Title { get; set; } |
|||
|
|||
[Required] |
|||
public DateTime StartTime { get; set; } |
|||
|
|||
[Required] |
|||
public DateTime EndTime { get; set; } |
|||
|
|||
[Required] |
|||
[StringLength(EventConsts.MaxDescriptionLength, MinimumLength = EventConsts.MinDescriptionLength)] |
|||
public string Description { get; set; } |
|||
|
|||
public bool IsOnline { get; set; } |
|||
|
|||
public int? Capacity { get; set; } |
|||
}} |
|||
@ -0,0 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public interface IEventAppService : IApplicationService |
|||
{ |
|||
Task CreateAsync(CreateEventDto input); |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public class EventAppService : EventHubAppService, IEventAppService |
|||
{ |
|||
public async Task CreateAsync(CreateEventDto input) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace EventHub.Events |
|||
{ |
|||
public static class EventConsts |
|||
{ |
|||
public const int MinTitleLength = 8; |
|||
public const int MaxTitleLength = 128; |
|||
|
|||
public const int MinDescriptionLength = 50; |
|||
public const int MaxDescriptionLength = 2000; |
|||
} |
|||
} |
|||
@ -1,10 +1,96 @@ |
|||
namespace EventHub.Web.Pages.Events |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using EventHub.Events; |
|||
using EventHub.Organizations; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.Rendering; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; |
|||
|
|||
namespace EventHub.Web.Pages.Events |
|||
{ |
|||
public class New : EventHubPageModel |
|||
{ |
|||
public void OnGet() |
|||
[BindProperty] |
|||
public NewEventViewModel Event { get; set; } |
|||
|
|||
public List<SelectListItem> Organizations { get; set; } |
|||
|
|||
private readonly IEventAppService _eventAppService; |
|||
private readonly IOrganizationAppService _organizationAppService; |
|||
|
|||
public New( |
|||
IEventAppService eventAppService, |
|||
IOrganizationAppService organizationAppService) |
|||
{ |
|||
_eventAppService = eventAppService; |
|||
_organizationAppService = organizationAppService; |
|||
} |
|||
|
|||
public async Task OnGetAsync() |
|||
{ |
|||
Event = new NewEventViewModel |
|||
{ |
|||
StartTime = DateTime.Now.ClearTime().AddDays(1).AddHours(19), |
|||
EndTime = DateTime.Now.ClearTime().AddDays(1).AddHours(21) |
|||
}; |
|||
|
|||
var result = await _organizationAppService.GetMyOrganizationsAsync(); |
|||
Organizations = result.Items.Select( |
|||
organization => new SelectListItem |
|||
{ |
|||
Value = organization.Id.ToString(), |
|||
Text = organization.DisplayName |
|||
} |
|||
).ToList(); |
|||
} |
|||
|
|||
public async Task<IActionResult> OnPostAsync() |
|||
{ |
|||
try |
|||
{ |
|||
ValidateModel(); |
|||
|
|||
var input = ObjectMapper.Map<NewEventViewModel, CreateEventDto>(Event); |
|||
await _eventAppService.CreateAsync(input); |
|||
|
|||
//TODO: Redirect to the event!
|
|||
return RedirectToPage("/"); |
|||
} |
|||
catch (Exception exception) |
|||
{ |
|||
ShowAlert(exception); |
|||
return Page(); |
|||
} |
|||
} |
|||
|
|||
public class NewEventViewModel |
|||
{ |
|||
[SelectItems(nameof(Organizations))] |
|||
[DisplayName("Organization")] |
|||
public Guid OrganizationId { get; set; } |
|||
|
|||
[Required] |
|||
[StringLength(EventConsts.MaxTitleLength, MinimumLength = EventConsts.MinTitleLength)] |
|||
public string Title { get; set; } |
|||
|
|||
[Required] |
|||
public DateTime StartTime { get; set; } |
|||
|
|||
[Required] |
|||
public DateTime EndTime { get; set; } |
|||
|
|||
[Required] |
|||
[StringLength(EventConsts.MaxDescriptionLength, MinimumLength = EventConsts.MinDescriptionLength)] |
|||
[TextArea] |
|||
public string Description { get; set; } |
|||
|
|||
public bool IsOnline { get; set; } |
|||
|
|||
public int? Capacity { get; set; } |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,34 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Xunit; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public class EventAppServiceTests : EventHubApplicationTestBase |
|||
{ |
|||
private readonly IEventAppService _eventAppService; |
|||
private readonly EventHubTestData _testData; |
|||
|
|||
public EventAppServiceTests() |
|||
{ |
|||
_eventAppService = GetRequiredService<IEventAppService>(); |
|||
_testData = GetRequiredService<EventHubTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Create_A_New_Valid_Event() |
|||
{ |
|||
await _eventAppService.CreateAsync( |
|||
new CreateEventDto |
|||
{ |
|||
OrganizationId = _testData.OrganizationVolosoftId, |
|||
Title = "Introduction to the ABP Framework", |
|||
Description = "In this event, we will introduce the ABP Framework and explore the fundamental features.", |
|||
StartTime = DateTime.Now.AddDays(1), |
|||
EndTime = DateTime.Now.AddDays(1).AddHours(3), |
|||
IsOnline = true |
|||
} |
|||
); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue