mirror of https://github.com/abpframework/eventhub
14 changed files with 191 additions and 14 deletions
@ -0,0 +1,19 @@ |
|||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
|
namespace EventHub.Organizations |
||||
|
{ |
||||
|
public class CreateOrganizationDto |
||||
|
{ |
||||
|
[Required] |
||||
|
[StringLength(OrganizationConsts.MaxNameLength, MinimumLength = OrganizationConsts.MinNameLength)] |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[StringLength(OrganizationConsts.MaxDisplayNameLength, MinimumLength = OrganizationConsts.MinDisplayNameLength)] |
||||
|
public string DisplayName { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[StringLength(OrganizationConsts.MaxDescriptionNameLength, MinimumLength = OrganizationConsts.MinDescriptionNameLength)] |
||||
|
public string Description { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -1,7 +0,0 @@ |
|||||
namespace EventHub |
|
||||
{ |
|
||||
public static class EventHubDomainErrorCodes |
|
||||
{ |
|
||||
/* You can add your business exception error codes here, as constants */ |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,7 @@ |
|||||
|
namespace EventHub |
||||
|
{ |
||||
|
public static class EventHubErrorCodes |
||||
|
{ |
||||
|
public const string OrganizationNameAlreadyExists = "EventHub:OrganizationNameAlreadyExists"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
|
||||
|
namespace EventHub.Organizations |
||||
|
{ |
||||
|
public class OrganizationManager : DomainService |
||||
|
{ |
||||
|
private readonly IRepository<Organization, Guid> _organizationRepository; |
||||
|
|
||||
|
public OrganizationManager(IRepository<Organization, Guid> organizationRepository) |
||||
|
{ |
||||
|
_organizationRepository = organizationRepository; |
||||
|
} |
||||
|
|
||||
|
public async Task<Organization> CreateAsync( |
||||
|
Guid ownerUserId, |
||||
|
string name, |
||||
|
string displayName, |
||||
|
string description) |
||||
|
{ |
||||
|
if (await _organizationRepository.AnyAsync(o => o.Name == name)) |
||||
|
{ |
||||
|
throw new BusinessException(EventHubErrorCodes.OrganizationNameAlreadyExists) |
||||
|
.WithData("Name", name); |
||||
|
} |
||||
|
|
||||
|
var organization = new Organization( |
||||
|
GuidGenerator.Create(), |
||||
|
ownerUserId, |
||||
|
name, |
||||
|
displayName, |
||||
|
description |
||||
|
); |
||||
|
|
||||
|
return await _organizationRepository.InsertAsync(organization); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,10 +1,71 @@ |
|||||
namespace EventHub.Web.Pages.Organizations |
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Threading.Tasks; |
||||
|
using EventHub.Organizations; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Volo.Abp.AspNetCore.ExceptionHandling; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; |
||||
|
|
||||
|
namespace EventHub.Web.Pages.Organizations |
||||
{ |
{ |
||||
|
[Authorize] |
||||
public class New : EventHubPageModel |
public class New : EventHubPageModel |
||||
{ |
{ |
||||
|
[BindProperty] |
||||
|
public CreateOrganizationViewModel Organization { get; set; } |
||||
|
|
||||
|
private readonly IOrganizationAppService _organizationAppService; |
||||
|
private readonly IExceptionToErrorInfoConverter _errorInfoConverter; |
||||
|
|
||||
|
public New( |
||||
|
IOrganizationAppService organizationAppService, |
||||
|
IExceptionToErrorInfoConverter errorInfoConverter) |
||||
|
{ |
||||
|
_organizationAppService = organizationAppService; |
||||
|
_errorInfoConverter = errorInfoConverter; |
||||
|
} |
||||
|
|
||||
public void OnGet() |
public void OnGet() |
||||
{ |
{ |
||||
|
Organization = new CreateOrganizationViewModel(); |
||||
|
} |
||||
|
|
||||
|
public async Task<IActionResult> OnPostAsync() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
ValidateModel(); |
||||
|
|
||||
|
var input = ObjectMapper.Map<CreateOrganizationViewModel, CreateOrganizationDto>(Organization); |
||||
|
await _organizationAppService.CreateAsync(input); |
||||
|
|
||||
|
return RedirectToPage("./OrganizationProfile", new {name = Organization.Name}); |
||||
|
} |
||||
|
catch (Exception exception) |
||||
|
{ |
||||
|
Logger.LogException(exception); |
||||
|
var errorInfo = _errorInfoConverter.Convert(exception, false); |
||||
|
Alerts.Danger(errorInfo.Message); |
||||
|
return Page(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class CreateOrganizationViewModel |
||||
|
{ |
||||
|
[Required] |
||||
|
[StringLength(OrganizationConsts.MaxNameLength, MinimumLength = OrganizationConsts.MinNameLength)] |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[StringLength(OrganizationConsts.MaxDisplayNameLength, MinimumLength = OrganizationConsts.MinDisplayNameLength)] |
||||
|
public string DisplayName { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[StringLength(OrganizationConsts.MaxDescriptionNameLength, MinimumLength = OrganizationConsts.MinDescriptionNameLength)] |
||||
|
[TextArea] |
||||
|
public string Description { get; set; } |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,3 @@ |
|||||
|
@page "/organizations/{name}" |
||||
|
@model EventHub.Web.Pages.Organizations.OrganizationProfile |
||||
|
<h1>Organization: @Model.Name</h1> |
||||
@ -0,0 +1,17 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.AspNetCore.Mvc.RazorPages; |
||||
|
|
||||
|
namespace EventHub.Web.Pages.Organizations |
||||
|
{ |
||||
|
public class OrganizationProfile : PageModel |
||||
|
{ |
||||
|
[BindProperty(SupportsGet = true)] |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public async Task OnGetAsync() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue