Agfgiunta tab e metodi gestione file attach

This commit is contained in:
Samuele Locatelli
2021-12-21 11:43:27 +01:00
parent 8c1c8075c6
commit 7af20fb602
5 changed files with 138 additions and 8 deletions
+74 -4
View File
@@ -6,6 +6,7 @@ using Microsoft.Extensions.Configuration;
using NLog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
@@ -277,6 +278,74 @@ namespace LiMan.DB.Controllers
//Log.Info("Dispose di GWMSController");
}
/// <summary>
/// Elenco files attach da registrare
/// </summary>
/// <param name="idxTicket">Identificativo del ticket</param>
/// <param name="baseDir">Directory di salvataggio dei file</param>
/// <param name="fileUploaded">lista risultati della funzione di upload</param>
/// <returns></returns>
public bool FileAdd(int idxTicket, string baseDir, List<UploadResult> fileUploaded)
{
bool fatto = false;
if (fileUploaded == null || fileUploaded.Count == 0)
{
Log.Error("Errore FileAdd: fileUploaded è vuoto/nullo");
}
else
{
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
{
// verifico Ticket sia esistente
var currTicket = localDbCtx
.DbSetTicket
.Where(x => x.IdxTicket == idxTicket)
.FirstOrDefault();
if (currTicket != null)
{
var newFiles = fileUploaded
.Select(x => new FileAttachModel()
{
IdxTicket = idxTicket,
OriginalName = x.FileName,
StorageName = x.StoredFileName,
DtEvent = DateTime.Now,
FullStoragePath = Path.Combine(baseDir, x.StoredFileName)
}).ToList();
localDbCtx
.DbSetFileAttach
.AddRange(newFiles);
localDbCtx.SaveChanges();
fatto = true;
}
}
}
return fatto;
}
/// <summary>
/// Elenco file registrati dato ticket id
/// </summary>
/// <param name="idxTicket">Identificativo del ticket</param>
/// <returns></returns>
public List<FileAttachModel> FileGetFilt(int idxTicket)
{
List<FileAttachModel> dbResult = new List<FileAttachModel>();
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
{
// recupero locenza...
dbResult = localDbCtx
.DbSetFileAttach
.Where(x => x.IdxTicket == idxTicket)
.ToList();
}
return dbResult;
}
public List<ApplicativoDTO> GetApplicativiFilt(bool OnlyActive, string CodApp, string CodInst, bool hideData)
{
List<ApplicativoDTO> dbResult = new List<ApplicativoDTO>();
@@ -775,7 +844,8 @@ namespace LiMan.DB.Controllers
ContactPhone = currRequest.ContactPhone,
ReqBody = currRequest.ReqBody,
Status = Enum.StatoRichiesta.Richiesta,
Tipo = Enum.TipoLicenza.UserKey
Tipo = Enum.TipoLicenza.UserKey,
TType = currRequest.Tipo
};
localDbCtx
@@ -790,7 +860,7 @@ namespace LiMan.DB.Controllers
return fatto;
}
public List<TicketDTO> TicketGetFilt(bool onlyOpen, string CodApp, string CodInst, string MasterKey, int maxNum)
public List<TicketDTO> TicketGetFilt(bool onlyOpen, TipologiaTicket Tipo, string CodApp, string CodInst, string MasterKey, int maxNum)
{
List<TicketDTO> dbResult = new List<TicketDTO>();
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
@@ -805,7 +875,7 @@ namespace LiMan.DB.Controllers
{
dbResult = localDbCtx
.DbSetTicket
.Where(x => x.IdxLic == currLic.IdxLic)
.Where(x => x.IdxLic == currLic.IdxLic && (x.TType == Tipo || Tipo == TipologiaTicket.ND))
.OrderByDescending(x => x.DtReq)
.Take(maxNum)
.Select(x => new TicketDTO
@@ -823,7 +893,7 @@ namespace LiMan.DB.Controllers
SupplAnsw = x.SupplAnsw,
SupplEmail = x.SupplEmail,
SupplUserCode = x.SupplUserCode,
Tipo= x.Tipo
Tipo = x.Tipo
})
.ToList();
}
+53
View File
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using static LiMan.DB.Enum;
#nullable disable
namespace LiMan.DB.DBModels
{
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
//[Index(nameof(Installazione), nameof(Active), nameof(DiskStatus))]
[Table("FileAttach")]
public partial class FileAttachModel
{
#region Public Properties
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdxFileAttach { get; set; }
/// <summary>
/// Id del ticket cui è collegato
/// </summary>
public int IdxTicket { get; set; }
/// <summary>
/// DataOra evento
/// </summary>
public DateTime DtEvent { get; set; } = DateTime.Now;
/// <summary>
/// Codice univoco della sub licenza (opzionale)
/// </summary>
public string OriginalName { get; set; } = "";
/// <summary>
/// Nome con cui è salvato il file localmente
/// </summary>
public string StorageName { get; set; } = "";
/// <summary>
/// Path completo del file
/// </summary>
public string FullStoragePath { get; set; } = "";
[ForeignKey("IdxTicket")]
public virtual TicketModel TicketNav { get; set; }
#endregion Public Properties
}
}
+7 -3
View File
@@ -1,5 +1,5 @@
using System;
using System.Collections.Generic;
using Core;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using static LiMan.DB.Enum;
@@ -11,7 +11,6 @@ namespace LiMan.DB.DBModels
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
//[Index(nameof(Installazione), nameof(Active), nameof(DiskStatus))]
[Table("TicketLog")]
public partial class TicketModel
{
@@ -22,6 +21,11 @@ namespace LiMan.DB.DBModels
public DateTime DtReq { get; set; } = DateTime.Now;
/// <summary>
/// Tipologia di ticket
/// </summary>
public TipologiaTicket TType { get; set; } = TipologiaTicket.Licenze;
/// <summary>
/// Tipologia di licenza gestita
/// </summary>
+2
View File
@@ -51,6 +51,8 @@ namespace LiMan.DB
CheckSumKey
}
#endregion Public Enums
}
}
+2 -1
View File
@@ -49,6 +49,7 @@ namespace LiMan.DB
#region Public Properties
public virtual DbSet<ApplicativoModel> DbSetApp { get; set; }
public virtual DbSet<FileAttachModel> DbSetFileAttach { get; set; }
public virtual DbSet<InstallazioneModel> DbSetInst { get; set; }
public virtual DbSet<LicenzaModel> DbSetLicenze { get; set; }
public virtual DbSet<LogCallModel> DbSetLogCall { get; set; }
@@ -57,7 +58,7 @@ namespace LiMan.DB
public virtual DbSet<TicketModel> DbSetTicket { get; set; }
#endregion Public Properties
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);