From f7d8a96c438fd00385549200dd146d74b5046022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Mon, 29 Jun 2020 15:03:20 +0300 Subject: [PATCH] Blog module consts converted to static --- .../Blogging/Admin/Blogs/Create.cshtml.cs | 7 +++-- .../Pages/Blogging/Admin/Blogs/Edit.cshtml.cs | 7 +++-- .../Volo/Blogging/Files/BloggingWebConsts.cs | 5 +++- .../Volo/Blogging/Posts/CreatePostDto.cs | 9 +++--- .../Volo/Blogging/Blogs/BlogConsts.cs | 15 ++++++++-- .../Volo/Blogging/Comments/CommentConsts.cs | 5 +++- .../Volo/Blogging/Posts/PostConsts.cs | 30 +++++++++++++++---- .../Volo/Blogging/Tagging/TagConsts.cs | 10 +++++-- .../Pages/Blogs/Posts/Edit.cshtml.cs | 9 +++--- .../Pages/Blogs/Posts/New.cshtml.cs | 9 +++--- 10 files changed, 75 insertions(+), 31 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Create.cshtml.cs b/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Create.cshtml.cs index b2d89fbd55..6f4bae5e63 100644 --- a/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Create.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Create.cshtml.cs @@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Validation; using Volo.Blogging.Admin.Blogs; using Volo.Blogging.Blogs; @@ -44,14 +45,14 @@ namespace Volo.Blogging.Admin.Pages.Blogging.Admin.Blogs public class BlogCreateModalView { [Required] - [StringLength(BlogConsts.MaxNameLength)] + [DynamicStringLength(typeof(BlogConsts), nameof(BlogConsts.MaxNameLength))] public string Name { get; set; } [Required] - [StringLength(BlogConsts.MaxShortNameLength)] + [DynamicStringLength(typeof(BlogConsts), nameof(BlogConsts.MaxShortNameLength))] public string ShortName { get; set; } - [StringLength(BlogConsts.MaxDescriptionLength)] + [DynamicStringLength(typeof(BlogConsts), nameof(BlogConsts.MaxDescriptionLength))] public string Description { get; set; } } diff --git a/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Edit.cshtml.cs b/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Edit.cshtml.cs index 536810e015..8d0b2ba978 100644 --- a/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Edit.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Edit.cshtml.cs @@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Validation; using Volo.Blogging.Admin.Blogs; using Volo.Blogging.Blogs; @@ -58,14 +59,14 @@ namespace Volo.Blogging.Admin.Pages.Blogging.Admin.Blogs public Guid Id { get; set; } [Required] - [StringLength(BlogConsts.MaxNameLength)] + [DynamicStringLength(typeof(BlogConsts), nameof(BlogConsts.MaxNameLength))] public string Name { get; set; } [Required] - [StringLength(BlogConsts.MaxShortNameLength)] + [DynamicStringLength(typeof(BlogConsts), nameof(BlogConsts.MaxShortNameLength))] public string ShortName { get; set; } - [StringLength(BlogConsts.MaxDescriptionLength)] + [DynamicStringLength(typeof(BlogConsts), nameof(BlogConsts.MaxDescriptionLength))] public string Description { get; set; } } } diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Files/BloggingWebConsts.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Files/BloggingWebConsts.cs index ae4eb32dff..d9eb284ac6 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Files/BloggingWebConsts.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Files/BloggingWebConsts.cs @@ -6,7 +6,10 @@ namespace Volo.Blogging { public class FileUploading { - public const int MaxFileSize = 5242880; //5MB + /// + /// Default value: 5242880 + /// + public static int MaxFileSize { get; set; } = 5242880; //5MB public static int MaxFileSizeAsMegabytes => Convert.ToInt32((MaxFileSize / 1024f) / 1024f); } diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/CreatePostDto.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/CreatePostDto.cs index 164e4f691f..96cfbd6859 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/CreatePostDto.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/CreatePostDto.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; namespace Volo.Blogging.Posts { @@ -8,22 +9,22 @@ namespace Volo.Blogging.Posts public Guid BlogId { get; set; } [Required] - [StringLength(PostConsts.MaxTitleLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxTitleLength))] public string Title { get; set; } [Required] public string CoverImage { get; set; } [Required] - [StringLength(PostConsts.MaxUrlLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxUrlLength))] public string Url { get; set; } - [StringLength(PostConsts.MaxContentLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxContentLength))] public string Content { get; set; } public string Tags { get; set; } - [StringLength(PostConsts.MaxDescriptionLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxDescriptionLength))] public string Description { get; set; } } diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Blogs/BlogConsts.cs b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Blogs/BlogConsts.cs index 502a4364e7..b4b428207c 100644 --- a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Blogs/BlogConsts.cs +++ b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Blogs/BlogConsts.cs @@ -2,10 +2,19 @@ { public static class BlogConsts { - public const int MaxNameLength = 256; + /// + /// Default value: 256 + /// + public static int MaxNameLength { get; set; } = 256; - public const int MaxShortNameLength = 32; + /// + /// Default value: 32 + /// + public static int MaxShortNameLength { get; set; } = 32; - public const int MaxDescriptionLength = 1024; + /// + /// Default value: 1024 + /// + public static int MaxDescriptionLength { get; set; } = 1024; } } diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Comments/CommentConsts.cs b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Comments/CommentConsts.cs index 34cc655fb3..359b322cbf 100644 --- a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Comments/CommentConsts.cs +++ b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Comments/CommentConsts.cs @@ -2,6 +2,9 @@ { public class CommentConsts { - public const int MaxTextLength = 1024; + /// + /// Default value: 1024 + /// + public static int MaxTextLength { get; set; } = 1024; } } diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Posts/PostConsts.cs b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Posts/PostConsts.cs index 665984dfbb..de91caa2d3 100644 --- a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Posts/PostConsts.cs +++ b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Posts/PostConsts.cs @@ -2,16 +2,34 @@ { public static class PostConsts { - public const int MaxTitleLength = 512; + /// + /// Default value: 512 + /// + public static int MaxTitleLength { get; set; } = 512; - public const int MaxUrlLength = 64; + /// + /// Default value: 64 + /// + public static int MaxUrlLength { get; set; } = 64; - public const int MaxContentLength = 1024 * 1024; //1MB + /// + /// Default value: 1024 * 1024 + /// + public static int MaxContentLength { get; set; } = 1024 * 1024; //1MB - public const int MaxDescriptionLength = 1000; + /// + /// Default value: 1000 + /// + public static int MaxDescriptionLength { get; set; } = 1000; - public const int MaxTitleLengthToBeSeoFriendly = 60; + /// + /// Default value: 60 + /// + public static int MaxTitleLengthToBeSeoFriendly { get; set; } = 60; - public const int MaxSeoFriendlyDescriptionLength = 200; + /// + /// Default value: 200 + /// + public static int MaxSeoFriendlyDescriptionLength { get; set; } = 200; } } diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Tagging/TagConsts.cs b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Tagging/TagConsts.cs index c75ccd4184..ad2be87ca8 100644 --- a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Tagging/TagConsts.cs +++ b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Tagging/TagConsts.cs @@ -2,8 +2,14 @@ { public class TagConsts { - public const int MaxNameLength = 64; + /// + /// Default value: 64 + /// + public static int MaxNameLength { get; set; } = 64; - public const int MaxDescriptionLength = 512; + /// + /// Default value: 512 + /// + public static int MaxDescriptionLength { get; set; } = 512; } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs index c2ebcc441b..6d998a7172 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Edit.cshtml.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Abp.Validation; using Volo.Blogging.Blogs; using Volo.Blogging.Pages.Blogs.Shared.Helpers; using Volo.Blogging.Posts; @@ -85,7 +86,7 @@ namespace Volo.Blogging.Pages.Blog.Posts public Guid BlogId { get; set; } [Required] - [StringLength(PostConsts.MaxTitleLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxTitleLength))] public string Title { get; set; } [Required] @@ -93,14 +94,14 @@ namespace Volo.Blogging.Pages.Blog.Posts public string CoverImage { get; set; } [Required] - [StringLength(PostConsts.MaxUrlLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxUrlLength))] public string Url { get; set; } [HiddenInput] - [StringLength(PostConsts.MaxContentLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxContentLength))] public string Content { get; set; } - [StringLength(PostConsts.MaxDescriptionLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxDescriptionLength))] public string Description { get; set; } public string Tags { get; set; } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs index 41c8f43ddd..3930a79900 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/New.cshtml.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Abp.Validation; using Volo.Blogging.Blogs; using Volo.Blogging.Blogs.Dtos; using Volo.Blogging.Pages.Blogs.Shared.Helpers; @@ -79,7 +80,7 @@ namespace Volo.Blogging.Pages.Blog.Posts public Guid BlogId { get; set; } [Required] - [StringLength(PostConsts.MaxTitleLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxTitleLength))] public string Title { get; set; } [Required] @@ -87,16 +88,16 @@ namespace Volo.Blogging.Pages.Blog.Posts public string CoverImage { get; set; } [Required] - [StringLength(PostConsts.MaxUrlLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxUrlLength))] public string Url { get; set; } [HiddenInput] - [StringLength(PostConsts.MaxContentLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxContentLength))] public string Content { get; set; } public string Tags { get; set; } - [StringLength(PostConsts.MaxDescriptionLength)] + [DynamicStringLength(typeof(PostConsts), nameof(PostConsts.MaxDescriptionLength))] public string Description { get; set; } }