Browse Source

Create event timing edit section

pull/21/head
EngincanV 6 years ago
parent
commit
4d439acd68
  1. 2
      src/EventHub.Application.Contracts/Events/IEventAppService.cs
  2. 11
      src/EventHub.Application.Contracts/Events/UpdateEventTimingDto.cs
  3. 16
      src/EventHub.Application/Events/EventAppService.cs
  4. 1
      src/EventHub.Domain.Shared/EventHubErrorCodes.cs
  5. 2
      src/EventHub.Domain.Shared/Events/EventConsts.cs
  6. 3
      src/EventHub.Domain.Shared/Localization/EventHub/en.json
  7. 4
      src/EventHub.Domain/Events/Event.cs
  8. 2627
      src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/20210210110442_Added_TimingChangeCount_To_Event.Designer.cs
  9. 24
      src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/20210210110442_Added_TimingChangeCount_To_Event.cs
  10. 7
      src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/EventHubMigrationsDbContextModelSnapshot.cs
  11. 29
      src/EventHub.Web/Controllers/EventController.cs
  12. 1
      src/EventHub.Web/EventHubWebAutoMapperProfile.cs
  13. 15
      src/EventHub.Web/Pages/Events/Edit.cshtml
  14. 14
      src/EventHub.Web/Pages/Events/Edit.cshtml.cs
  15. 29
      src/EventHub.Web/Pages/Events/Edit.js

2
src/EventHub.Application.Contracts/Events/IEventAppService.cs

@ -21,5 +21,7 @@ namespace EventHub.Events
Task<bool> IsEventOwnerAsync(Guid id);
Task UpdateAsync(Guid id, UpdateEventDto input);
Task UpdateEventTimingAsync(Guid id, UpdateEventTimingDto input);
}
}

11
src/EventHub.Application.Contracts/Events/UpdateEventTimingDto.cs

@ -0,0 +1,11 @@
using System;
namespace EventHub.Events
{
public class UpdateEventTimingDto
{
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
}

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

@ -205,5 +205,21 @@ namespace EventHub.Events
await _eventRepository.UpdateAsync(updatedEvent);
}
public async Task UpdateEventTimingAsync(Guid id, UpdateEventTimingDto input)
{
var @event = await _eventRepository.GetAsync(id);
if (@event.TimingChangeCount >= EventConsts.MaxTimingChangeCountForUser)
{
throw new BusinessException(EventHubErrorCodes.CantChangeEventTiming)
.WithData("MaxTimingChangeLimit", EventConsts.MaxTimingChangeCountForUser);
}
@event.SetTime(input.StartTime, input.EndTime);
@event.TimingChangeCount = @event.TimingChangeCount + 1;
await _eventRepository.UpdateAsync(@event);
}
}
}

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

@ -10,5 +10,6 @@
public const string CapacityOfEventFull = "EventHub:CapacityOfEventFull";
public const string CapacityCantBeLowerThanRegisteredUserCount = "EventHub:CapacityCantBeLowerThanRegisteredUserCount";
public const string NotAuthorizedToUpdateEventProfile = "EventHub:NotAuthorizedToUpdateEventProfile";
public const string CantChangeEventTiming = "EventHub:CantChangeEventTiming";
}
}

2
src/EventHub.Domain.Shared/Events/EventConsts.cs

@ -20,5 +20,7 @@
public const int MinLanguageLength = 2;
public const int MaxLanguageLength = 16;
public const int MaxTimingChangeCountForUser = 2;
}
}

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

@ -63,6 +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:NotAuthorizedToUpdateEventProfile": "You are not authorized to update the \"{EventTitle}\" event.",
"EventHub:CantChangeEventTiming": "Can not change the event timing more than {MaxTimingChangeLimit} times."
}
}

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

@ -35,7 +35,9 @@ namespace EventHub.Events
public bool IsRemindingEmailSent { get; set; }
public bool IsEmailSentToMembers { get; set; }
public int TimingChangeCount { get; set; }
private Event()
{

2627
src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/20210210110442_Added_TimingChangeCount_To_Event.Designer.cs

File diff suppressed because it is too large

24
src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/20210210110442_Added_TimingChangeCount_To_Event.cs

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace EventHub.Migrations
{
public partial class Added_TimingChangeCount_To_Event : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "TimingChangeCount",
table: "AppEvents",
type: "int",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "TimingChangeCount",
table: "AppEvents");
}
}
}

7
src/EventHub.EntityFrameworkCore.DbMigrations/Migrations/EventHubMigrationsDbContextModelSnapshot.cs

