瀏覽代碼

refactoring&nugets update

ganahrhr 3 年之前
父節點
當前提交
cc53ada03c
共有 3 個文件被更改,包括 62 次插入61 次删除
  1. 6 6
      HyperCube.csproj
  2. 15 24
      Pages/DocEdit.razor
  3. 41 31
      Pages/DocEdit.razor.cs

+ 6 - 6
HyperCube.csproj

@@ -9,15 +9,15 @@
   <ItemGroup>
     <PackageReference Include="BitMiracle.Docotic.Pdf" Version="8.2.12561" />
     <PackageReference Include="MailKit" Version="2.15.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.10" />
-    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.10" />
-    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.10" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.10">
+    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.11" />
+    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.11" />
+    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.11" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.11">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
-    <PackageReference Include="MySql.EntityFrameworkCore" Version="5.0.5" />
-    <PackageReference Include="MySql.Data" Version="8.0.26" />
+    <PackageReference Include="MySql.EntityFrameworkCore" Version="5.0.8" />
+    <PackageReference Include="MySql.Data" Version="8.0.27" />
     <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
   </ItemGroup>
 

+ 15 - 24
Pages/DocEdit.razor

@@ -1,17 +1,9 @@
 @page "/docedit"
 @page "/docedit/{docID:int}"
 
-@inject NavigationManager NavigationManager
-@inject IJSRuntime JsRuntime
-
-@using Microsoft.AspNetCore.Identity;
-@inject AuthenticationStateProvider AuthenticationStateProvider
-@inject UserManager<IdentityUser> UserManager
-
 @attribute [Authorize]
 @*@attribute [Authorize(Roles = "admin")]*@
 
-
 <div class="tabs__content">
     <div class="tabs__controls">
         <a class="tabs__btn tabs__btn_active">Загрузка материалов</a>        
@@ -19,38 +11,37 @@
         <a class="tabs__btn">Библиотеки</a>
         <a class="tabs__btn">Заказы</a>
     </div>
-    <EditForm Model="@articleModel">
+    <EditForm Model="@article">
 
         <div class="upload">
             <h2 class="upload__title">Загрузка материала</h2>
             <form class="upload__form">
-                @if (docID < 1)
+                @if (DocID < 1)
                 {
-                    <InputFile class="upload__btn" id="inputDefault" OnChange="@HandleSelection" accept="application/pdf" />
-                    //accept="application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document"
+                    <InputFile class="upload__btn" id="inputDefault" OnChange="@HandleSelection" accept="application/pdf" />                    
                 }
                 else
                 {
-                    <p>Исходный документ: <a href=@fullName download target="_top">@articleModel.Filename</a></p>                    
+                    <p>Исходный документ: <a href=@fullName download target="_top">@article.Filename</a></p>                    
                 }
-                <InputText type="text" class="form-control upload__input" id="article_name" @bind-Value="articleModel.Name" placeholder="Наименование статьи" />
-                <InputDate type="date" class="form-control upload__input" id="date_publish" @bind-Value="articleModel.PublishDate" placeholder="Дата издания" />
+                <InputText type="text" class="form-control upload__input" id="article_name" @bind-Value="article.Name" placeholder="Наименование статьи" />
+                <InputDate type="date" class="form-control upload__input" id="date_publish" @bind-Value="article.PublishDate" placeholder="Дата издания" />
                 <label class="upload__label">
-                    <InputText type="text" class="form-control upload__input" id="author" @bind-Value="articleModel.Authors" placeholder="Автор" />
+                    <InputText type="text" class="form-control upload__input" id="author" @bind-Value="article.Authors" placeholder="Автор" />
                     <div class="upload__input-descr">+ Добавить автора, указывать имена авторов через запятую</div>
                 </label>
-                <InputText type="text" class="form-control upload__input" id="keywords" @bind-Value="articleModel.Keywords" placeholder="Ключевые слова" />
-                <InputTextArea class="form-control upload__textarea" id="annotation" @bind-Value="articleModel.Annotation" placeholder="Аннотация" />
-                <InputTextArea class="form-control upload__textarea" id="text" @bind-Value="articleModel.Text" placeholder="Текст статьи" /> @*rows="10"*@
+                <InputText type="text" class="form-control upload__input" id="keywords" @bind-Value="article.Keywords" placeholder="Ключевые слова" />
+                <InputTextArea class="form-control upload__textarea" id="annotation" @bind-Value="article.Annotation" placeholder="Аннотация" />
+                <InputTextArea class="form-control upload__textarea" id="text" @bind-Value="article.Text" placeholder="Текст статьи" />
 
