From 6d87dd3414727cfbd4fc242d9a8abc57079656b5 Mon Sep 17 00:00:00 2001 From: Berkan Sasmaz Date: Tue, 11 May 2021 01:18:29 +0300 Subject: [PATCH] Revise event edit page --- .../Events/EventDetailDto.cs | 8 + .../Events/IEventAppService.cs | 4 - .../Events/UpdateEventDto.cs | 3 + .../EventHubApplicationAutoMapperProfile.cs | 1 + .../Events/EventAppService.cs | 24 +- .../Controllers/EventController.cs | 31 --- .../EventHubWebAutoMapperProfile.cs | 1 - src/EventHub.Web/Pages/Events/Edit.cshtml | 187 +++++++++------ src/EventHub.Web/Pages/Events/Edit.cshtml.cs | 135 ++++++----- src/EventHub.Web/Pages/Events/Edit.js | 224 ++++++------------ src/EventHub.Web/Pages/Events/New.cshtml.cs | 37 ++- .../Pages/Organizations/Edit.cshtml | 9 +- .../Pages/Organizations/Edit.cshtml.cs | 4 +- 13 files changed, 303 insertions(+), 365 deletions(-) diff --git a/src/EventHub.Application.Contracts/Events/EventDetailDto.cs b/src/EventHub.Application.Contracts/Events/EventDetailDto.cs index 973c958..de41e99 100644 --- a/src/EventHub.Application.Contracts/Events/EventDetailDto.cs +++ b/src/EventHub.Application.Contracts/Events/EventDetailDto.cs @@ -5,6 +5,8 @@ namespace EventHub.Events { public class EventDetailDto : EntityDto { + public Guid OrganizationId { get; set; } + public string OrganizationName { get; set; } public string OrganizationDisplayName { get; set; } @@ -22,6 +24,12 @@ namespace EventHub.Events public byte[] CoverImageContent { get; set; } public bool IsOnline { get; set; } + + public string OnlineLink { get; set; } + + public Guid? CountryId { get; set; } + + public string City { get; set; } public bool IsLive { get; set; } diff --git a/src/EventHub.Application.Contracts/Events/IEventAppService.cs b/src/EventHub.Application.Contracts/Events/IEventAppService.cs index ca9132b..07db0ad 100644 --- a/src/EventHub.Application.Contracts/Events/IEventAppService.cs +++ b/src/EventHub.Application.Contracts/Events/IEventAppService.cs @@ -21,9 +21,5 @@ namespace EventHub.Events Task IsEventOwnerAsync(Guid id); Task UpdateAsync(Guid id, UpdateEventDto input); - - Task UpdateEventTimingAsync(Guid id, UpdateEventTimingDto input); - - Task SaveCoverImageAsync(Guid id, byte[] coverImageContent); } } diff --git a/src/EventHub.Application.Contracts/Events/UpdateEventDto.cs b/src/EventHub.Application.Contracts/Events/UpdateEventDto.cs index b768cd5..459816b 100644 --- a/src/EventHub.Application.Contracts/Events/UpdateEventDto.cs +++ b/src/EventHub.Application.Contracts/Events/UpdateEventDto.cs @@ -13,6 +13,9 @@ namespace EventHub.Events [Required] [StringLength(EventConsts.MaxDescriptionLength, MinimumLength = EventConsts.MinDescriptionLength)] public string Description { get; set; } + + [CanBeNull] + public byte[] CoverImageContent { get; set; } public bool IsOnline { get; set; } diff --git a/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs b/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs index 483f44e..ab8409e 100644 --- a/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs +++ b/src/EventHub.Application/EventHubApplicationAutoMapperProfile.cs @@ -24,6 +24,7 @@ namespace EventHub .Ignore(x => x.OrganizationDisplayName) .Ignore(x => x.IsLiveNow); CreateMap() + .Ignore(x => x.OrganizationId) .Ignore(x => x.OrganizationName) .Ignore(x => x.OrganizationDisplayName); diff --git a/src/EventHub.Application/Events/EventAppService.cs b/src/EventHub.Application/Events/EventAppService.cs index ae5aa17..09b439d 100644 --- a/src/EventHub.Application/Events/EventAppService.cs +++ b/src/EventHub.Application/Events/EventAppService.cs @@ -176,6 +176,7 @@ namespace EventHub.Events var dto = ObjectMapper.Map(@event); + dto.OrganizationId = organization.Id; dto.OrganizationName = organization.Name; dto.OrganizationDisplayName = organization.DisplayName; dto.OwnerEmail = (await _userRepository.GetAsync(organization.OwnerUserId)).Email; @@ -249,29 +250,16 @@ namespace EventHub.Events @event.Language = input.Language; await _eventManager.SetCapacityAsync(@event, input.Capacity); - - await _eventRepository.UpdateAsync(@event); - } - - [Authorize] - public async Task UpdateEventTimingAsync(Guid id, UpdateEventTimingDto input) - { - var @event = await _eventRepository.GetAsync(id); - - if (@event.TimingChangeCount >= EventConsts.MaxTimingChangeCountForUser) + + if (input.CoverImageContent != null && input.CoverImageContent.Length > 0) { - throw new BusinessException(EventHubErrorCodes.CantChangeEventTiming) - .WithData("MaxTimingChangeLimit", EventConsts.MaxTimingChangeCountForUser); + await SaveCoverImageAsync(@event.Id, input.CoverImageContent); } - - @event.SetTime(input.StartTime, input.EndTime); - @event.TimingChangeCount++; - + await _eventRepository.UpdateAsync(@event); } - [Authorize] - public async Task SaveCoverImageAsync(Guid id, byte[] coverImageContent) + private async Task SaveCoverImageAsync(Guid id, byte[] coverImageContent) { var blobName = id.ToString(); diff --git a/src/EventHub.Web/Controllers/EventController.cs b/src/EventHub.Web/Controllers/EventController.cs index c497a2a..fcc385b 100644 --- a/src/EventHub.Web/Controllers/EventController.cs +++ b/src/EventHub.Web/Controllers/EventController.cs @@ -1,12 +1,8 @@ -using System.IO; using System.Linq; 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; -using EditPageModel = EventHub.Web.Pages.Events.EditPageModel; namespace EventHub.Web.Controllers { @@ -32,32 +28,5 @@ namespace EventHub.Web.Controllers ViewData = ViewData }; } - - [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 }); - } - - [HttpPost] - [Authorize] - [Route("save-cover-image")] - public async Task SaveCoverImage([FromForm] EventCoverImageInput input) - { - var coverImageContent = new byte[] {}; - - if (input.CoverImageFile.Length > 0) - { - using (var memoryStream = new MemoryStream()) - { - await input.CoverImageFile.CopyToAsync(memoryStream); - coverImageContent = memoryStream.ToArray(); - } - - await _eventAppService.SaveCoverImageAsync(input.EventId, coverImageContent); - } - } } } \ No newline at end of file diff --git a/src/EventHub.Web/EventHubWebAutoMapperProfile.cs b/src/EventHub.Web/EventHubWebAutoMapperProfile.cs index c5a306d..94e74fc 100644 --- a/src/EventHub.Web/EventHubWebAutoMapperProfile.cs +++ b/src/EventHub.Web/EventHubWebAutoMapperProfile.cs @@ -18,7 +18,6 @@ namespace EventHub.Web CreateMap(); CreateMap(); CreateMap(); - CreateMap(); } } } diff --git a/src/EventHub.Web/Pages/Events/Edit.cshtml b/src/EventHub.Web/Pages/Events/Edit.cshtml index 0f9f938..461b38e 100644 --- a/src/EventHub.Web/Pages/Events/Edit.cshtml +++ b/src/EventHub.Web/Pages/Events/Edit.cshtml @@ -2,90 +2,127 @@ @inject IHtmlLocalizer L @using EventHub.Localization @using Microsoft.AspNetCore.Mvc.Localization -@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal @model EventHub.Web.Pages.Events.EditPageModel @section scripts { } - -
-

