|
@@ -5,9 +5,11 @@ using Microsoft.AspNetCore.Identity;
|
|
|
using Microsoft.JSInterop;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.ComponentModel.DataAnnotations;
|
|
|
using System.IO;
|
|
|
using System.Reflection;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Linq;
|
|
|
using System.Net;
|
|
|
using System.Security.Cryptography;
|
|
|
using HyperCube.Models;
|
|
@@ -41,7 +43,9 @@ namespace HyperCube.Pages
|
|
|
string header;
|
|
|
string storageFolderPath;
|
|
|
MemoryStream memoryStream;
|
|
|
- Modal modal { get; set; }
|
|
|
+ ModalInfo modalInfo_error { get; set; }
|
|
|
+ ModalInfo modalInfo_transac { get; set; }
|
|
|
+ ModalLoading modalLoading { get; set; }
|
|
|
string fullName { get { return FOLDER_NAME + "/" + article.FilenameReal; } }
|
|
|
int editsCount;
|
|
|
|
|
@@ -117,13 +121,27 @@ namespace HyperCube.Pages
|
|
|
return reader.ReadToEnd();
|
|
|
}
|
|
|
|
|
|
- private async Task HandleValidSubmit()
|
|
|
+ private async Task HandleSubmit()
|
|
|
{
|
|
|
+ Console.WriteLine($"HandleSubmit, docID: {DocID}.");
|
|
|
+
|
|
|
+ modalLoading.Open();
|
|
|
+
|
|
|
+ /// form validation
|
|
|
+ List<string> errorFields = ValidateForm<ArticleModel>(article);
|
|
|
+ if (errorFields.Count > 0)
|
|
|
+ {
|
|
|
+ modalLoading.Close();
|
|
|
+ string invalid_fields = string.Join(", ", errorFields);
|
|
|
+ modalInfo_error.Open($"Не заполнены поля: {invalid_fields}");
|
|
|
+ Console.WriteLine($"HandleSubmit. Required fields: '{invalid_fields}' is not filled.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// all is fine, continue
|
|
|
MySQLConnector dbCon = MySQLConnector.Instance();
|
|
|
long id;
|
|
|
- string stringSQL;
|
|
|
-
|
|
|
- Console.WriteLine($"HandleValidSubmit, docID: {DocID}");
|
|
|
+ string stringSQL;
|
|
|
|
|
|
if (DocID > 0)
|
|
|
{
|
|
@@ -171,7 +189,7 @@ namespace HyperCube.Pages
|
|
|
|
|
|
///tmp
|
|
|
editsCount = await article.GetEditsCount(currentAcc.UUID);
|
|
|
- modal.Open();
|
|
|
+ modalInfo_transac.Open();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -200,6 +218,8 @@ namespace HyperCube.Pages
|
|
|
|
|
|
private async Task HandleSelection(InputFileChangeEventArgs e)
|
|
|
{
|
|
|
+ modalLoading.Open();
|
|
|
+
|
|
|
IBrowserFile file = e.File;
|
|
|
if (file != null)
|
|
|
{
|
|
@@ -235,8 +255,13 @@ namespace HyperCube.Pages
|
|
|
Console.WriteLine(status);
|
|
|
|
|
|
IsSubmitDisabled = true;
|
|
|
+ memoryStream.Close();
|
|
|
+ stream.Close();
|
|
|
+ modalInfo_error.Open("Загрузка не удалась, такой документ уже есть в системе.");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ modalLoading.Close();
|
|
|
}
|
|
|
|
|
|
private async Task Cancel()
|
|
@@ -288,5 +313,20 @@ namespace HyperCube.Pages
|
|
|
byte[] hash = await md5Provider.ComputeHashAsync(ms);
|
|
|
return Convert.ToBase64String(hash);
|
|
|
}
|
|
|
+
|
|
|
+ private List<string> ValidateForm<T>(T obj)
|
|
|
+ {
|
|
|
+ var props = typeof(T).GetProperties().Where(pi => Attribute.IsDefined(pi, typeof(RequiredAttribute)));
|
|
|
+ List<string> result = new();
|
|
|
+ foreach (var prop in props)
|
|
|
+ {
|
|
|
+ var val = prop.GetValue(obj, null);
|
|
|
+ if (val == null || val?.ToString().Length == 0)
|
|
|
+ result.Add(prop.Name);
|
|
|
+
|
|
|
+ //Console.WriteLine($"Required field '{prop.Name}' is not filled.");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
}
|