Browse Source

Edit organization profile

pull/17/head
EngincanV 6 years ago
parent
commit
b4550b2bc0
  1. 7
      src/EventHub.Application.Contracts/Organizations/IOrganizationAppService.cs
  2. 27
      src/EventHub.Application.Contracts/Organizations/UpdateOrganizationDto.cs
  3. 28
      src/EventHub.Application/Organizations/OrganizationAppService.cs
  4. 6
      src/EventHub.Domain.Shared/Localization/EventHub/en.json
  5. 7
      src/EventHub.Web/EventHubWebAutoMapperProfile.cs
  6. 10
      src/EventHub.Web/Pages/Organizations/Edit.cshtml
  7. 90
      src/EventHub.Web/Pages/Organizations/Edit.cshtml.cs
  8. 75
      src/EventHub.Web/Pages/Organizations/Profile.cshtml
  9. 4
      src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs

7
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.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
@ -13,5 +14,9 @@ namespace EventHub.Organizations
Task<OrganizationProfileDto> GetProfileAsync(string name); Task<OrganizationProfileDto> GetProfileAsync(string name);
Task<ListResultDto<OrganizationInListDto>> GetMyOrganizationsAsync(); Task<ListResultDto<OrganizationInListDto>> GetMyOrganizationsAsync();
Task<bool> IsOrganizationOwnerAsync(Guid organizationId);
Task UpdateAsync(Guid id, UpdateOrganizationDto input);
} }
} }

27
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; }
}
}

28
src/EventHub.Application/Organizations/OrganizationAppService.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using EventHub.Permissions;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -67,5 +68,32 @@ namespace EventHub.Organizations
ObjectMapper.Map<List<Organization>, List<OrganizationInListDto>>(organizations) ObjectMapper.Map<List<Organization>, List<OrganizationInListDto>>(organizations)
); );
} }
public async Task<bool> 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);
}
} }
} }

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

@ -42,6 +42,10 @@
"OrganizationJoinSuccessMessage": "See you at the events.", "OrganizationJoinSuccessMessage": "See you at the events.",
"OrganizationMembershipLeaveMessage": "You left your organization membership.", "OrganizationMembershipLeaveMessage": "You left your organization membership.",
"LeaveOrganization": "Leave this organization", "LeaveOrganization": "Leave this organization",
"JoinOrganization": "Join the organization" "JoinOrganization": "Join the organization",
"Edit": "Edit",
"EditOrganization": "Edit Organization",
"PersonalWebsite": "Personal Website",
"SocialMedia": "Social Media"
} }
} }

7
src/EventHub.Web/EventHubWebAutoMapperProfile.cs

@ -1,6 +1,7 @@
using AutoMapper; using AutoMapper;
using EventHub.Events; using EventHub.Events;
using EventHub.Organizations; using EventHub.Organizations;
using EventHub.Web.Pages.Organizations;
namespace EventHub.Web namespace EventHub.Web
{ {
@ -8,8 +9,10 @@ namespace EventHub.Web
{ {
public EventHubWebAutoMapperProfile() public EventHubWebAutoMapperProfile()
{ {
CreateMap<EventHub.Web.Pages.Organizations.NewPageModel.CreateOrganizationViewModel, CreateOrganizationDto>(); CreateMap<NewPageModel.CreateOrganizationViewModel, CreateOrganizationDto>();
CreateMap<EventHub.Web.Pages.Events.NewPageModel.NewEventViewModel, CreateEventDto>(); CreateMap<Pages.Events.NewPageModel.NewEventViewModel, CreateEventDto>();
CreateMap<OrganizationProfileDto, EditOrganizationViewModel>();
CreateMap<EditOrganizationViewModel, UpdateOrganizationDto>();
} }
} }
} }

10
src/EventHub.Web/Pages/Organizations/Edit.cshtml

@ -0,0 +1,10 @@
@page "/organization/edit/{name}"
@inject IHtmlLocalizer<EventHubResource> L
@using EventHub.Localization
@using Microsoft.AspNetCore.Mvc.Localization
@model EventHub.Web.Pages.Organizations.EditPageModel
<div class="container mb-4">
<h1>@L["EditOrganization"]</h1>
<abp-dynamic-form abp-model="Organization" submit-button="true"/>
</div>

