116 lines
2.8 KiB
C#
116 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using GWMS.Data.DTO;
|
|
using Microsoft.Extensions.Configuration;
|
|
using NLog;
|
|
|
|
namespace GWMS.Data.Controllers
|
|
{
|
|
public class GWMSController : IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
private static GWMSContext dbCtx;
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public GWMSController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
dbCtx = new GWMSContext(configuration);
|
|
Log.Info("Avviata classe GWMSController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
dbCtx.Dispose();
|
|
}
|
|
|
|
public List<DatabaseModels.ConfigModel> GetConfig()
|
|
{
|
|
var dbResult = dbCtx
|
|
.DbSetConfig
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
public List<DatabaseModels.ItemModel> GetItems()
|
|
{
|
|
var dbResult = dbCtx
|
|
.DbSetItems
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
public DatabaseModels.PlantDetailModel GetPlant(int PlantId)
|
|
{
|
|
var dbResult = dbCtx
|
|
.DbSetPlant
|
|
.Where(x => x.PlantId == PlantId)
|
|
.FirstOrDefault();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
public List<DatabaseModels.PlantDetailModel> GetPlants()
|
|
{
|
|
var dbResult = dbCtx
|
|
.DbSetPlant
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
public List<PlantDTO> GetPlantsDTO()
|
|
{
|
|
var plantList = dbCtx
|
|
.DbSetPlant
|
|
.ToList();
|
|
|
|
var dbResult = plantList
|
|
.Select(x => PlantDTO(x.PlantId))
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero info PLANT modalità DTO
|
|
/// </summary>
|
|
/// <param name="PlantId"></param>
|
|
/// <returns></returns>
|
|
public PlantDTO PlantDTO(int PlantId)
|
|
{
|
|
var currPlant = GetPlant(PlantId);
|
|
|
|
// FIXME TODO !!!! è casuale
|
|
Random rnd = new Random();
|
|
|
|
PlantDTO answ = new PlantDTO()
|
|
{
|
|
PlantId = PlantId,
|
|
PlantCode = currPlant.PlantCode,
|
|
PlantDesc = currPlant.PlantDesc,
|
|
LevelAct = rnd.Next(1, (int)currPlant.LevelMax),
|
|
LevelMax = currPlant.LevelMax
|
|
};
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |