From b4550b2bc016df4397ceb63ded0833052c62c560 Mon Sep 17 00:00:00 2001 From: EngincanV Date: Wed, 3 Feb 2021 14:29:19 +0300 Subject: [PATCH] Edit organization profile --- .../Organizations/IOrganizationAppService.cs | 7 +- .../Organizations/UpdateOrganizationDto.cs | 27 ++++++ .../Organizations/OrganizationAppService.cs | 28 ++++++ .../Localization/EventHub/en.json | 6 +- .../EventHubWebAutoMapperProfile.cs | 7 +- .../Pages/Organizations/Edit.cshtml | 10 +++ .../Pages/Organizations/Edit.cshtml.cs | 90 +++++++++++++++++++ .../Pages/Organizations/Profile.cshtml | 75 +++++++++++++++- .../Pages/Organizations/Profile.cshtml.cs | 4 + 9 files changed, 249 insertions(+), 5 deletions(-) create mode 100644 src/EventHub.Application.Contracts/Organizations/UpdateOrganizationDto.cs create mode 100644 src/EventHub.Web/Pages/Organizations/Edit.cshtml create mode 100644 src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs diff --git a/src/EventHub.Application.Contracts/Organizations/IOrganizationAppService.cs b/src/EventHub.Application.Contracts/Organizations/IOrganizationAppService.cs index b31555a..650edcb 100644 --- a/src/EventHub.Application.Contracts/Organizations/IOrganizationAppService.cs +++ b/src/EventHub.Application.Contracts/Organizations/IOrganizationAppService.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; @@ -13,5 +14,9 @@ namespace EventHub.Organizations Task GetProfileAsync(string name); Task> GetMyOrganizationsAsync(); + + Task IsOrganizationOwnerAsync(Guid organizationId); + + Task UpdateAsync(Guid id, UpdateOrganizationDto input); } } diff --git a/src/EventHub.Application.Contracts/Organizations/UpdateOrganizationDto.cs b/src/EventHub.Application.Contracts/Organizations/UpdateOrganizationDto.cs new file mode 100644 index 0000000..32516a0 --- /dev/null +++ b/src/EventHub.Application.Contracts/Organizations/UpdateOrganizationDto.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations; + +namespace EventHub.Organizations +{ + public class UpdateOrganizationDto + { + [Required] + [StringLength(OrganizationConsts.MaxDisplayNameLength, MinimumLength = OrganizationConsts.MinDisplayNameLength)] + public string DisplayName { get; set; } + + [Required] + [StringLength(OrganizationConsts.MaxDescriptionNameLength, MinimumLength = OrganizationConsts.MinDescriptionNameLength)] + public string Description { get; set; } + + public string Website { get; set; } + + public string TwitterUsername { get; set; } + + public string GitHubUsername { get; set; } + + public string FacebookUsername { get; set; } + + public string InstagramUsername { get; set; } + + public string MediumUsername { get; set; } + } +} \ No newline at end of file diff --git a/src/EventHub.Application/Organizations/OrganizationAppService.cs b/src/EventHub.Application/Organizations/OrganizationAppService.cs index 2536cb4..5ca0472 100644 --- a/src/EventHub.Application/Organizations/OrganizationAppService.cs +++ b/src/EventHub.Application/Organizations/OrganizationAppService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using EventHub.Permissions; using Microsoft.AspNetCore.Authorization; using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Repositories; @@ -67,5 +68,32 @@ namespace EventHub.Organizations ObjectMapper.Map, List>(organizations) ); } + + public async Task IsOrganizationOwnerAsync(Guid organizationId) + { + return CurrentUser.Id.HasValue && await _organizationRepository.AnyAsync(x => x.Id == organizationId && x.OwnerUserId == CurrentUser.Id.Value); + } + + [Authorize] + public async Task UpdateAsync(Guid id, UpdateOrganizationDto input) + { + var organization = await _organizationRepository.GetAsync(id); + + if (organization.OwnerUserId != CurrentUser.GetId()) + { + return; + } + + organization.SetDisplayName(input.DisplayName); + organization.SetDescription(input.Description); + organization.Website = input.Website; + organization.TwitterUsername = input.TwitterUsername; + organization.GitHubUsername = input.GitHubUsername; + organization.InstagramUsername = input.InstagramUsername; + organization.FacebookUsername = input.FacebookUsername; + organization.MediumUsername = input.MediumUsername; + + await _organizationRepository.UpdateAsync(organization); + } } } diff --git a/src/EventHub.Domain.Shared/Localization/EventHub/en.json b/src/EventHub.Domain.Shared/Localization/EventHub/en.json index 18fb75d..4477cf9 100644 --- a/src/EventHub.Domain.Shared/Localization/EventHub/en.json +++ b/src/EventHub.Domain.Shared/Localization/EventHub/en.json @@ -42,6 +42,10 @@ "OrganizationJoinSuccessMessage": "See you at the events.", "OrganizationMembershipLeaveMessage": "You left your organization membership.", "LeaveOrganization": "Leave this organization", - "JoinOrganization": "Join the organization" + "JoinOrganization": "Join the organization", + "Edit": "Edit", + "EditOrganization": "Edit Organization", + "PersonalWebsite": "Personal Website", + "SocialMedia": "Social Media" } } diff --git a/src/EventHub.Web/EventHubWebAutoMapperProfile.cs b/src/EventHub.Web/EventHubWebAutoMapperProfile.cs index a82e04f..d0e9a0b 100644 --- a/src/EventHub.Web/EventHubWebAutoMapperProfile.cs +++ b/src/EventHub.Web/EventHubWebAutoMapperProfile.cs @@ -1,6 +1,7 @@ using AutoMapper; using EventHub.Events; using EventHub.Organizations; +using EventHub.Web.Pages.Organizations; namespace EventHub.Web { @@ -8,8 +9,10 @@ namespace EventHub.Web { public EventHubWebAutoMapperProfile() { - CreateMap(); - CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); } } } diff --git a/src/EventHub.Web/Pages/Organizations/Edit.cshtml b/src/EventHub.Web/Pages/Organizations/Edit.cshtml new file mode 100644 index 0000000..5eb4651 --- /dev/null +++ b/src/EventHub.Web/Pages/Organizations/Edit.cshtml @@ -0,0 +1,10 @@ +@page "/organization/edit/{name}" +@inject IHtmlLocalizer L +@using EventHub.Localization +@using Microsoft.AspNetCore.Mvc.Localization +@model EventHub.Web.Pages.Organizations.EditPageModel + +
+

