mirror of https://github.com/abpframework/eventhub
16 changed files with 2794 additions and 29 deletions
@ -1,12 +1,49 @@ |
|||
using System.Threading.Tasks; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EventHub.Organizations; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public class EventAppService : EventHubAppService, IEventAppService |
|||
{ |
|||
private readonly IRepository<Organization, Guid> _organizationRepository; |
|||
private readonly EventManager _eventManager; |
|||
private readonly IRepository<Event, Guid> _eventRepository; |
|||
|
|||
public EventAppService( |
|||
EventManager eventManager, |
|||
IRepository<Organization, Guid> organizationRepository, |
|||
IRepository<Event, Guid> eventRepository) |
|||
{ |
|||
_eventManager = eventManager; |
|||
_organizationRepository = organizationRepository; |
|||
_eventRepository = eventRepository; |
|||
} |
|||
|
|||
[Authorize] |
|||
public async Task CreateAsync(CreateEventDto input) |
|||
{ |
|||
var organization = await _organizationRepository.GetAsync(input.OrganizationId); |
|||
|
|||
if (organization.OwnerUserId != CurrentUser.GetId()) |
|||
{ |
|||
throw new BusinessException(EventHubErrorCodes.NotAuthorizedToCreateEventInThisOrganization) |
|||
.WithData("OrganizationName", organization.DisplayName); |
|||
} |
|||
|
|||
var @event = await _eventManager.CreateAsync( |
|||
organization, |
|||
input.Title, |
|||
input.StartTime, |
|||
input.EndTime, |
|||
input.Description |
|||
); |
|||
|
|||
await _eventRepository.InsertAsync(@event); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,62 @@ |
|||
using System; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public class Event : FullAuditedAggregateRoot<Guid> |
|||
{ |
|||
public Guid OrganizationId { get; private set; } |
|||
|
|||
public string Title { get; private set; } |
|||
|
|||
public DateTime StartTime { get; private set; } |
|||
|
|||
public DateTime EndTime { get; private set; } |
|||
|
|||
public string Description { get; private set; } |
|||
|
|||
public bool IsOnline { get; set; } |
|||
|
|||
public int? Capacity { get; set; } |
|||
|
|||
private Event() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public Event( |
|||
Guid id, |
|||
Guid organizationId, |
|||
string title, |
|||
DateTime startTime, |
|||
DateTime endTime, |
|||
string description) |
|||
: base(id) |
|||
{ |
|||
OrganizationId = organizationId; |
|||
SetTitle(title); |
|||
SetDescription(description); |
|||
SetTime(startTime, endTime); |
|||
} |
|||
|
|||
public Event SetTitle(string title) |
|||
{ |
|||
Title = Check.NotNullOrWhiteSpace(title, nameof(title), EventConsts.MaxTitleLength, EventConsts.MinTitleLength); |
|||
return this; |
|||
} |
|||
|
|||
public Event SetDescription(string description) |
|||
{ |
|||
Description = Check.NotNullOrWhiteSpace(description, nameof(description), EventConsts.MaxDescriptionLength, EventConsts.MinDescriptionLength); |
|||
return this; |
|||
} |
|||
|
|||
public Event SetTime(DateTime startTime, DateTime endTime) |
|||
{ |
|||
StartTime = startTime; |
|||
EndTime = endTime; |
|||
return this; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EventHub.Organizations; |
|||
using Volo.Abp.Domain.Services; |
|||
|
|||
namespace EventHub.Events |
|||
{ |
|||
public class EventManager : DomainService |
|||
{ |
|||
public async Task<Event> CreateAsync( |
|||
Organization organization, |
|||
string title, |
|||
DateTime startTime, |
|||
DateTime endTime, |
|||
string description) |
|||
{ |
|||
return new Event( |
|||
GuidGenerator.Create(), |
|||
organization.Id, |
|||
title, |
|||
startTime, |
|||
endTime, |
|||
description |
|||
); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,146 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace EventHub.Migrations |
|||
{ |
|||
public partial class Added_Events : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Description", |
|||
table: "AppOrganizations", |
|||
type: "nvarchar(1000)", |
|||
maxLength: 1000, |
|||
nullable: false, |
|||
defaultValue: "", |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(max)", |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.AddColumn<DateTime>( |
|||
name: "CreationTime", |
|||
table: "AppOrganizations", |
|||
type: "datetime2", |
|||
nullable: false, |
|||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); |
|||
|
|||
migrationBuilder.AddColumn<Guid>( |
|||
name: "CreatorId", |
|||
table: "AppOrganizations", |
|||
type: "uniqueidentifier", |
|||
nullable: true); |
|||
|
|||
migrationBuilder.AddColumn<Guid>( |
|||
name: "DeleterId", |
|||
table: "AppOrganizations", |
|||
type: "uniqueidentifier", |
|||
nullable: true); |
|||
|
|||
migrationBuilder.AddColumn<DateTime>( |
|||
name: "DeletionTime", |
|||
table: "AppOrganizations", |
|||
type: "datetime2", |
|||
nullable: true); |
|||
|
|||
migrationBuilder.AddColumn<bool>( |
|||
name: "IsDeleted", |
|||
table: "AppOrganizations", |
|||
type: "bit", |
|||
nullable: false, |
|||
defaultValue: false); |
|||
|
|||
migrationBuilder.AddColumn<DateTime>( |
|||
name: "LastModificationTime", |
|||
table: "AppOrganizations", |
|||
type: "datetime2", |
|||
nullable: true); |
|||
|
|||
migrationBuilder.AddColumn<Guid>( |
|||
name: "LastModifierId", |
|||
table: "AppOrganizations", |
|||
type: "uniqueidentifier", |
|||
nullable: true); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "AppEvents", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
OrganizationId = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
Title = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false), |
|||
StartTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
EndTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
Description = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false), |
|||
IsOnline = table.Column<bool>(type: "bit", nullable: false), |
|||
Capacity = table.Column<int>(type: "int", nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AppEvents", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AppEvents_OrganizationId_StartTime", |
|||
table: "AppEvents", |
|||
columns: new[] { "OrganizationId", "StartTime" }); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AppEvents_StartTime", |
|||
table: "AppEvents", |
|||
column: "StartTime"); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AppEvents"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "CreationTime", |
|||
table: "AppOrganizations"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "CreatorId", |
|||
table: "AppOrganizations"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "DeleterId", |
|||
table: "AppOrganizations"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "DeletionTime", |
|||
table: "AppOrganizations"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "IsDeleted", |
|||
table: "AppOrganizations"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "LastModificationTime", |
|||
table: "AppOrganizations"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "LastModifierId", |
|||
table: "AppOrganizations"); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Description", |
|||
table: "AppOrganizations", |
|||
type: "nvarchar(max)", |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(1000)", |
|||
oldMaxLength: 1000); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue