public static List <ObservationDatePeriod> GetDatePeriods(int indicatorId, int siteId, DateTime date, int?periods) { using (Entity context = new Entity()) { var list = new List <ObservationDatePeriod>(); var result = context.p_get_observation_date_periods(indicatorId, siteId, date, periods); foreach (var r in result) { // Set the times as UTC. Important for JSON serialization! var odp = new ObservationDatePeriod() { ObservationId = r.observation_id }; if (r.begin_date.HasValue) { odp.BeginDate = DateTime.SpecifyKind(r.begin_date.Value, DateTimeKind.Local); } if (r.end_date.HasValue) { odp.EndDate = DateTime.SpecifyKind(r.end_date.Value, DateTimeKind.Local); } odp.HasChangeCommentAttachment = r.has_changecommentattachment; odp.ObservationId = r.observation_id; list.Add(odp); } return(list); } }
private void SetProperties(int indicatorId, int siteId, t_observation observation, bool loadChildren) { IndicatorId = indicatorId; SiteId = siteId; t_observation_entry firstEntry = observation?.entries?.FirstOrDefault(); CreatedBy = firstEntry?.createdby?.full_name; CreatedOn = firstEntry?.created_date; UpdatedBy = firstEntry?.updateby?.full_name; UpdatedOn = firstEntry?.updated_date; // Observation entries. Entries = StoredProcedures.GetObservations(IndicatorId, SiteId, BeginDate); if (loadChildren) { // Aim and Indicator Indicator = new Indicator(IndicatorId, false); Aim = new Aim(Indicator.AimId, false); // Other Aim Indicators // NOTE: Don't use UserAssignedObjects here. Only show active aims/indicators. var aims = Context.t_indicator.Find(indicatorId).aim.activity.aims .Where(e => e.active == true).OrderBy(e => e.sort); AimsAndIndicators = new List <Tuple <string, int, string> >(); foreach (var aim in aims) { AimsAndIndicators.Add(new Tuple <string, int, string>("Aim", aim.aim_id, aim.get_name_translated(CurrentLanguageId))); foreach (var ind in aim.indicators.Where(e => e.active == true).OrderBy(e => e.sort)) { AimsAndIndicators.Add(new Tuple <string, int, string>("Indicator", ind.indicator_id, ind.get_name_translated(CurrentLanguageId))); } } // Populate date period selector's initial set of date periods. DatePeriods = ObservationDatePeriod.GetDatePeriods(IndicatorId, siteId, BeginDate, null) .ToDictionary(k => k.BeginDate.ToString("yyyy-MM-dd"), v => v); // One-time population of min/max tolerance dictionary. MinMaxTolerance = GetMinMaxTolerance(); // Child collections. Changes = observation?.changes?.OrderBy(e => e.start_date).Select(e => new ObservationChange(e)).ToList(); Attachments = observation?.attachments?.Select(e => new ObservationAttachment(e)).Where(a => (a.Active == true) || (a.CreatedByUserId == CurrentUserId) || (CurrentUser.IsInRole(BusinessLayer.Identity.Role.SystemAdministrator))).ToList(); Comments = observation?.comments?.OrderBy(e => e.created_date).Select(e => new ObservationComment(e)).ToList(); History = observation?.change_history?.OrderBy(e => e.change_history_id).Select(e => new ObservationHistory(e)).ToList(); using (Entity context = new Entity()) Sexes = context.t_sex.OrderBy(e => e.sex_id).ToDictionary(e => e.sex_code, e => e.sex_description); } }