diff --git a/RMuseum/Models/GanjoorAudio/ViewModels/UserNarrationProfileViewModel.cs b/RMuseum/Models/GanjoorAudio/ViewModels/UserNarrationProfileViewModel.cs
index cf2cb256..bfbd27db 100644
--- a/RMuseum/Models/GanjoorAudio/ViewModels/UserNarrationProfileViewModel.cs
+++ b/RMuseum/Models/GanjoorAudio/ViewModels/UserNarrationProfileViewModel.cs
@@ -8,6 +8,13 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels
///
public class UserNarrationProfileViewModel
{
+ ///
+ /// parameterless constructor
+ ///
+ public UserNarrationProfileViewModel()
+ {
+
+ }
///
/// constructor
///
@@ -28,16 +35,25 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels
///
/// Id
///
+ ///
+ /// Do not fill it in POST api
+ ///
public Guid Id { get; set; }
///
/// User
///
+ ///
+ /// Do not fill it in POST api
+ ///
public PublicRAppUser User { get; set; }
///
/// UserId
///
+ ///
+ /// Do not fill it in POST api
+ ///
public Guid UserId { get; set; }
///
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index 002f1734..41bf1be1 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -2139,6 +2139,11 @@
UserNarrationProfile View Model
+
+
+ parameterless constructor
+
+
constructor
@@ -2149,16 +2154,25 @@
Id
+
+ Do not fill it in POST api
+
User
+
+ Do not fill it in POST api
+
UserId
+
+ Do not fill it in POST api
+
@@ -4564,6 +4578,30 @@
equaivalnet for persian characters
+
+
+ Language Utilitis
+
+
+
+
+ Persian Alphabet
+
+
+
+
+ English Alphabet
+
+
+
+
+ Contains Only Specific Characters
+
+
+
+
+
+
manipulating picture files
diff --git a/RMuseum/Services/Implementation/AudioNarrationService.cs b/RMuseum/Services/Implementation/AudioNarrationService.cs
index 6db2bda4..e940bba7 100644
--- a/RMuseum/Services/Implementation/AudioNarrationService.cs
+++ b/RMuseum/Services/Implementation/AudioNarrationService.cs
@@ -693,13 +693,51 @@ namespace RMuseum.Services.Implementation
var p = new UserNarrationProfile()
{
UserId = profile.UserId,
- ArtistName = profile.ArtistName,
- ArtistUrl = profile.ArtistUrl,
- AudioSrc = profile.AudioSrc,
- AudioSrcUrl = profile.AudioSrcUrl,
- FileSuffixWithoutDash = profile.FileSuffixWithoutDash,
+ ArtistName = profile.ArtistName.Trim(),
+ ArtistUrl = profile.ArtistUrl.Trim(),
+ AudioSrc = profile.AudioSrc.Trim(),
+ AudioSrcUrl = profile.AudioSrcUrl.Trim(),
+ FileSuffixWithoutDash = profile.FileSuffixWithoutDash.Trim(),
IsDefault = profile.IsDefault
};
+
+ if(p.ArtistName.Length < 3)
+ {
+ return new RServiceResult(null, "نام خوانشگر باید حداقل شامل سه نویسه باشد.");
+ }
+
+ if (p.FileSuffixWithoutDash.Length < 2)
+ {
+ return new RServiceResult(null, "طول پسوند قابل پذیرش حداقل دو کاراکتر است.");
+ }
+
+ if (p.FileSuffixWithoutDash.Length > 4)
+ {
+ return new RServiceResult(null, "طول پسوند قابل پذیرش حداکثر چهار کاراکتر است.");
+ }
+
+ if (!LanguageUtils.ContainsOnlySpecificCharacters(p.ArtistName, LanguageUtils.PersianAlphabet, " "))
+ {
+ return new RServiceResult(null, "نام فقط باید شامل حروف فارسی و فاصله باشد.");
+ }
+
+ if (
+ !LanguageUtils.ContainsOnlySpecificCharacters(p.ArtistUrl, LanguageUtils.EnglishLowerCaseAlphabet, LanguageUtils.EnglishLowerCaseAlphabet.ToUpper() + @":/.")
+ ||
+ !LanguageUtils.ContainsOnlySpecificCharacters(p.AudioSrcUrl, LanguageUtils.EnglishLowerCaseAlphabet, LanguageUtils.EnglishLowerCaseAlphabet.ToUpper() + @":/.")
+
+ )
+ {
+ return new RServiceResult(null, "نشانیهای وب نادرستند.");
+ }
+
+ if (!LanguageUtils.ContainsOnlySpecificCharacters(p.FileSuffixWithoutDash, LanguageUtils.EnglishLowerCaseAlphabet))
+ {
+ return new RServiceResult(null, "پسوند فقط میتواند از حروف کوچک انگلیسی تشکیل شود.");
+ }
+
+
+
await _context.UserNarrationProfiles.AddAsync(p);
await _context.SaveChangesAsync();
diff --git a/RMuseum/Services/Implementation/LanguageUtils.cs b/RMuseum/Services/Implementation/LanguageUtils.cs
new file mode 100644
index 00000000..00426192
--- /dev/null
+++ b/RMuseum/Services/Implementation/LanguageUtils.cs
@@ -0,0 +1,34 @@
+namespace RMuseum.Services.Implementation
+{
+ ///
+ /// Language Utilitis
+ ///
+ public static class LanguageUtils
+ {
+ ///
+ /// Persian Alphabet
+ ///
+ public const string PersianAlphabet = "آابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیئؤ";
+
+ ///
+ /// English Alphabet
+ ///
+ public const string EnglishLowerCaseAlphabet = "abcdefghijklmnopqrstuvwxyz";
+
+ ///
+ /// Contains Only Specific Characters
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool ContainsOnlySpecificCharacters(string input, string specfics, string additional= "")
+ {
+ string all = specfics + additional;
+ foreach (char c in input)
+ if (all.IndexOf(c) == -1)
+ return false;
+ return true;
+ }
+ }
+}