refactor code

pull/16313/head
Onur Pıçakcı 2 years ago
parent 20ec1b371a
commit e74a057553

@ -0,0 +1,5 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bundling
@addTagHelper *, Volo.Blogging.Web

@ -6,5 +6,5 @@ namespace Volo.Blogging.Members;
public interface IMemberAppService : IApplicationService
{
Task<BlogUserDto> FindAsync(string username);
Task<BlogUserDto> GetAsync(string username);
}

@ -14,10 +14,10 @@ public class MemberAppService : BloggingAppServiceBase, IMemberAppService
{
_userRepository = userRepository;
}
public async Task<BlogUserDto> FindAsync(string username)
public async Task<BlogUserDto> GetAsync(string username)
{
var user = await _userRepository.FindAsync(x => x.UserName == username);
var user = await _userRepository.GetAsync(x => x.UserName == username);
return ObjectMapper.Map<BlogUser, BlogUserDto>(user);
}

@ -1,48 +0,0 @@
using System;
using System.Linq;
namespace Volo.Blogging.Helpers;
public static class PostCoverImageHelper
{
private static readonly string[] PostColors =
{
"linear-gradient(135deg, #4b2d21 0%, #7d4b37 100%)",
"linear-gradient(135deg, #41003d 0%, #a10097 100%)",
"linear-gradient(135deg, #163e4b 0%, #297791 100%)",
"linear-gradient(135deg, #660040 0%, #aa006b 100%)",
"linear-gradient(135deg, #240d88 0%, #571fff 100%)",
"linear-gradient(135deg, #0d6a88 0%, #16b0e1 100%)",
"linear-gradient(135deg, #329063 0%, #4be099 100%)",
"linear-gradient(135deg, #904432 0%, #f07153 100%)",
"linear-gradient(135deg, #903282 0%, #e04cca 100%)",
"linear-gradient(135deg, #901943 0%, #f02a70 100%)",
"linear-gradient(135deg, #2e634a 0%, #4da57b 100%)",
"linear-gradient(135deg, #9c003f 0%, #e41d6f 100%)",
"linear-gradient(135deg, #806419 0%, #d5a72a 100%)",
"linear-gradient(135deg, #545975 0%, #8890bd 100%)",
"linear-gradient(135deg, #67172a 0%, #ba2549 100%)"
};
public static string GetRandomColor(string postTitle)
{
long total = postTitle.Truncate(32).ToCharArray().Sum(c => c);
return PostColors[total % PostColors.Length];
}
public static string GetTitleCapitals(string postTitle)
{
if (postTitle.Length < 2)
{
return postTitle.ToUpperInvariant();
}
if (postTitle.Contains(" "))
{
var splitted = postTitle.Split(" ");
return (splitted[0][0].ToString() + splitted[1][0].ToString()).ToUpperInvariant();
}
return postTitle.ToUpperInvariant().Left(2);
}
}

@ -1,5 +1,6 @@
@page
@using Microsoft.AspNetCore.Authorization
@using Volo.Blogging.Areas.Blog.Helpers.TagHelpers
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.OwlCarousel
@using Volo.Blogging
@inject IAuthorizationService Authorization

@ -2,7 +2,6 @@
@using Microsoft.Extensions.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
@using Volo.Abp.Users
@using Volo.Blogging.Helpers
@using Volo.Blogging.Localization
@model Volo.Blogging.Pages.Members.IndexModel
@inject IStringLocalizer<BloggingResource> L
@ -15,15 +14,14 @@
<abp-style src="/Pages/Members/Index.css"/>
}
<main class="pt-4" id="MemberDetail">
<main>
<div class="container">
<div class="row gx-lg-5">
<div class="col-md-4 mb-5 mb-md-0">
<div class="card h-auto member-profile-info">
<div class="card-body">
<div class="d-inline-block position-relative">
<img src="https://localhost:44333/api/account/profile-picture-file/@Model.User.Id" class="post-member-img rounded-circle d-block">
<img gravatar-email="@Model.User.Email" default-image="Identicon" class="post-member-img rounded-circle d-block"/>
</div>
@if (Model.User.UserName != null)
{
@ -36,7 +34,7 @@
</div>
<div class="col-md-8">
<abp-tabs>
<abp-tab name="all-posts" title="All Blogs">
<abp-tab name="all-posts" title="All Blog Posts">
<div class="mt-4 pt-3">
@foreach (var post in Model.Posts)
{
@ -44,7 +42,7 @@
<div class="post-type-cont">
<a href="/members/@Model.User.UserName" class="text-decoration-none">
<img src="https://localhost:44333/api/account/profile-picture-file/@Model.User.Id" class="post-member-img rounded-circle d-block">
<img gravatar-email="@Model.User.Email" default-image="Identicon" class="post-member-img rounded-circle d-block"/>
</a>
<span class="post-type">
<i class="fas fa-pen-nib"></i>
@ -65,16 +63,16 @@
</a>
</h3>
<p class="post-desc">
<a href="/">
<a href="/..">
@(post.Description.Length >= 150 ? post.Description.Substring(0, 150) + "..." : post.Description)
</a>
<a href="/" class="readMore">@L["ReadMore"]</a>
</p>
</div>
<div class="post-img-cont">
<div class="post-list-span text-center post" style="background: @(PostCoverImageHelper.GetRandomColor(post.Title))">
<span>@PostCoverImageHelper.GetTitleCapitals(post.Title)</span>
</div>
<div class="post-list-span text-center post">
<img src="@post.CoverImage" class="box-articles">
</div>
</div>
</div>
}

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Blogging.Blogs;
using Volo.Blogging.Blogs.Dtos;
using Volo.Blogging.Members;
using Volo.Blogging.Posts;
@ -13,9 +14,10 @@ public class IndexModel : AbpPageModel
private readonly IPostAppService _postAppService;
private readonly IMemberAppService _memberAppService;
public BlogUserDto User { get; set; }
public List<PostWithDetailsDto> Posts { get; set; }
public IndexModel(IPostAppService postAppService, IMemberAppService memberAppService)
{
_postAppService = postAppService;
@ -24,15 +26,15 @@ public class IndexModel : AbpPageModel
public async Task<IActionResult> OnGetAsync(string userName)
{
User = await _memberAppService.FindAsync(userName);
User = await _memberAppService.GetAsync(userName);
if (User is null)
{
return Redirect("/abp");
return Redirect("/");
}
Posts = await _postAppService.GetListByUserIdAsync(User.Id);
return Page();
}

Loading…
Cancel
Save