Browse Source

Truly implement event update.

pull/29/head
Halil İbrahim Kalkan 6 years ago
parent
commit
606d266647
  1. 29
      src/EventHub.Application/Events/EventAppService.cs
  2. 2
      src/EventHub.Domain.Shared/EventHubErrorCodes.cs
  3. 2
      src/EventHub.Domain.Shared/Localization/EventHub/en.json
  4. 2
      src/EventHub.Domain/Events/Event.cs
  5. 28
      src/EventHub.Domain/Events/EventManager.cs
  6. 19
      test/EventHub.Domain.Tests/Events/EventManagerTests.cs

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

@ -9,6 +9,7 @@ using EventHub.Users;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Authorization;
using Volo.Abp.BlobStoring;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Users;
@ -67,7 +68,8 @@ namespace EventHub.Events
@event.SetLocation(input.IsOnline, input.OnlineLink, input.CountryId, input.City);
@event.Language = input.Language;
@event.Capacity = input.Capacity;
await _eventManager.SetCapacityAsync(@event, input.Capacity);
if (input.CoverImageContent != null && input.CoverImageContent.Length > 0)
{
@ -206,23 +208,20 @@ namespace EventHub.Events
if (organization.OwnerUserId != CurrentUser.GetId())
{
throw new BusinessException(EventHubErrorCodes.NotAuthorizedToUpdateEventProfile)
.WithData("EventTitle", @event.Title);
throw new AbpAuthorizationException(
L["EventHub:NotAuthorizedToUpdateEvent"].Value.Replace("{EventTitle}", @event.Title),
EventHubErrorCodes.NotAuthorizedToUpdateEvent
);
}
@event.SetLocation(input.IsOnline, input.OnlineLink, input.CountryId, input.City);
@event.SetTitle(input.Title);
@event.SetDescription(input.Description);
@event.Language = input.Language;
var updatedEvent = await _eventManager.UpdateAsync(
id,
input.CountryId,
input.Title,
input.Description,
input.Language,
input.IsOnline,
input.OnlineLink,
input.City,
input.Capacity
);
await _eventManager.SetCapacityAsync(@event, input.Capacity);
await _eventRepository.UpdateAsync(updatedEvent);
await _eventRepository.UpdateAsync(@event);
}
[Authorize]

2
src/EventHub.Domain.Shared/EventHubErrorCodes.cs

@ -9,7 +9,7 @@
public const string NotAuthorizedToUpdateOrganizationProfile = "EventHub:NotAuthorizedToUpdateOrganizationProfile";
public const string CapacityOfEventFull = "EventHub:CapacityOfEventFull";
public const string CapacityCantBeLowerThanRegisteredUserCount = "EventHub:CapacityCantBeLowerThanRegisteredUserCount";
public const string NotAuthorizedToUpdateEventProfile = "EventHub:NotAuthorizedToUpdateEventProfile";
public const string NotAuthorizedToUpdateEvent = "EventHub:NotAuthorizedToUpdateEvent";
public const string CantChangeEventTiming = "EventHub:CantChangeEventTiming";
}
}

2
src/EventHub.Domain.Shared/Localization/EventHub/en.json

@ -63,7 +63,7 @@
"LocationHasNotSpecifiedYet": "Event {0} has not been specified yet.",
"Language": "Language",
"EventHub:CapacityCantBeLowerThanRegisteredUserCount": "Capacity can not be lower than the currently registered user count.",
"EventHub:NotAuthorizedToUpdateEventProfile": "You are not authorized to update the \"{EventTitle}\" event.",
"EventHub:NotAuthorizedToUpdateEvent": "You are not authorized to update the \"{EventTitle}\" event.",
"CoverImage": "Cover Image",
"EventHub:CantChangeEventTiming": "Can not change the event timing more than {MaxTimingChangeLimit} times.",
"EventCoverImageEditSuccessMessage": "The event's cover image has been changed successfully.",

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

@ -30,7 +30,7 @@ namespace EventHub.Events
public string Language { get; set; }
public int? Capacity { get; set; }
public int? Capacity { get; internal set; }
public bool IsRemindingEmailSent { get; set; }

28
src/EventHub.Domain/Events/EventManager.cs

@ -44,32 +44,20 @@ namespace EventHub.Events
);
}
public async Task<Event> UpdateAsync(
Guid id,
Guid? countryId,
string title,
string description,
string language,
bool isOnline,
string onlineLink,
string city,
public async Task SetCapacityAsync(
Event @event,
int? capacity)
{
var @event = await _eventRepository.GetAsync(id);
var registeredUserCount = await _eventRegistrationRepository.CountAsync(x => x.EventId == @event.Id);
if (capacity < registeredUserCount)
if (capacity.HasValue)
{
throw new BusinessException(EventHubErrorCodes.CapacityCantBeLowerThanRegisteredUserCount);
var registeredUserCount = await _eventRegistrationRepository.CountAsync(x => x.EventId == @event.Id);
if (capacity.Value < registeredUserCount)
{
throw new BusinessException(EventHubErrorCodes.CapacityCantBeLowerThanRegisteredUserCount);
}
}
@event.SetTitle(title);
@event.SetDescription(description);
@event.SetLocation(isOnline, onlineLink, countryId, city);
@event.Capacity = capacity;
@event.Language = language;
return @event;
}
}
}

19
test/EventHub.Domain.Tests/Events/EventManagerTests.cs

@ -47,26 +47,19 @@ namespace EventHub.Events
}
[Fact]
public async Task Should_Update_The_Event()
public async Task Should_Update_The_Event_Capacity()
{
await WithUnitOfWorkAsync(async () =>
{
var @event = await _eventRepository.GetAsync(_testData.AbpMicroservicesFutureEventId);
var newCapacity = @event.Capacity.HasValue ? @event.Capacity.Value + 1 : 42;
var updatedEvent = await _eventManager.UpdateAsync(
@event.Id,
null,
"Updated_Microservice_Event_Title",
"Updated_Microservice_Event_Description" + @event.Description,
"en",
true,
"online_link",
null,
null
await _eventManager.SetCapacityAsync(
@event,
newCapacity
);
@event.Title.ShouldBe(updatedEvent.Title);
@event.Description.ShouldBe(updatedEvent.Description);
@event.Capacity.ShouldBe(newCapacity);
});
}
}

Loading…
Cancel
Save