#12 profile narration validation improvement
This commit is contained in:
parent
7ec0f91da5
commit
3d2ac2c484
@ -4473,6 +4473,13 @@
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.GetUserProfileValidationError(RMuseum.Models.GanjoorAudio.UserNarrationProfile)">
|
||||
<summary>
|
||||
validating narration profile
|
||||
</summary>
|
||||
<param name="p"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.AddUserNarrationProfiles(RMuseum.Models.GanjoorAudio.ViewModels.UserNarrationProfileViewModel)">
|
||||
<summary>
|
||||
Add a narration profile
|
||||
@ -4593,9 +4600,9 @@
|
||||
English Alphabet
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.LanguageUtils.ContainsOnlySpecificCharacters(System.String,System.String,System.String)">
|
||||
<member name="M:RMuseum.Services.Implementation.LanguageUtils.GetFirstNotMatchingCharacter(System.String,System.String,System.String)">
|
||||
<summary>
|
||||
Contains Only Specific Characters
|
||||
Check to see if input Contains Only Specific Characters
|
||||
</summary>
|
||||
<param name="input"></param>
|
||||
<param name="specfics"></param>
|
||||
|
||||
@ -681,6 +681,58 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// validating narration profile
|
||||
/// </summary>
|
||||
/// <param name="p"></param>
|
||||
/// <returns></returns>
|
||||
private static string GetUserProfileValidationError(UserNarrationProfile p)
|
||||
{
|
||||
if (p.ArtistName.Length < 3)
|
||||
{
|
||||
return "نام خوانشگر باید حداقل شامل سه نویسه باشد.";
|
||||
}
|
||||
|
||||
if (p.FileSuffixWithoutDash.Length < 2)
|
||||
{
|
||||
return "طول پسوند قابل پذیرش حداقل دو کاراکتر است.";
|
||||
}
|
||||
|
||||
if (p.FileSuffixWithoutDash.Length > 4)
|
||||
{
|
||||
return "طول پسوند قابل پذیرش حداکثر چهار کاراکتر است.";
|
||||
}
|
||||
|
||||
string s = LanguageUtils.GetFirstNotMatchingCharacter(p.ArtistName, LanguageUtils.PersianAlphabet, " ");
|
||||
if (s != "")
|
||||
{
|
||||
return $"نام فقط باید شامل حروف فارسی و فاصله باشد. اولین حرف غیرمجاز = {s}";
|
||||
}
|
||||
|
||||
s = LanguageUtils.GetFirstNotMatchingCharacter(p.ArtistUrl, LanguageUtils.EnglishLowerCaseAlphabet, LanguageUtils.EnglishLowerCaseAlphabet.ToUpper() + @":/.");
|
||||
|
||||
if (s != "")
|
||||
{
|
||||
return $"نشانی وب خوانشگر شامل حروف غیر مجاز است. اولین حرف غیرمجاز = {s}";
|
||||
}
|
||||
|
||||
s = LanguageUtils.GetFirstNotMatchingCharacter(p.AudioSrcUrl, LanguageUtils.EnglishLowerCaseAlphabet, LanguageUtils.EnglishLowerCaseAlphabet.ToUpper() + @":/.");
|
||||
if (s != "")
|
||||
{
|
||||
return $"نشانی وب منبع شامل حروف غیر مجاز است. اولین حرف غیرمجاز = {s}";
|
||||
}
|
||||
|
||||
s = LanguageUtils.GetFirstNotMatchingCharacter(p.FileSuffixWithoutDash, LanguageUtils.EnglishLowerCaseAlphabet);
|
||||
|
||||
if (s != "")
|
||||
{
|
||||
return $"پسوند فقط میتواند از حروف کوچک انگلیسی تشکیل شود. اولین حرف غیر مجاز = {s}";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Add a narration profile
|
||||
/// </summary>
|
||||
@ -701,43 +753,12 @@ namespace RMuseum.Services.Implementation
|
||||
IsDefault = profile.IsDefault
|
||||
};
|
||||
|
||||
if(p.ArtistName.Length < 3)
|
||||
string error = GetUserProfileValidationError(p);
|
||||
if(error != "")
|
||||
{
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(null, "نام خوانشگر باید حداقل شامل سه نویسه باشد.");
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(null, error);
|
||||
}
|
||||
|
||||
if (p.FileSuffixWithoutDash.Length < 2)
|
||||
{
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(null, "طول پسوند قابل پذیرش حداقل دو کاراکتر است.");
|
||||
}
|
||||
|
||||
if (p.FileSuffixWithoutDash.Length > 4)
|
||||
{
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(null, "طول پسوند قابل پذیرش حداکثر چهار کاراکتر است.");
|
||||
}
|
||||
|
||||
if (!LanguageUtils.ContainsOnlySpecificCharacters(p.ArtistName, LanguageUtils.PersianAlphabet, " "))
|
||||
{
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(null, "نام فقط باید شامل حروف فارسی و فاصله باشد.");
|
||||
}
|
||||
|
||||
if (
|
||||
!LanguageUtils.ContainsOnlySpecificCharacters(p.ArtistUrl, LanguageUtils.EnglishLowerCaseAlphabet, LanguageUtils.EnglishLowerCaseAlphabet.ToUpper() + @":/.")
|
||||
||
|
||||
!LanguageUtils.ContainsOnlySpecificCharacters(p.AudioSrcUrl, LanguageUtils.EnglishLowerCaseAlphabet, LanguageUtils.EnglishLowerCaseAlphabet.ToUpper() + @":/.")
|
||||
|
||||
)
|
||||
{
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(null, "نشانیهای وب نادرستند.");
|
||||
}
|
||||
|
||||
if (!LanguageUtils.ContainsOnlySpecificCharacters(p.FileSuffixWithoutDash, LanguageUtils.EnglishLowerCaseAlphabet))
|
||||
{
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(null, "پسوند فقط میتواند از حروف کوچک انگلیسی تشکیل شود.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
await _context.UserNarrationProfiles.AddAsync(p);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
@ -16,19 +16,19 @@
|
||||
public const string EnglishLowerCaseAlphabet = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
/// <summary>
|
||||
/// Contains Only Specific Characters
|
||||
/// Check to see if input Contains Only Specific Characters
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="specfics"></param>
|
||||
/// <param name="additional"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ContainsOnlySpecificCharacters(string input, string specfics, string additional= "")
|
||||
public static string GetFirstNotMatchingCharacter(string input, string specfics, string additional= "")
|
||||
{
|
||||
string all = specfics + additional;
|
||||
foreach (char c in input)
|
||||
if (all.IndexOf(c) == -1)
|
||||
return false;
|
||||
return true;
|
||||
return (c + "");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user