public ActionResult RecordByAttachment(int id) { using (Entity context = new Entity()) { t_observation_attachment attachment = context.t_observation_attachment.Find(id); if (attachment == null) { throw new ArgumentException("Invalid ObservationAttachmentID: " + id.ToString()); } t_observation observation = context.t_observation.Find(attachment.observation_id); if (observation == null) { throw new ArgumentException("Invalid observationId: " + attachment.observation_id.ToString()); } t_site site = context.t_site.Find(observation.site_id); if (site == null) { throw new ArgumentException("Invalid siteId: " + observation.site_id.ToString()); } t_indicator indicator = context.t_indicator.Find(observation.indicator_id); if (indicator == null) { throw new ArgumentException("Invalid indicatorId: " + observation.indicator_id.ToString()); } return(View("Record", (new Observation(indicator, site, observation.begin_date)))); //RedirectToAction("Record", (new Observation(observation.site_id, site, observation.begin_date))); //return RedirectToAction("Record", new { indicatorId = observation.indicator_id, siteId = observation.site_id, beginDate = observation.begin_date }); //return Record(observation.indicator_id, observation.site_id, observation.begin_date); } }
public Request(t_site entity) : this(entity, false) { ObjectType = RequestObjectType.Site; ObjectId = entity.site_id; Name = entity.name; Status = SetStatus(entity.active); }
private void SetProperties(v_site site, bool loadChildren) { SiteId = site.site_id; SiteName = site.name; CountryId = site.country_id ?? 0; CountryName = site.country_name; SiteTypeFieldId = site.site_type_fieldid; SiteTypeValue = site.site_type_value; AdministrativeDivisionId1 = site.administrative_division_id_1; AdministrativeDivisionName1 = site.administrative_division_name_1; AdministrativeDivisionType1 = site.administrative_division_type_1; AdministrativeDivisionId2 = site.administrative_division_id_2; AdministrativeDivisionName2 = site.administrative_division_name_2; AdministrativeDivisionType2 = site.administrative_division_type_2; AdministrativeDivisionId3 = site.administrative_division_id_3; AdministrativeDivisionName3 = site.administrative_division_name_3; AdministrativeDivisionType3 = site.administrative_division_type_3; AdministrativeDivisionId4 = site.administrative_division_id_4; AdministrativeDivisionName4 = site.administrative_division_name_4; AdministrativeDivisionType4 = site.administrative_division_type_4; FundingTypeFieldId = site.funding_type_fieldid; FundingTypeValue = site.funding_type_value; Partner = site.partner; Longitude = site.longitude; Latitude = site.latitude; QIIndexScoreFieldId = site.qi_index_score_fieldid; QIIndexScoreValue = site.qi_index_score_value; PopulationDensityFieldId = site.rural_urban_fieldid; PopulationDensityValue = site.rural_urban_value; OtherKeyInformation = site.other_key_information; Active = site.active; if (loadChildren) { using (Entity context = new Entity()) { IsFavorite = context.t_user.Find(Identity.CurrentUser.Id).favorite_sites?.Select(e => e.site_id).Contains(site.site_id) ?? false; t_site t_site = context.t_site.Find(site.site_id); ICollection <t_note> notes = t_site.notes; Notes = notes.Select(e => new Note(e)).ToArray(); ICollection <t_activity> activities = t_site .activities .Select(e => e.activity) .Where(e => (e.active.HasValue && e.active.Value) || (e.createdby_userid == Identity.CurrentUser.Id) || (Identity.CurrentUser.IsInRole(Role.SystemAdministrator))) .ToArray(); Activities = activities.Select(e => new Activity(e)).ToArray(); } } }
private t_site SetCoreFields(Site model) { using (Entity context = new Entity()) { t_site site = null; if (model.SiteId.HasValue) { site = context.t_site.Find(model.SiteId.Value); if (site == null) { throw new ArgumentException("Invalid siteId: " + model.SiteId.ToString()); } site.updatedby_userid = CurrentUser.Id; site.updated_date = DateTime.Now; } else { site = new t_site(); site.createdby_userid = CurrentUser.Id; site.created_date = DateTime.Now; context.t_site.Add(site); } var language = IidCulture.CurrentLanguage; site.country_id = model.CountryId; site.site_type_fieldid = model.SiteTypeFieldId; site.administrative_division_id = model.AdministrativeDivisionId4 ?? model.AdministrativeDivisionId3 ?? model.AdministrativeDivisionId2 ?? model.AdministrativeDivisionId1 ?? -1; site.latitude = model.Latitude; site.longitude = model.Longitude; site.qi_index_score_fieldid = model.QIIndexScoreFieldId; site.rural_urban_fieldid = model.PopulationDensityFieldId; if (language == Language.English || !model.SiteId.HasValue) { site.other_key_information = model.OtherKeyInformation; } site.name = model.SiteName; site.funding_type_fieldid = model.FundingTypeFieldId; site.partner = model.Partner; site.active = model.Active; context.SaveChanges(); if (language != Language.English) { var languageId = IidCulture.CurrentLanguageId; var userId = CurrentUser.Id; site.set_other_key_information_translated(languageId, model.OtherKeyInformation, userId); } return(site); } }
public JsonResult Add(Note model) { if (ModelState.IsValid) { using (Entity db = new Entity()) { try { if (model.ActivityId.HasValue) { t_activity activity = db.t_activity.Find(model.ActivityId); if (activity == null) { throw new ArgumentException("Invalid activityId: " + model.ActivityId.ToString()); } } if (model.SiteId.HasValue) { t_site site = db.t_site.Find(model.SiteId); if (site == null) { throw new ArgumentException("Invalid siteId: " + model.SiteId.ToString()); } } t_note note = new t_note(); note.site_id = model.SiteId; note.activity_id = model.ActivityId; note.subject = model.Subject; note.note_text = model.NoteText; note.createdby_userid = CurrentUser.Id; note.created_date = DateTime.Now; db.t_note.Add(note); db.SaveChanges(); db.Entry(note).Reference(n => n.createdby).Load(); return(GetJsonResult(note)); } catch (Exception ex) { return(GetJsonResult(false, "An error occurred: " + ex.ToString())); } } } else { return(GetJsonResult(false, "Model is invalid.")); } }
private void SetSite(int siteId) { IEnumerable <t_site> sites; if (ActivityId.HasValue) { // Get sites user is allowed to access (view or update). DataTable userSites = StoredProcedures.GetUserSites(CurrentUserId, ActivityId.Value); var userSiteIds = userSites.AsEnumerable().Select(r => (int)r["site_id"]).ToArray(); sites = Context.t_site.Where(e => userSiteIds.Contains(e.site_id)); } else { sites = new t_site[] { Context.t_site.Find(siteId) }; } Sites = sites.OrderBy(e => e.name).ToDictionary(k => k.site_id, v => v.name); SelectedSiteId = siteId; }
public Observation(t_indicator indicator, t_site site, DateTime?beginDate) { t_observation observation = indicator.observations.Where(e => e.begin_date == beginDate && e.site_id == site.site_id).FirstOrDefault(); if (observation == null) { if (beginDate.HasValue) { BeginDate = beginDate.Value; ObjectParameter endDate = new ObjectParameter("end_date", typeof(DateTime)); Context.p_get_period_end_date(beginDate, indicator.data_collection_frequency_fieldid, endDate); EndDate = (DateTime)endDate.Value; } else { DateTime lastDay = beginDate ?? indicator.aim.activity.end_date ?? DateTime.Now; p_get_latest_date_period_Result result = Context.p_get_latest_date_period(lastDay, indicator.data_collection_frequency_fieldid).FirstOrDefault(); BeginDate = result.begin_date.Value; EndDate = result.end_date.Value; } IsAgeDisaggregated = indicator.disaggregate_by_age; IsSexDisaggregated = indicator.disaggregate_by_sex; } else { ObservationId = observation.observation_id; BeginDate = observation.begin_date; EndDate = observation.end_date; IsAgeDisaggregated = observation.is_age_disaggregated; IsSexDisaggregated = observation.is_sex_disaggregated; } SetProperties(indicator.indicator_id, site.site_id, observation, true); }