@L["EditEvent"]

- - -
- - - - + +
+
+
- - -
- - -
+
+
+

Edit Event

+
+
+ + +
+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
- - +
+

Cover Image

+
+
+
+ @if (Model.CoverImageContent != null && Model.CoverImageContent.Length > 0) + { + + } + else + { + + } +
+
+
+
+

For horizontal format 600x300 sized upload images.

+ + +
+
+
+
+
+ +
+ +
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
- - - - - - -
- - - - - -
- -
- - - -
- -
- - - @L["ChooseEventCoverImageInfo"] +
+ +
-
-
- - - -
- - - - - @L["EventTimingChangeEmailNotificationMessage"] - - - - - - - - - - - event-cover-image-preview - - - -
\ No newline at end of file +
+
+
+
+
+ \ No newline at end of file diff --git a/src/EventHub.Web/Pages/Events/Edit.cshtml.cs b/src/EventHub.Web/Pages/Events/Edit.cshtml.cs index 1aa2b6f..6d6b76e 100644 --- a/src/EventHub.Web/Pages/Events/Edit.cshtml.cs +++ b/src/EventHub.Web/Pages/Events/Edit.cshtml.cs @@ -3,10 +3,11 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Globalization; +using System.IO; using System.Linq; using System.Threading.Tasks; using EventHub.Events; -using EventHub.Events.Registrations; +using EventHub.Organizations; using EventHub.Web.Helpers; using JetBrains.Annotations; using Microsoft.AspNetCore.Http; @@ -25,38 +26,34 @@ namespace EventHub.Web.Pages.Events [BindProperty] public EditEventViewModel Event { get; set; } - [BindProperty] - public EditEventTimingViewModel EventTiming { get; set; } - - public int AttendeeCount { get; set; } - + public List Organizations { get; private set; } public List Countries { get; private set; } public List Languages { get; private set; } + public byte[] CoverImageContent { get; private set; } private readonly IEventAppService _eventAppService; - private readonly IEventRegistrationAppService _eventRegistrationAppService; + private readonly IOrganizationAppService _organizationAppService; - public EditPageModel(IEventAppService eventAppService, IEventRegistrationAppService eventRegistrationAppService) + public EditPageModel( + IEventAppService eventAppService, + IOrganizationAppService organizationAppService) { _eventAppService = eventAppService; - _eventRegistrationAppService = eventRegistrationAppService; + _organizationAppService = organizationAppService; } public async Task OnGetAsync() { var urlCode = EventUrlCodeHelper.GetCodeFromUrl(Url); - var eventDetailDto = await _eventAppService.GetByUrlCodeAsync(urlCode); + CoverImageContent = eventDetailDto.CoverImageContent; Event = ObjectMapper.Map(eventDetailDto); - EventTiming = ObjectMapper.Map(eventDetailDto); - FillLanguages(); + await FillOrganizationsAsync(); await FillCountriesAsync(); - await GetLocationInfoAsync(); - - AttendeeCount = await _eventRegistrationAppService.GetAttendeeCountAsync(Event.Id); + FillLanguages(); } - + public async Task OnPostAsync() { try @@ -64,6 +61,16 @@ namespace EventHub.Web.Pages.Events ValidateModel(); var input = ObjectMapper.Map(Event); + + if (Event.CoverImageFile != null && Event.CoverImageFile.Length > 0) + { + using (var memoryStream = new MemoryStream()) + { + await Event.CoverImageFile.CopyToAsync(memoryStream); + input.CoverImageContent = memoryStream.ToArray(); + } + } + await _eventAppService.UpdateAsync(Event.Id, input); return RedirectToPage("./Detail", new { url = Url }); @@ -71,11 +78,29 @@ namespace EventHub.Web.Pages.Events catch (Exception exception) { ShowAlert(exception); - FillLanguages(); + await FillOrganizationsAsync(); await FillCountriesAsync(); + FillLanguages(); return Page(); } } + + private async Task FillOrganizationsAsync() + { + var result = await _organizationAppService.GetMyOrganizationsAsync(); + Organizations = result.Items.Select( + organization => new SelectListItem + { + Value = organization.Id.ToString(), + Text = organization.DisplayName + } + ).ToList(); + + if (Event.OrganizationId != Guid.Empty) + { + Organizations.Single(x => x.Value == Event.OrganizationId.ToString()).Selected = true; + } + } private async Task FillCountriesAsync() { @@ -88,6 +113,11 @@ namespace EventHub.Web.Pages.Events Text = country.Name } ).ToList(); + + if (Event.CountryId.HasValue) + { + Countries.Single(x => x.Value == Event.CountryId.ToString()).Selected = true; + } } private void FillLanguages() @@ -105,78 +135,67 @@ namespace EventHub.Web.Pages.Events 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; + if (!string.IsNullOrWhiteSpace(Event.Language)) + { + Languages.Single(x => x.Value == Event.Language).Selected = true; + } } - + public class EditEventViewModel { [HiddenInput] public Guid Id { get; set; } + [SelectItems(nameof(Organizations))] + [DisplayName("Organization")] + public Guid OrganizationId { get; set; } + [Required] [StringLength(EventConsts.MaxTitleLength, MinimumLength = EventConsts.MinTitleLength)] public string Title { get; set; } + [Required] + [DataType(DataType.DateTime)] + public DateTime StartTime { get; set; } = DateTime.Now; + + [Required] + [DataType(DataType.DateTime)] + public DateTime EndTime { get; set; } = DateTime.Now; + [Required] [StringLength(EventConsts.MaxDescriptionLength, MinimumLength = EventConsts.MinDescriptionLength)] [TextArea] public string Description { get; set; } + + [CanBeNull] + [Display(Name = "Cover Image")] + [DataType(DataType.Upload)] + [MaxFileSize(EventConsts.MaxCoverImageFileSize)] + [AllowedExtensions(new string[] { ".jpg", ".png", ".jpeg" })] + public IFormFile CoverImageFile { get; set; } + [Required] 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; } } - - public class EditEventTimingViewModel - { - [HiddenInput] - public Guid Id { get; set; } - - public DateTime StartTime { get; set; } - - public DateTime EndTime { get; set; } - } - } - - public class EventCoverImageInput - { - [Required] - public Guid EventId { get; set; } - - [Required] - [DataType(DataType.Upload)] - [MaxFileSize(EventConsts.MaxCoverImageFileSize)] - [AllowedExtensions(new string[] { ".jpg", ".png", ".jpeg" })] - public IFormFile CoverImageFile { get; set; } } } \ No newline at end of file diff --git a/src/EventHub.Web/Pages/Events/Edit.js b/src/EventHub.Web/Pages/Events/Edit.js index 2aa93bb..6432df7 100644 --- a/src/EventHub.Web/Pages/Events/Edit.js +++ b/src/EventHub.Web/Pages/Events/Edit.js @@ -1,178 +1,90 @@ $(function () { var l = abp.localization.getResource('EventHub'); - $("#Event_CountryId").prepend(""); - $("#Event_Language").prepend(""); - - if($("#Event_IsOnline").is(":checked")) { - $("#event-link-group").show(); - $("#event-location-group").hide(); + var isOnline = $("#Event_IsOnline option:selected").val() + if (isOnline === "True") { + $(".event-link-group").show(); + $(".event-location-group").hide(); + } else { + $(".event-link-group").hide(); + $(".event-location-group").show(); } - $('#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(); + $('#Event_IsOnline').on('change', '', function () { + var isOnline = $("#Event_IsOnline option:selected").val() + if (isOnline === "True") { + $(".event-link-group").show(); + $(".event-location-group").hide(); + } else { + $(".event-link-group").hide(); + $(".event-location-group").show(); } }); - - $("#btn-event-timing").click(function () { - $("#event-timing-preview-modal").modal("show"); - }); - - $("#event-timing-confirm").click(function () { - $("#Event_Timing_Form").submit(); - $("#event-timing-preview-modal").modal("hide"); - }) - - $("#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(l("EventTimingChangeSuccessMessage")) - .then(data => window.location.href = "/events/" + $("#event-detail-url").val()); - }, - error: function (data) { - abp.message.error(data.responseJSON.error.message); - } - }); - }) - // Cover Image Section - $('#event-cover-image-btnSubmit').prop( "disabled", true ); - var fileInput = document.getElementById('event-cover-image-input'); + var infoArea = document.getElementById('upload-label'); + var fileInput = document.getElementById('Event_CoverImageFile'); var file; - fileInput.addEventListener('change', function () { - var showModal = true; + if (fileInput !== null) { + fileInput.addEventListener('change', function () { + var showFile = true; - file = fileInput.files[0]; + file = fileInput.files[0]; - if (file === undefined){ - $('#event-cover-image-input').val(''); - $("#choose-cover-image").html(l("ChooseEventCoverImage")); - $('#event-cover-image-btnSubmit').prop( "disabled", true ); - return; - }else{ - document.getElementById("choose-cover-image").innerHTML = file.name; - } - - var permittedExtensions = ["jpg", "jpeg", "png"] - var fileExtension = $(this).val().split('.').pop(); - if (permittedExtensions.indexOf(fileExtension) === -1) { - showModal = false; - abp.message.error(l('EventCoverImageExtensionNotAllowed')) - .then(() => { - $('#event-cover-image-file').val(''); - $("#choose-cover-image").html(l("ChooseEventCoverImage")); - file = null; - }); - } - else if(file.size > 1024*1024) { - showModal = false; - abp.message.error(l('EventCoverImageSizeExceedMessage')) - .then(() => { - $('#event-cover-image-file').val(''); - $("#choose-cover-image").html(l("ChooseEventCoverImage")); - file = null; - }); - } - - var img = new Image(); - img.onload = function() { - var imageError = true; - var sizes = { - width: this.width, - height: this.height - }; - URL.revokeObjectURL(this.src); - - if(showModal && imageError) { - readURL(file); - $('#cover-image-preview-modal').modal('show'); + if (file === undefined) { + $('#Event_CoverImageFile').val(''); + $('#imageResult').attr('src', '#'); + infoArea.textContent = 'Choose file' + return; } - } - - var objectURL = URL.createObjectURL(file); - img.src = objectURL; - if (file.size > 0 && file.size < 1024*1024){ - $('#event-cover-image-btnSubmit').prop( "disabled", false); - } - }); - - function readURL(input) { - if (input) { - var reader = new FileReader(); - reader.onload = function (e) { - $('#img-upload').attr('src', e.target.result); + var permittedExtensions = ["jpg", "jpeg", "png"] + var fileExtension = $(this).val().split('.').pop(); + if (permittedExtensions.indexOf(fileExtension) === -1) { + showFile = false; + abp.message.error(l('EventCoverImageExtensionNotAllowed')) + .then(() => { + $('#Event_CoverImageFile').val(''); + file = null; + }); + } else if (file.size > 1024 * 1024) { + showFile = false; + abp.message.error(l('EventCoverImageSizeExceedMessage')) + .then(() => { + $('#Event_CoverImageFile').val(''); + file = null; + }); } - reader.readAsDataURL(input); - } - } - - $('form#cover-image-form').submit(function (e) { - e.preventDefault(); - - var eventId = document.getElementById("event-id").value; + var img = new Image(); + img.onload = function () { + var imageError = true; + var sizes = { + width: this.width, + height: this.height + }; + URL.revokeObjectURL(this.src); + + if (showFile && imageError) { + readURL(file); + } + } - if(!$(this).valid()) { - return false; - } + var objectURL = URL.createObjectURL(file); + img.src = objectURL; + }); - var formData = new FormData(); - formData.append("EventId", eventId); - formData.append("CoverImageFile", file); + function readURL(input) { + if (input) { + var reader = new FileReader(); - $.ajax({ - xhr: function() { - var xhr = new window.XMLHttpRequest(); - xhr.upload.addEventListener("progress", function(evt) { - if (evt.lengthComputable) { - var percentComplete = evt.loaded / evt.total; - percentComplete = parseInt(percentComplete * 100); - if(percentComplete !== 100){ - fileInput.prop( "disabled", true ); - $('#event-cover-image-btnSubmit').prop( "disabled", true ); - } - } - }, false); + reader.onload = function (e) { + $('#imageResult').attr('src', e.target.result); + infoArea.textContent = 'File name: ' + input.name; + } - return xhr; - }, - url: abp.appPath + `api/event/save-cover-image`, - data: formData, - type: 'POST', - contentType: false, - processData: false, - success: function(data){ - abp.message - .success(l('EventCoverImageEditSuccessMessage')) - .then(data => window.location.href = "/events/" + $("#event-detail-url").val()); - }, - error: function (data) { - abp.message.error(data.responseJSON.error.message); + reader.readAsDataURL(input); } - }); - }); + } + } }); \ No newline at end of file diff --git a/src/EventHub.Web/Pages/Events/New.cshtml.cs b/src/EventHub.Web/Pages/Events/New.cshtml.cs index b45b3d8..59ac1ff 100644 --- a/src/EventHub.Web/Pages/Events/New.cshtml.cs +++ b/src/EventHub.Web/Pages/Events/New.cshtml.cs @@ -20,8 +20,7 @@ namespace EventHub.Web.Pages.Events { public class NewPageModel : EventHubPageModel { - [BindProperty] - public NewEventViewModel Event { get; set; } + [BindProperty] public NewEventViewModel Event { get; set; } public List Organizations { get; private set; } public List Countries { get; private set; } @@ -50,7 +49,7 @@ namespace EventHub.Web.Pages.Events await FillCountriesAsync(); FillLanguages(); } - + public async Task OnPostAsync() { try @@ -81,7 +80,7 @@ namespace EventHub.Web.Pages.Events return Page(); } } - + private async Task FillOrganizationsAsync() { var result = await _organizationAppService.GetMyOrganizationsAsync(); @@ -93,11 +92,11 @@ namespace EventHub.Web.Pages.Events } ).ToList(); } - + private async Task FillCountriesAsync() { var result = await _eventAppService.GetCountriesLookupAsync(); - + Countries = result.Select( country => new SelectListItem { @@ -146,35 +145,33 @@ namespace EventHub.Web.Pages.Events [StringLength(EventConsts.MaxDescriptionLength, MinimumLength = EventConsts.MinDescriptionLength)] [TextArea] public string Description { get; set; } - + [CanBeNull] [Display(Name = "Cover Image")] [DataType(DataType.Upload)] - [MaxFileSize(EventConsts.MaxCoverImageFileSize)] - [AllowedExtensions(new string[] { ".jpg", ".png", ".jpeg" })] + [MaxFileSize(EventConsts.MaxCoverImageFileSize)] + [AllowedExtensions(new string[] {".jpg", ".png", ".jpeg"})] public IFormFile CoverImageFile { get; set; } - [Required] - public bool? IsOnline { get; set; } - + [Required] 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; } - [SelectItems(nameof(Languages))] - [DisplayName("Language")] - public string Language { get; set; } - [CanBeNull] [StringLength(EventConsts.MaxCityLength, MinimumLength = EventConsts.MinCityLength)] public string City { get; set; } - [Range(1, int.MaxValue)] - public int? Capacity { get; set; } + [SelectItems(nameof(Languages))] + [DisplayName("Language")] + public string Language { get; set; } + + [Range(1, int.MaxValue)] public int? Capacity { get; set; } } } -} +} \ No newline at end of file diff --git a/src/EventHub.Web/Pages/Organizations/Edit.cshtml b/src/EventHub.Web/Pages/Organizations/Edit.cshtml index 307f0e3..cded6fd 100644 --- a/src/EventHub.Web/Pages/Organizations/Edit.cshtml +++ b/src/EventHub.Web/Pages/Organizations/Edit.cshtml @@ -26,7 +26,14 @@
- + @if (Model.ProfilePictureContent != null && Model.ProfilePictureContent.Length > 0) + { + + } + else + { + + }
diff --git a/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs b/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs index 8937ef7..221eddc 100644 --- a/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs +++ b/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs @@ -20,7 +20,8 @@ namespace EventHub.Web.Pages.Organizations [BindProperty] public EditOrganizationViewModel Organization { get; set; } - + public byte[] ProfilePictureContent { get; private set; } + private readonly IOrganizationAppService _organizationAppService; public EditPageModel(IOrganizationAppService organizationAppService) @@ -31,6 +32,7 @@ namespace EventHub.Web.Pages.Organizations public async Task OnGetAsync() { var organizationProfileDto = await _organizationAppService.GetProfileAsync(Name); + ProfilePictureContent = organizationProfileDto.ProfilePictureContent; Organization = ObjectMapper.Map(organizationProfileDto); }