-                @if (docID < 1)
-                {                    
+                @if (DocID < 1)
+                {
                     <button type="button" class="upload__btn" @onclick="@HandleValidSubmit" disabled=@IsSubmitDisabled>загрузить на верификацию</button>
                 }
                 else
                 {
                     <p>
-                        <InputRadioGroup @bind-Value="articleModel.Rating">
+                        <InputRadioGroup @bind-Value="article.Rating">
                             Оценка:
                             <br>
                             @for (int i = 1; i < 6; i++)
@@ -79,8 +70,8 @@
                         ID транзакции: @transactionId
                     </p>
                     <p>
-                        Инициатор: <mark>@initiatorAcc.Name</mark> Сумма: @(articleModel.Rating*5) <b>WEI</b><br>
-                        Рейтинг статьи: @articleModel.Rating<br>
+                        Инициатор: <mark>@initiatorAcc.Name</mark> Сумма: @(article.Rating*5) <b>WEI</b><br>
+                        Рейтинг статьи: @article.Rating<br>
                     </p>
                     <p>
                         Верификатор: <mark>@currentAcc.Name</mark> Сумма: @editsCount <b>WEI</b><br>

+ 41 - 31
Pages/DocEdit.razor.cs

@@ -1,6 +1,7 @@
 using Microsoft.AspNetCore.Components;
 using Microsoft.AspNetCore.Components.Authorization;
 using Microsoft.AspNetCore.Components.Forms;
+using Microsoft.AspNetCore.Identity;
 using Microsoft.JSInterop;
 using System;
 using System.Collections.Generic;
@@ -17,14 +18,23 @@ namespace HyperCube.Pages
     public partial class DocEdit : ComponentBase
     {
         [Parameter]
-        public int docID { get; set; }
+        public int DocID { get; set; }
+
+        [Inject]
+        public NavigationManager NavigationManager { get; set; }
+        [Inject]
+        public IJSRuntime JsRuntime { get; set; }
+        [Inject]
+        public AuthenticationStateProvider AuthenticationStateProvider { get; set; }
+        [Inject]
+        public UserManager<IdentityUser> UserManager { get; set; }
 
         const string FOLDER_NAME = "articles_storage";
         const long MAX_FILE_SIZE = 5120000; //bytes
 
         string transactionId;
-        ArticleModel articleModelClone = new();
-        ArticleModel articleModel = new();
+        ArticleModel articleClone = new();
+        ArticleModel article = new();
         AccountModel currentAcc = new();
         AccountModel initiatorAcc = new();
         string status;
@@ -32,7 +42,7 @@ namespace HyperCube.Pages
         string storageFolderPath;
         MemoryStream memoryStream;
         Modal modal { get; set; }
-        string fullName { get { return FOLDER_NAME + "/" + articleModel.FilenameReal; } }
+        string fullName { get { return FOLDER_NAME + "/" + article.FilenameReal; } }
         int editsCount;
 
         bool IsSubmitDisabled = false;
@@ -46,7 +56,7 @@ namespace HyperCube.Pages
                 if (verifyContract != null)
                 {
                     Console.WriteLine($"VerifyContract found");
-                    transactionId = await verifyContract.Run(articleModel);
+                    transactionId = await verifyContract.Run(article);
                     return transactionId;
                 }
                 else
@@ -67,7 +77,7 @@ namespace HyperCube.Pages
             string path = AppDomain.CurrentDomain.BaseDirectory+@"wwwroot";
             storageFolderPath = (Path.Combine(path, FOLDER_NAME));
             Console.WriteLine("docedit OnInitializedAsync storageFolderPath2 " + storageFolderPath);
-            if (docID > 0)
+            if (DocID > 0)
             {
                 header = "Проверка материала";
 
@@ -76,14 +86,14 @@ namespace HyperCube.Pages
                 string stringSQL = $"SELECT articles.id, filename, article_name, authors, date_publish, annotation, keywords, action_type, rating " +
                     $"FROM articles " +
                     $"JOIN actions_history ON actions_history.article_id = articles.id " +
-                    $"WHERE articles.id={docID} " +
+                    $"WHERE articles.id={DocID} " +
                     $"ORDER BY actions_history.id DESC LiMIT 1";
-                articleModelClone = await dbCon.SQLSelectArticle(stringSQL);
-                articleModel = (ArticleModel)articleModelClone.Clone();
+                articleClone = await dbCon.SQLSelectArticle(stringSQL);
+                article = (ArticleModel)articleClone.Clone();
 
-                string initiator = await articleModel.GetInitiatorUUID();
+                string initiator = await article.GetInitiatorUUID();
                 initiatorAcc = AccountModel.Find(initiator);
-                status = $"Article ID={docID} loaded, status: {articleModel.Status}, initiator: {initiatorAcc.Name}";
+                status = $"Article ID={DocID} loaded, status: {article.Status}, initiator: {initiatorAcc.Name}";
             }
             else
                 header = "Загрузка материала";
@@ -113,65 +123,65 @@ namespace HyperCube.Pages
             long id;
             string stringSQL;
 
-            Console.WriteLine($"HandleValidSubmit, docID: {docID}");
+            Console.WriteLine($"HandleValidSubmit, docID: {DocID}");
 
-            if (docID > 0)
+            if (DocID > 0)
             {
-                id = docID;
+                id = DocID;
                 stringSQL = $"UPDATE articles " +
-                    $"SET filename='{articleModel.Filename}', article_name='{articleModel.Name}', authors='{articleModel.Authors}', " +
-                        $"date_publish='{articleModel.PublishDate:yyyy-MM-dd}', annotation='{articleModel.Annotation}', " +
-                        $"keywords='{articleModel.Keywords}', rating={articleModel.Rating}, file_hash={articleModel.FileHashSum} " +
-                    $"WHERE id={docID}";
+                    $"SET filename='{article.Filename}', article_name='{article.Name}', authors='{article.Authors}', " +
+                        $"date_publish='{article.PublishDate:yyyy-MM-dd}', annotation='{article.Annotation}', " +
+                        $"keywords='{article.Keywords}', rating={article.Rating}, file_hash='{article.FileHashSum}' " +
+                    $"WHERE id={DocID}";
                 await dbCon.SQLInsert(stringSQL);
             }
             else
             {
                 stringSQL = $"INSERT INTO articles (filename, article_name, authors, date_publish, annotation, keywords, file_hash) " +
-                    $"VALUES ('{articleModel.Filename}', '{articleModel.Name}', '{articleModel.Authors}', '{articleModel.PublishDate:yyyy-MM-dd}'," +
-                        $"'{articleModel.Annotation}', '{articleModel.Keywords}', '{articleModel.FileHashSum}')";
+                    $"VALUES ('{article.Filename}', '{article.Name}', '{article.Authors}', '{article.PublishDate:yyyy-MM-dd}'," +
+                        $"'{article.Annotation}', '{article.Keywords}', '{article.FileHashSum}')";
                 id = await dbCon.SQLInsert(stringSQL);
                 NewProjectSmopp(id);
             }          
 
             /// tmp
-            int action_type = docID > 0 ? 2 : 1;
+            int action_type = DocID > 0 ? 2 : 1;
 
             stringSQL = $"INSERT INTO actions_history (article_id, action_type, acc_id) " +
                 $"VALUES ('{id}', '{action_type}', '{currentAcc.UUID}')";
             await dbCon.SQLInsert(stringSQL);
 
-            Dictionary<string, PropertyInfo> propDict = Compare.SimpleCompare<ArticleModel>(articleModel, articleModelClone);
+            Dictionary<string, PropertyInfo> propDict = Compare.SimpleCompare<ArticleModel>(article, articleClone);
             foreach (KeyValuePair<string, PropertyInfo> prop in propDict)
             {
                 //Console.WriteLine($"property name: {prop.Key}, value: {prop.Value.GetValue(articleModel, null)}");
 
                 stringSQL = $"INSERT INTO articles_edit_log (article_id, acc_id, field_name, field_prevvalue, field_newvalue) " +
-                    $"VALUES ('{id}', '{currentAcc.UUID}', '{prop.Key}', '{prop.Value.GetValue(articleModelClone, null)}', '{prop.Value.GetValue(articleModel, null)}')";
+                    $"VALUES ('{id}', '{currentAcc.UUID}', '{prop.Key}', '{prop.Value.GetValue(articleClone, null)}', '{prop.Value.GetValue(article, null)}')";
                 await dbCon.SQLInsert(stringSQL);
             }
 
             //dbCon.Close();
 
-            if (docID > 0)
+            if (DocID > 0)
             {
                 status = propDict.Count > 0 ? "All changes saved, article has veryfied." : "Article verifyed without any changes.";
                 transactionId = await Verify();
                 Console.WriteLine("transactionId found " + transactionId);
 
                 ///tmp
-                editsCount = await articleModel.GetEditsCount(currentAcc.UUID);
+                editsCount = await article.GetEditsCount(currentAcc.UUID);
                 modal.Open();
             }
             else
             {
-                string fullpath = Path.Combine(storageFolderPath, $"{id}_{articleModel.Filename}");
+                string fullpath = Path.Combine(storageFolderPath, $"{id}_{article.Filename}");
                 Directory.CreateDirectory(storageFolderPath);
                 FileStream fs = new(fullpath, FileMode.Create, FileAccess.Write);
                 memoryStream.Position = 0;
                 await memoryStream.CopyToAsync(fs);
 
-                Console.WriteLine($"User has saved new article data, {id}_{articleModel.Filename}, memory size:{memoryStream.Length}b, file size: {fs.Length}b");
+                Console.WriteLine($"User has saved new article data, {id}_{article.Filename}, memory size:{memoryStream.Length}b, file size: {fs.Length}b");
                 memoryStream.Close();
                 fs.Close();
 
@@ -212,10 +222,10 @@ namespace HyperCube.Pages
 
                 if (count < 1)
                 {
-                    articleModelClone = DocParse.ReadPDF(memoryStream);
-                    articleModelClone.Filename = file.Name;
-                    articleModelClone.FileHashSum = hash;
-                    articleModel = (ArticleModel)articleModelClone.Clone();
+                    articleClone = DocParse.ReadPDF(memoryStream);
+                    articleClone.Filename = file.Name;
+                    articleClone.FileHashSum = hash;
+                    article = (ArticleModel)articleClone.Clone();
 
                     IsSubmitDisabled = false;
                 }