mirror of https://github.com/abpframework/eventhub
14 changed files with 362 additions and 6 deletions
@ -0,0 +1,36 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace EventHub.Events |
||||
|
{ |
||||
|
public class UpdateEventDto |
||||
|
{ |
||||
|
[Required] |
||||
|
[StringLength(EventConsts.MaxTitleLength, MinimumLength = EventConsts.MinTitleLength)] |
||||
|
public string Title { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[StringLength(EventConsts.MaxDescriptionLength, MinimumLength = EventConsts.MinDescriptionLength)] |
||||
|
public string Description { get; set; } |
||||
|
|
||||
|
public bool IsOnline { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(EventConsts.MaxOnlineLinkLength, MinimumLength = EventConsts.MinOnlineLinkLength)] |
||||
|
public string OnlineLink { get; set; } |
||||
|
|
||||
|
public Guid? CountryId { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(EventConsts.MaxCityLength, MinimumLength = EventConsts.MinCityLength)] |
||||
|
public string City { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(EventConsts.MaxLanguageLength, MinimumLength = EventConsts.MinLanguageLength)] |
||||
|
public string Language { get; set; } |
||||
|
|
||||
|
[Range(1, int.MaxValue)] |
||||
|
public int? Capacity { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
@page "/event/edit/{url}" |
||||
|
@inject IHtmlLocalizer<EventHubResource> L |
||||
|
@using EventHub.Localization |
||||
|
@using Microsoft.AspNetCore.Mvc.Localization |
||||
|
@model EventHub.Web.Pages.Events.EditPageModel |
||||
|
|
||||
|
@section scripts { |
||||
|
<abp-script src="/Pages/Events/Edit.js"/> |
||||
|
} |
||||
|
|
||||
|
<div class="container mb-4"> |
||||
|
<h1>Edit Event</h1> |
||||
|
|
||||
|
<ul class="nav nav-pills mt-3 mb-3" id="pills-tab" role="tablist"> |
||||
|
<li class="nav-item"> |
||||
|
<a class="nav-link active" id="event-info-tab" data-toggle="pill" href="#event-info" role="tab" aria-controls="event-info" aria-selected="true">Event Information</a> |
||||
|
</li> |
||||
|
<li class="nav-item"> |
||||
|
<a class="nav-link" id="event-timing-tab" data-toggle="pill" href="#event-timing" role="tab" aria-controls="event-timing" aria-selected="false">Event Timing</a> |
||||
|
</li> |
||||
|
</ul> |
||||
|
<div class="tab-content" id="pills-tabContent"> |
||||
|
<div class="tab-pane fade show active" id="event-info" role="tabpanel" aria-labelledby="event-info-tab"> |
||||
|
<form method="post"> |
||||
|
<abp-input asp-for="Event.Id" /> |
||||
|
<abp-input asp-for="Event.Title"/> |
||||
|
<abp-input asp-for="Event.Description"/> |
||||
|
<abp-input asp-for="Event.IsOnline"/> |
||||
|
|
||||
|
<div id="event-link-group" style="display: none"> |
||||
|
<abp-input asp-for="Event.OnlineLink"/> |
||||
|
</div> |
||||
|
|
||||
|
<div id="event-location-group"> |
||||
|
<abp-select asp-for="Event.CountryId"/> |
||||
|
<abp-input asp-for="Event.City"/> |
||||
|
</div> |
||||
|
|
||||
|
<abp-select asp-for="Event.Language"/> |
||||
|
<abp-input asp-for="Event.Capacity"/> |
||||
|
|
||||
|
<abp-button size="Large" button-type="Primary" type="submit" text="@L["Submit"].Value"/> |
||||
|
</form> |
||||
|
</div> |
||||
|
<div class="tab-pane fade" id="event-timing" role="tabpanel" aria-labelledby="event-timing-tab"> |
||||
|
//TODO |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
@ -0,0 +1,147 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Globalization; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using EventHub.Events; |
||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.AspNetCore.Mvc.Rendering; |
||||
|
using NUglify.Helpers; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; |
||||
|
|
||||
|
namespace EventHub.Web.Pages.Events |
||||
|
{ |
||||
|
public class EditPageModel : EventHubPageModel |
||||
|
{ |
||||
|
[BindProperty(SupportsGet = true)] |
||||
|
public string Url { get; set; } |
||||
|
|
||||
|
[BindProperty] |
||||
|
public EditEventViewModel Event { get; set; } |
||||
|
|
||||
|
public List<SelectListItem> Countries { get; private set; } |
||||
|
public List<SelectListItem> Languages { get; private set; } |
||||
|
|
||||
|
private readonly IEventAppService _eventAppService; |
||||
|
|
||||
|
public EditPageModel(IEventAppService eventAppService) |
||||
|
{ |
||||
|
_eventAppService = eventAppService; |
||||
|
} |
||||
|
|
||||
|
public async Task OnGetAsync() |
||||
|
{ |
||||
|
var urlCode = EventUrlCodeHelper.GetCodeFromUrl(Url); |
||||
|
|
||||
|
var eventDetailDto = await _eventAppService.GetByUrlCodeAsync(urlCode); |
||||
|
Event = ObjectMapper.Map<EventDetailDto, EditEventViewModel>(eventDetailDto); |
||||
|
|
||||
|
FillLanguages(); |
||||
|
await FillCountriesAsync(); |
||||
|
await GetLocationInfoAsync(); |
||||
|
} |
||||
|
|
||||
|
public async Task<IActionResult> OnPostAsync() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
ValidateModel(); |
||||
|
|
||||
|
var input = ObjectMapper.Map<EditEventViewModel, UpdateEventDto>(Event); |
||||
|
await _eventAppService.UpdateAsync(Event.Id, input); |
||||
|
|
||||
|
return RedirectToPage("./Detail", new { url = Url }); |
||||
|
} |
||||
|
catch (Exception exception) |
||||
|
{ |
||||
|
ShowAlert(exception); |
||||
|
FillLanguages(); |
||||
|
await FillCountriesAsync(); |
||||
|
return Page(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private async Task FillCountriesAsync() |
||||
|
{ |
||||
|
var result = await _eventAppService.GetCountriesLookupAsync(); |
||||
|
|
||||
|
Countries = result.Select( |
||||
|
country => new SelectListItem |
||||
|
{ |
||||
|
Value = country.Id.ToString(), |
||||
|
Text = country.Name |
||||
|
} |
||||
|
).ToList(); |
||||
|
} |
||||
|
|
||||
|
private void FillLanguages() |
||||
|
{ |
||||
|
var result = CultureInfo.GetCultures(CultureTypes.NeutralCultures) |
||||
|
.DistinctBy(x => x.EnglishName) |
||||
|
.OrderBy(x => x.EnglishName) |
||||
|
.ToList(); |
||||
|
result.Remove(result.Single(x => x.TwoLetterISOLanguageName == "iv")); // Invariant Language
|
||||
|
|
||||
|
Languages = result.Select( |
||||
|
cultureInfo => new SelectListItem |
||||
|
{ |
||||
|
Value = cultureInfo.TwoLetterISOLanguageName, |
||||
|
Text = cultureInfo.EnglishName |
||||
|
} |
||||
|
).ToList(); |
||||
|
} |
||||
|
|
||||
|
private async Task GetLocationInfoAsync() |
||||
|
{ |
||||
|
var eventLocationDto = await _eventAppService.GetLocationAsync(Event.Id); |
||||
|
Event.City = eventLocationDto.City; |
||||
|
Event.OnlineLink = eventLocationDto.OnlineLink; |
||||
|
|
||||
|
Event.CountryId = Guid.TryParse( |
||||
|
Countries.FirstOrDefault(x => x.Text == eventLocationDto.Country)?.Value, |
||||
|
out var countryId |
||||
|
) |
||||
|
? countryId |
||||
|
: null; |
||||
|
} |
||||
|
|
||||
|
public class EditEventViewModel |
||||
|
{ |
||||
|
[HiddenInput] |
||||
|
public Guid Id { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[StringLength(EventConsts.MaxTitleLength, MinimumLength = EventConsts.MinTitleLength)] |
||||
|
public string Title { get; set; } |
||||
|
|
||||
|
[Required] |
||||
|
[StringLength(EventConsts.MaxDescriptionLength, MinimumLength = EventConsts.MinDescriptionLength)] |
||||
|
[TextArea] |
||||
|
public string Description { get; set; } |
||||
|
|
||||
|
public bool IsOnline { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(EventConsts.MaxOnlineLinkLength, MinimumLength = EventConsts.MinOnlineLinkLength)] |
||||
|
public string OnlineLink { get; set; } |
||||
|
|
||||
|
[SelectItems(nameof(Countries))] |
||||
|
[DisplayName("Country")] |
||||
|
public Guid? CountryId { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
[StringLength(EventConsts.MaxCityLength, MinimumLength = EventConsts.MinCityLength)] |
||||
|
public string City { get; set; } |
||||
|
|
||||
|
[SelectItems(nameof(Languages))] |
||||
|
[DisplayName("Language")] |
||||
|
public string Language { get; set; } |
||||
|
|
||||
|
[Range(1, int.MaxValue)] |
||||
|
public int? Capacity { get; set; } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
$(function () { |
||||
|
$("#Event_CountryId").prepend("<option value=''></option>"); |
||||
|
$("#Event_Language").prepend("<option value=''></option>"); |
||||
|
|
||||
|
if($("#Event_IsOnline").is(":checked")) { |
||||
|
$("#event-link-group").show(); |
||||
|
$("#event-location-group").hide(); |
||||
|
} |
||||
|
|
||||
|
$('#Event_IsOnline').click(function() { |
||||
|
if ($(this).is(':checked')) { |
||||
|
$("#event-link-group").show(); |
||||
|
$("#event-location-group").hide(); |
||||
|
}else{ |
||||
|
$("#event-link-group").hide(); |
||||
|
$("#event-location-group").show(); |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
Loading…
Reference in new issue