@ -16,10 +16,10 @@ namespace EventHub.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.UseIdentityColumns()
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.2");
.HasAnnotation("ProductVersion", "5.0.3")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("EventHub.Countries.Country", b =>
{
@ -126,6 +126,9 @@ namespace EventHub.Migrations
b.Property<DateTime>("StartTime")
.HasColumnType("datetime2");
b.Property<int>("TimingChangeCount")
.HasColumnType("int");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(128)

29
src/EventHub.Web/Controllers/EventController.cs

@ -0,0 +1,29 @@
using System;
using System.Threading.Tasks;
using EventHub.Events;
using EventHub.Web.Pages.Events;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
namespace EventHub.Web.Controllers
{
[Route("api/event")]
public class EventController : AbpController
{
private readonly IEventAppService _eventAppService;
public EventController(IEventAppService eventAppService)
{
_eventAppService = eventAppService;
}
[Authorize]
[HttpPost]
[Route("update-timing")]
public async Task UpdateEventTiming(EditPageModel.EditEventTimingViewModel input)
{
await _eventAppService.UpdateEventTimingAsync(input.Id, new UpdateEventTimingDto { StartTime = input.StartTime, EndTime = input.EndTime });
}
}
}

1
src/EventHub.Web/EventHubWebAutoMapperProfile.cs

@ -16,6 +16,7 @@ namespace EventHub.Web
CreateMap<EditOrganizationViewModel, UpdateOrganizationDto>();
CreateMap<EventDetailDto, EditPageModel.EditEventViewModel>();
CreateMap<EditPageModel.EditEventViewModel, UpdateEventDto>();
CreateMap<EventDetailDto, EditPageModel.EditEventTimingViewModel>();
}
}
}

15
src/EventHub.Web/Pages/Events/Edit.cshtml

@ -8,6 +8,7 @@
<abp-script src="/Pages/Events/Edit.js"/>
}
<input type="hidden" value="@Model.Url" id="event-detail-url"/>
<div class="container mb-4">
<h1>Edit Event</h1>
@ -43,7 +44,19 @@
</form>
</div>
<div class="tab-pane fade" id="event-timing" role="tabpanel" aria-labelledby="event-timing-tab">
//TODO
<div class="alert alert-info" role="alert">
Note: You can not change the event timing more than two times.
</div>
<div class="alert alert-warning mt-3" role="alert">
Note: If you change the event times, an informational email will be sent to all attendees
</div>
<form method="post" id="Event_Timing_Form">
<abp-input asp-for="EventTiming.Id"/>
<abp-input asp-for="EventTiming.StartTime"/>
<abp-input asp-for="EventTiming.EndTime"/>
<abp-button size="Large" button-type="Primary" type="submit" text="@L["Submit"].Value"/>
</form>
</div>
</div>
</div>

14
src/EventHub.Web/Pages/Events/Edit.cshtml.cs

@ -22,6 +22,9 @@ namespace EventHub.Web.Pages.Events
[BindProperty]
public EditEventViewModel Event { get; set; }
[BindProperty]
public EditEventTimingViewModel EventTiming { get; set; }
public List<SelectListItem> Countries { get; private set; }
public List<SelectListItem> Languages { get; private set; }
@ -38,6 +41,7 @@ namespace EventHub.Web.Pages.Events
var eventDetailDto = await _eventAppService.GetByUrlCodeAsync(urlCode);
Event = ObjectMapper.Map<EventDetailDto, EditEventViewModel>(eventDetailDto);
EventTiming = ObjectMapper.Map<EventDetailDto, EditEventTimingViewModel>(eventDetailDto);
FillLanguages();
await FillCountriesAsync();
@ -143,5 +147,15 @@ namespace EventHub.Web.Pages.Events
[Range(1, int.MaxValue)]
public int? Capacity { get; set; }
}
public class EditEventTimingViewModel
{
[HiddenInput]
public Guid Id { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
}
}

29
src/EventHub.Web/Pages/Events/Edit.js

@ -16,4 +16,33 @@ $(function () {
$("#event-location-group").show();
}
});
$("#Event_Timing_Form").submit(function (e) {
e.preventDefault();
if(!$(this).valid()) {
return false;
}
var data = {
id: $('#EventTiming_Id').val(),
startTime: $('#EventTiming_StartTime').val(),
endTime: $('#EventTiming_EndTime').val()
};
$.ajax({
url: abp.appPath + `api/event/update-timing`,
type: 'POST',
dataType: 'json',
data: data,
success: function (data) {
abp.message
.success("Timing changed successfully!") //TODO: localize it!
.then(data => window.location.href = "/events/" + $("#event-detail-url").val());
},
error: function (data) {
abp.message.error(data.responseJSON.error.message);
}
});
})
});
Loading…
Cancel
Save