90
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<IActionResult> OnGetAsync()
{
try
{
await GetOrganizationAsync();
}
catch (Exception exception)
{
ShowAlert(exception);
return RedirectToPage("./Index");
}
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
try
{
ValidateModel();
var input = ObjectMapper.Map<EditOrganizationViewModel, UpdateOrganizationDto>(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, EditOrganizationViewModel>(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; }
}
}

75
src/EventHub.Web/Pages/Organizations/Profile.cshtml

@ -15,10 +15,83 @@
<img abp-card-image="Top" src="https://picsum.photos/seed/@Model.Name/1920/400?blur=8" alt="@Model.Organization.DisplayName"/> <img abp-card-image="Top" src="https://picsum.photos/seed/@Model.Name/1920/400?blur=8" alt="@Model.Organization.DisplayName"/>
<abp-card-body> <abp-card-body>
<abp-card-title> <abp-card-title>
<h2>@Model.Organization.DisplayName</h2> @if (Model.IsOrganizationOwner)
{
<div class="row">
<div class="col-9">
<h2>@Model.Organization.DisplayName</h2>
</div>
<div class="col-3 text-right">
<a href="/organization/edit/@Model.Organization.Name" class="btn btn-primary text-white">@L["Edit"] <i class="far fa-edit"></i></a>
</div>
</div>
}
else
{
<h2>@Model.Organization.DisplayName</h2>
}
</abp-card-title> </abp-card-title>
<abp-card-text class="mt-3"> <abp-card-text class="mt-3">
@Model.Organization.Description @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())
{
<hr/>
@if (Model.Organization.Website != null)
{
<div class="mt-4 text-center">
<small class="text-muted text-uppercase">@L["PersonalWebsite"]</small>
<h5 class="m-0">
@if (Model.Organization.Website != null)
{
<a href="@Model.Organization.Website" class="text-personel-web-site text-decoration-none" target="_blank" style="font-size: 1rem">
@Model.Organization.Website
</a>
}
</h5>
</div>
}
@if (Model.Organization.TwitterUsername != null || Model.Organization.GitHubUsername != null ||
Model.Organization.InstagramUsername != null || Model.Organization.GitHubUsername != null ||
Model.Organization.MediumUsername != null)
{
<div class="profile-icons mt-4 text-center">
<small class="text-muted text-uppercase">@L["SocialMedia"]</small><br/>
@if (Model.Organization.TwitterUsername != null)
{
<a href="https://twitter.com/@Model.Organization.TwitterUsername" class="text-twitter text-decoration-none" target="_blank" style="font-size: 1.5rem">
<i class="fab fa-twitter"></i>
</a>
}
@if (Model.Organization.GitHubUsername != null)
{
<a href="https://github.com/@Model.Organization.GitHubUsername" class="text-github text-decoration-none" target="_blank" style="font-size: 1.5rem">
<i class="fab fa-github"></i>
</a>
}
@if (Model.Organization.InstagramUsername != null)
{
<a href="https://www.instagram.com/@Model.Organization.InstagramUsername" class="text-instagram text-decoration-none" target="_blank" style="font-size: 1.5rem">
<i class="fab fa-instagram"></i>
</a>
}
@if (Model.Organization.FacebookUsername != null)
{
<a href="https://www.facebook.com/@Model.Organization.FacebookUsername" class="text-facebook text-decoration-none" target="_blank" style="font-size: 1.5rem">
<i class="fab fa-facebook"></i>
</a>
}
@if (Model.Organization.MediumUsername != null)
{
<a href="https://medium.com/@Html.Raw("@")@Model.Organization.MediumUsername" class="text-medium text-decoration-none" target="_blank" style="font-size: 1.5rem">
<i class="fab fa-medium"></i>
</a>
}
</div>
}
}
</abp-card-text> </abp-card-text>
</abp-card-body> </abp-card-body>
</abp-card> </abp-card>

4
src/EventHub.Web/Pages/Organizations/Profile.cshtml.cs

@ -18,6 +18,8 @@ namespace EventHub.Web.Pages.Organizations
public IReadOnlyList<EventInListDto> PastEvents { get; private set; } public IReadOnlyList<EventInListDto> PastEvents { get; private set; }
public long PastEventTotalCount { get; private set; } public long PastEventTotalCount { get; private set; }
public bool IsOrganizationOwner { get; private set; }
private readonly IEventAppService _eventAppService; private readonly IEventAppService _eventAppService;
private readonly IOrganizationAppService _organizationAppService; private readonly IOrganizationAppService _organizationAppService;
@ -34,6 +36,8 @@ namespace EventHub.Web.Pages.Organizations
await GetProfileAsync(); await GetProfileAsync();
await GetUpcomingEventsAsync(); await GetUpcomingEventsAsync();
await GetPastEventsAsync(); await GetPastEventsAsync();
IsOrganizationOwner = await _organizationAppService.IsOrganizationOwnerAsync(Organization.Id);
} }
private async Task GetProfileAsync() private async Task GetProfileAsync()

Loading…
Cancel
Save