using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using NHibernate; using NHibernate.Linq; using Sleis.Models; using Sleis.Infrastructure; using log4net; using Sleis.Utility; using Sleis.Data; using Sleis.ViewModels; using Sleis.Models.CustomFields; namespace Sleis.Service { public class CustomFieldService : BaseService { public override void Init() { base.Init(); } public new List GetCustomFields(int id, int reportYear, CustomFieldEntityType entityType) where T : CustomFieldEntityValue { List customFields = new List(); //Get all custom fields for this type of identity foreach (CustomFieldModel field in CustomFieldData.Get(entityType)) { //Create an instance of the custom field view CustomFieldView fieldView = new CustomFieldView(field); //Set field vuew value in case this is an edit fieldView.Value = CustomFieldValueData.Get(id, fieldView.Field.Id); if ( (field.LastReportingYear == 0) || //End year has not been set (field.LastReportingYear >= reportYear) || //End year >= reporting year (!fieldView.ValueIsNullOrEmpty) //Regardless of the reporting year, if the value is there ) { //if the value has not been set if (fieldView.Value == null) { fieldView.Value = new CustomFieldEntityValue(); } customFields.Add(fieldView); } } return customFields; } } }