using System.Collections.Generic;
using Newtonsoft.Json;
using System;
using System.Linq;
namespace Consulenza.ReportCommon
{
public class ReportStruct
{
///
/// Imposta o recupera la lista di schede richieste dal "frontend".
///
public List Schede { get; set; }
///
/// Imposta o recupera le opzioni a livello di report globale.
///
public Dictionary Opzioni { get; set; }
///
/// 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.
///
/// tipo di Opzione
///
public T GetOptionReport() 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);
}
///
/// 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.
///
/// tipo di Opzione
///
public T GetOptionScheda(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
{
///
/// Imposta o recupera le opzioni a livello di singola scheda [sezione].
///
public Dictionary Opzioni { get; set; }
///
/// Imposta o recupera l'Id della scheda.
///
public int Id { get; set; }
}
}