70 lines
2.6 KiB
C#
70 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace Consulenza.ReportCommon
|
|
{
|
|
public class ReportStruct
|
|
{
|
|
/// <summary>
|
|
/// Imposta o recupera la lista di schede richieste dal "frontend".
|
|
/// </summary>
|
|
public List<Scheda> Schede { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera le opzioni a livello di report globale.
|
|
/// </summary>
|
|
public Dictionary<string, string> Opzioni { get; set; }
|
|
|
|
/// <summary>
|
|
/// Recupera il primo oggetto Opzione a livello di Report la cui chiave corrisponde al tipo di opzione richiesto.
|
|
/// Se non trovato restituisce l'istanza valorizzata a null della classe il cui tipo è stato richiesto.
|
|
/// </summary>
|
|
/// <typeparam name="T">tipo di Opzione</typeparam>
|
|
/// <returns></returns>
|
|
public T GetOptionReport<T>() where T : class
|
|
{
|
|
var option = Opzioni.Where(p => p.Key.Equals(typeof(T).Name)).FirstOrDefault();
|
|
|
|
var type = Helper.GetType(string.Format("Consulenza.ReportCommon.{0}", option.Key));
|
|
|
|
if (type == null)
|
|
return (T)Activator.CreateInstance(typeof(T), null);
|
|
|
|
return (T)JsonConvert.DeserializeObject(option.Value, type);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera il primo oggetto Opzione a livello di Scheda (sezione) filtrato per IdSection la cui chiave corrisponde al tipo di opzione richiesto.
|
|
/// Se non trovato restituisce l'istanza valorizzata a null della classe il cui tipo è stato richiesto.
|
|
/// </summary>
|
|
/// <typeparam name="T">tipo di Opzione</typeparam>
|
|
/// <returns></returns>
|
|
public T GetOptionScheda<T>(int IdSection) where T : class
|
|
{
|
|
var option = Schede.Where(s => s.Id.Equals(IdSection)).FirstOrDefault()
|
|
.Opzioni.Where(p => p.Key.Equals(typeof(T).Name)).FirstOrDefault();
|
|
|
|
var type = Helper.GetType(string.Format("Consulenza.ReportCommon.{0}", option.Key));
|
|
|
|
if (type == null)
|
|
return (T)Activator.CreateInstance(typeof(T), null);
|
|
|
|
return (T)JsonConvert.DeserializeObject(option.Value, type);
|
|
}
|
|
}
|
|
|
|
public class Scheda
|
|
{
|
|
/// <summary>
|
|
/// Imposta o recupera le opzioni a livello di singola scheda [sezione].
|
|
/// </summary>
|
|
public Dictionary<string, string> Opzioni { get; set; }
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera l'Id della scheda.
|
|
/// </summary>
|
|
public int Id { get; set; }
|
|
}
|
|
} |