@L["EditOrganization"]

+ +
\ No newline at end of file diff --git a/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs b/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs new file mode 100644 index 0000000..79a210e --- /dev/null +++ b/src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs @@ -0,0 +1,90 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; +using EventHub.Organizations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace EventHub.Web.Pages.Organizations +{ + [Authorize] + public class EditPageModel : EventHubPageModel + { + [BindProperty(SupportsGet = true)] + public string Name { get; set; } + + [BindProperty] + public EditOrganizationViewModel Organization { get; set; } + + private readonly IOrganizationAppService _organizationAppService; + + public EditPageModel(IOrganizationAppService organizationAppService) + { + _organizationAppService = organizationAppService; + } + + public async Task OnGetAsync() + { + try + { + await GetOrganizationAsync(); + } + catch (Exception exception) + { + ShowAlert(exception); + return RedirectToPage("./Index"); + } + + return Page(); + } + + public async Task OnPostAsync() + { + try + { + ValidateModel(); + + var input = ObjectMapper.Map(Organization); + await _organizationAppService.UpdateAsync(Organization.Id, input); + + return RedirectToPage("./Profile", new { name = Name }); + } + catch (Exception exception) + { + return Page(); + } + } + + private async Task GetOrganizationAsync() + { + var organizationProfileDto = await _organizationAppService.GetProfileAsync(Name); + Organization = ObjectMapper.Map(organizationProfileDto); + } + } + + public class EditOrganizationViewModel + { + [HiddenInput] + public Guid Id { 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; } + + public string Website { get; set; } + + public string TwitterUsername { get; set; } + + public string GitHubUsername { get; set; } + + public string FacebookUsername { get; set; } + + public string InstagramUsername { get; set; } + + public string MediumUsername { get; set; } + } +} \ No newline at end of file diff --git a/src/EventHub.Web/Pages/Organizations/Profile.cshtml b/src/EventHub.Web/Pages/Organizations/Profile.cshtml index 817437e..fbe2ab9 100644 --- a/src/EventHub.Web/Pages/Organizations/Profile.cshtml +++ b/src/EventHub.Web/Pages/Organizations/Profile.cshtml @@ -15,10 +15,83 @@ @Model.Organization.DisplayName -

@Model.Organization.DisplayName

+ @if (Model.IsOrganizationOwner) + { +
+
+

@Model.Organization.DisplayName

+
+ +
+ } + else + { +

@Model.Organization.DisplayName

+ }
@Model.Organization.Description + + @if (!Model.Organization.Website.IsNullOrEmpty() || !Model.Organization.TwitterUsername.IsNullOrEmpty() || + !Model.Organization.GitHubUsername.IsNullOrEmpty() || !Model.Organization.InstagramUsername.IsNullOrEmpty() || + !Model.Organization.GitHubUsername.IsNullOrEmpty() || !Model.Organization.MediumUsername.IsNullOrEmpty()) + { +
+ @if (Model.Organization.Website != null) + { +
+ @L["PersonalWebsite"] +
+ @if (Model.Organization.Website != null) + { + + @Model.Organization.Website + + } +
+
+ } + @if (Model.Organization.TwitterUsername != null || Model.Organization.GitHubUsername != null || + Model.Organization.InstagramUsername != null || Model.Organization.GitHubUsername != null || + Model.Organization.MediumUsername != null) + { +
+ @L["SocialMedia"]
+ @if (Model.Organization.TwitterUsername != null) + { + + + + } + @if (Model.Organization.GitHubUsername != null) + { + + + + } + @if (Model.Organization.InstagramUsername != null) + { + + + + } + @if (Model.Organization.FacebookUsername != null) + { + + + + } + @if (Model.Organization.MediumUsername != null) + { + + + + } +
+ } + }
diff --git a/src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs b/src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs index 73572dc..d7578a3 100644 --- a/src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs +++ b/src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs @@ -18,6 +18,8 @@ namespace EventHub.Web.Pages.Organizations public IReadOnlyList PastEvents { get; private set; } public long PastEventTotalCount { get; private set; } + public bool IsOrganizationOwner { get; private set; } + private readonly IEventAppService _eventAppService; private readonly IOrganizationAppService _organizationAppService; @@ -34,6 +36,8 @@ namespace EventHub.Web.Pages.Organizations await GetProfileAsync(); await GetUpcomingEventsAsync(); await GetPastEventsAsync(); + + IsOrganizationOwner = await _organizationAppService.IsOrganizationOwnerAsync(Organization.Id); } private async Task GetProfileAsync()