Inizio aggiunta controller editing file
This commit is contained in:
@@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MP.FileData.DatabaseModels;
|
||||
|
||||
namespace MP.FileData.Controllers
|
||||
{
|
||||
@@ -31,63 +32,6 @@ namespace MP.FileData.Controllers
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elenco Azioni (decodifica)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DatabaseModels.AzioniUL> ActionsGetAll()
|
||||
{
|
||||
List<DatabaseModels.AzioniUL> dbResult = new List<DatabaseModels.AzioniUL>();
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetAzioniUL
|
||||
.ToList();
|
||||
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli da filtro
|
||||
/// </summary>
|
||||
/// <param name="numRecord"></param>
|
||||
/// <param name="searchVal"></param>
|
||||
/// <returns></returns>
|
||||
public List<DatabaseModels.AnagArticoli> ArticoliGetSearch(int numRecord, string searchVal = "")
|
||||
{
|
||||
List<DatabaseModels.AnagArticoli> dbResult = new List<DatabaseModels.AnagArticoli>();
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal))
|
||||
.OrderBy(x => x.CodArticolo)
|
||||
.Take(numRecord)
|
||||
.ToList();
|
||||
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli da filtro
|
||||
/// </summary>
|
||||
/// <param name="numRecord"></param>
|
||||
/// <param name="searchVal"></param>
|
||||
/// <returns></returns>
|
||||
public List<DatabaseModels.ODL> CommesseGetSearch(int numRecord, string searchVal = "")
|
||||
{
|
||||
List<DatabaseModels.ODL> dbResult = new List<DatabaseModels.ODL>();
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetODL
|
||||
.Where(x => x.KeyRichiesta.Contains(searchVal) || string.IsNullOrEmpty(searchVal))
|
||||
.OrderBy(x => x.KeyRichiesta)
|
||||
.Take(numRecord)
|
||||
.ToList();
|
||||
|
||||
return dbResult;
|
||||
}
|
||||
#endif
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
@@ -181,6 +125,56 @@ namespace MP.FileData.Controllers
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ELiminazione file da tabella
|
||||
/// </summary>
|
||||
/// <param name="currItem"></param>
|
||||
/// <returns></returns>
|
||||
public bool FileDelete(FileModel currItem)
|
||||
{
|
||||
bool done = false;
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
// eliminazione di uno specifico file + rev da tabella
|
||||
var file2del = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.FileId == currItem.FileId)
|
||||
.FirstOrDefault();
|
||||
localDbCtx
|
||||
.DbSetProgFile
|
||||
.Remove(file2del);
|
||||
|
||||
// se ce ne fosse un altro precedente --> lo (ri)attiva
|
||||
var file2open = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.Articolo == currItem.Articolo && x.IdxMacchina == currItem.IdxMacchina)
|
||||
.OrderByDescending(y => y.Rev)
|
||||
.FirstOrDefault();
|
||||
if (file2open != null)
|
||||
{
|
||||
file2open.Active = true;
|
||||
}
|
||||
|
||||
// salvo!
|
||||
localDbCtx.SaveChanges();
|
||||
done = true;
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
public FileModel FileGetByKey(int FileId)
|
||||
{
|
||||
FileModel thisFile = null;
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
thisFile = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.FileId == FileId)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
return thisFile;
|
||||
}
|
||||
|
||||
public List<DatabaseModels.FileModel> FileGetByPath(string path, bool onlyActive)
|
||||
{
|
||||
List<DatabaseModels.FileModel> dbResult = new List<DatabaseModels.FileModel>();
|
||||
@@ -195,7 +189,7 @@ namespace MP.FileData.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public List<DatabaseModels.FileModel> FileGetFilt(string IdxMacchina, string CodArticolo, string SearchVal = "")
|
||||
public List<DatabaseModels.FileModel> FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyMod, string SearchVal = "")
|
||||
{
|
||||
List<DatabaseModels.FileModel> dbResult = new List<DatabaseModels.FileModel>();
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
@@ -204,7 +198,7 @@ namespace MP.FileData.Controllers
|
||||
.DbSetProgFile
|
||||
.Include(m => m.Macchina)
|
||||
.Include(a => a.Articolo)
|
||||
.Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") || (x.CodArticolo == CodArticolo || CodArticolo == "ND" || CodArticolo == "")) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)))
|
||||
.Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.CodArticolo == CodArticolo || CodArticolo == "ND" || CodArticolo.StartsWith("##") || string.IsNullOrEmpty(CodArticolo))) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)) && (!OnlyMod || x.Changed))
|
||||
.OrderBy(x => x.Name)
|
||||
.ToList();
|
||||
}
|
||||
@@ -252,6 +246,108 @@ namespace MP.FileData.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna un Ordine
|
||||
/// </summary>
|
||||
/// <param name="updItem"></param>
|
||||
/// <returns></returns>
|
||||
public bool FileUpdate(FileModel updItem)
|
||||
{
|
||||
bool done = false;
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
FileModel currData = null;
|
||||
currData = dbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => x.FileId == updItem.FileId)
|
||||
.FirstOrDefault();
|
||||
if (currData != null)
|
||||
{
|
||||
//// se ho modificato data --> cambio codice ordine!
|
||||
//if (!localDbCtx.Entry(updItem).OriginalValues["DtOrder"].Equals(localDbCtx.Entry(updItem).CurrentValues["DtOrder"]))
|
||||
//{
|
||||
// updItem.OrderCode = $"O{updItem.Plant.PlantCode}{updItem.DtOrder:yyMMddHHmm}";
|
||||
// updItem.OrderDesc = $"Ordine {updItem.Plant.PlantDesc} - {updItem.DtOrder}";
|
||||
//}
|
||||
localDbCtx.Entry(updItem).State = EntityState.Modified;
|
||||
localDbCtx.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbCtx
|
||||
.DbSetProgFile
|
||||
.Add(updItem);
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Eccezione durante FileUpdate");
|
||||
}
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elenco Azioni (decodifica)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DatabaseModels.AzioniUL> ActionsGetAll()
|
||||
{
|
||||
List<DatabaseModels.AzioniUL> dbResult = new List<DatabaseModels.AzioniUL>();
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetAzioniUL
|
||||
.ToList();
|
||||
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli da filtro
|
||||
/// </summary>
|
||||
/// <param name="numRecord"></param>
|
||||
/// <param name="searchVal"></param>
|
||||
/// <returns></returns>
|
||||
public List<DatabaseModels.AnagArticoli> ArticoliGetSearch(int numRecord, string searchVal = "")
|
||||
{
|
||||
List<DatabaseModels.AnagArticoli> dbResult = new List<DatabaseModels.AnagArticoli>();
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal))
|
||||
.OrderBy(x => x.CodArticolo)
|
||||
.Take(numRecord)
|
||||
.ToList();
|
||||
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli da filtro
|
||||
/// </summary>
|
||||
/// <param name="numRecord"></param>
|
||||
/// <param name="searchVal"></param>
|
||||
/// <returns></returns>
|
||||
public List<DatabaseModels.ODL> CommesseGetSearch(int numRecord, string searchVal = "")
|
||||
{
|
||||
List<DatabaseModels.ODL> dbResult = new List<DatabaseModels.ODL>();
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetODL
|
||||
.Where(x => x.KeyRichiesta.Contains(searchVal) || string.IsNullOrEmpty(searchVal))
|
||||
.OrderBy(x => x.KeyRichiesta)
|
||||
.Take(numRecord)
|
||||
.ToList();
|
||||
|
||||
return dbResult;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// effettua inserimento di un record in archivio come NUOVO documento tracciato
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user