public string GenerateUpdateJsonFromObject(PersonFollowUp updateFrom) { // form the json (determine the fields that need to be updated) var sb = new StringBuilder(); var sw = new StringWriter(sb); var writer = new JsonTextWriter(sw) { Formatting = Formatting.None }; writer.WriteStartObject(); writer.WritePropertyName(@"follow_up"); writer.WriteStartObject(); if (!FollowUpDate.Equals(updateFrom.FollowUpDate)) { writer.WritePropertyName("follow_date"); writer.WriteValue(updateFrom.FollowUpDate); } if (!HaveJobReturningTo.Equals(updateFrom.HaveJobReturningTo)) { writer.WritePropertyName("have_job_returning_to"); writer.WriteValue(updateFrom.HaveJobReturningTo); } if (!HoursWorked.Equals(updateFrom.HoursWorked)) { writer.WritePropertyName("hours_worked"); writer.WriteValue(updateFrom.HoursWorked); } if (!HouseWorkedOnHousework.Equals(updateFrom.HouseWorkedOnHousework)) { writer.WritePropertyName("hours_worked_on_housework"); writer.WriteValue(updateFrom.HouseWorkedOnHousework); } if (!EnrolledInSchool.Equals(updateFrom.EnrolledInSchool)) { writer.WritePropertyName("enrolled_in_school"); writer.WriteValue(updateFrom.EnrolledInSchool); } if (!GpsLatitude.Equals(updateFrom.GpsLatitude)) { writer.WritePropertyName("latitude"); writer.WriteValue(updateFrom.GpsLatitude); } if (!GpsLongitude.Equals(updateFrom.GpsLongitude)) { writer.WritePropertyName("longitude"); writer.WriteValue(updateFrom.GpsLongitude); } if (!GpsPositionAccuracy.Equals(updateFrom.GpsPositionAccuracy)) { writer.WritePropertyName("position_accuracy"); writer.WriteValue(updateFrom.GpsPositionAccuracy); } if (!GpsAltitude.Equals(updateFrom.GpsAltitude)) { writer.WritePropertyName("altitude"); writer.WriteValue(updateFrom.GpsAltitude); } if (!GpsAltitudeAccuracy.Equals(updateFrom.GpsAltitudeAccuracy)) { writer.WritePropertyName("altitude_accuracy"); writer.WriteValue(updateFrom.GpsAltitudeAccuracy); } if (!GpsHeading.Equals(updateFrom.GpsHeading)) { writer.WritePropertyName("heading"); writer.WriteValue(updateFrom.GpsHeading); } if (!GpsSpeed.Equals(updateFrom.GpsSpeed)) { writer.WritePropertyName("speed"); writer.WriteValue(updateFrom.GpsSpeed); } if (!GpsPositionTime.Equals(updateFrom.GpsPositionTime)) { writer.WritePropertyName("gps_recorded_at"); writer.WriteValue(updateFrom.GpsPositionTime); } if (!PeopleFollowUpHazardousConditions.Select(a => a.HazardousCondition).SequenceEqual(updateFrom.PeopleFollowUpHazardousConditions.Select(a => a.HazardousCondition))) { writer.WritePropertyName("hazardous_condition_ids"); writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleFollowUpHazardousConditions.Select(a => a.HazardousCondition))); } if (!PeopleFollowUpWorkActivities.Select(a => a.WorkActivity).SequenceEqual(updateFrom.PeopleFollowUpWorkActivities.Select(a => a.WorkActivity))) { writer.WritePropertyName("work_activity_ids"); writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleFollowUpWorkActivities.Select(a => a.WorkActivity))); } if (!PeopleFollowUpHouseholdTasks.Select(a => a.HouseholdTask).SequenceEqual(updateFrom.PeopleFollowUpHouseholdTasks.Select(a => a.HouseholdTask))) { writer.WritePropertyName("household_task_ids"); writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleFollowUpHouseholdTasks.Select(a => a.HouseholdTask))); } if (!ExternalParentId.Equals(updateFrom.ExternalParentId)) { writer.WritePropertyName("person_id"); writer.WriteValue(updateFrom.ExternalParentId); } writer.WriteEndObject(); writer.WriteEndObject(); return(sw.ToString()); }
public void UpdateObject(PersonFollowUp updateFrom) { LastUpdatedAt = updateFrom.LastUpdatedAt; ExternalParentId = updateFrom.ExternalParentId; FollowUpDate = updateFrom.FollowUpDate; HaveJobReturningTo = updateFrom.HaveJobReturningTo; HoursWorked = updateFrom.HoursWorked; HouseWorkedOnHousework = updateFrom.HouseWorkedOnHousework; EnrolledInSchool = updateFrom.EnrolledInSchool; GpsLatitude = updateFrom.GpsLatitude; GpsLongitude = updateFrom.GpsLongitude; GpsPositionAccuracy = updateFrom.GpsPositionAccuracy; GpsAltitude = updateFrom.GpsAltitude; GpsAltitudeAccuracy = updateFrom.GpsAltitudeAccuracy; GpsHeading = updateFrom.GpsHeading; GpsSpeed = updateFrom.GpsSpeed; GpsPositionTime = updateFrom.GpsPositionTime; // update status customizations if (!PeopleFollowUpWorkActivities.Select(a => a.WorkActivity.InternalId).SequenceEqual(updateFrom.PeopleFollowUpWorkActivities.Select(a => a.WorkActivity.InternalId))) { MdpmsDatabaseContext.RemoveRange(PeopleFollowUpWorkActivities); MdpmsDatabaseContext.SaveChanges(); foreach (var x in updateFrom.PeopleFollowUpWorkActivities.Select(a => a.WorkActivity.InternalId)) { var scQuery = MdpmsDatabaseContext.StatusCustomizationWorkActivities.Where(a => a.InternalId == x); if (scQuery.Any()) { PeopleFollowUpWorkActivities.Add(new PersonFollowUpWorkActivity { PersonFollowUp = this, WorkActivity = scQuery.First() }); } } MdpmsDatabaseContext.SaveChanges(); } if (!PeopleFollowUpHazardousConditions.Select(a => a.HazardousCondition.InternalId).SequenceEqual(updateFrom.PeopleFollowUpHazardousConditions.Select(a => a.HazardousCondition.InternalId))) { MdpmsDatabaseContext.RemoveRange(PeopleFollowUpHazardousConditions); MdpmsDatabaseContext.SaveChanges(); foreach (var x in updateFrom.PeopleFollowUpHazardousConditions.Select(a => a.HazardousCondition.InternalId)) { var scQuery = MdpmsDatabaseContext.StatusCustomizationHazardousConditions.Where(a => a.InternalId == x); if (scQuery.Any()) { PeopleFollowUpHazardousConditions.Add(new PersonFollowUpHazardousCondition { PersonFollowUp = this, HazardousCondition = scQuery.First() }); } } MdpmsDatabaseContext.SaveChanges(); } if (!PeopleFollowUpHouseholdTasks.Select(a => a.HouseholdTask.InternalId).SequenceEqual(updateFrom.PeopleFollowUpHouseholdTasks.Select(a => a.HouseholdTask.InternalId))) { MdpmsDatabaseContext.RemoveRange(PeopleFollowUpHouseholdTasks); MdpmsDatabaseContext.SaveChanges(); foreach (var x in updateFrom.PeopleFollowUpHouseholdTasks.Select(a => a.HouseholdTask.InternalId)) { var scQuery = MdpmsDatabaseContext.StatusCustomizationHouseholdTasks.Where(a => a.InternalId == x); if (scQuery.Any()) { PeopleFollowUpHouseholdTasks.Add(new PersonFollowUpHouseholdTask { PersonFollowUp = this, HouseholdTask = scQuery.First() }); } } MdpmsDatabaseContext.SaveChanges(); } }
public bool GetObjectNeedsUpate(PersonFollowUp checkUpdateFrom) { if (!FollowUpDate.Equals(checkUpdateFrom.FollowUpDate)) { return(true); } if (!HaveJobReturningTo.Equals(checkUpdateFrom.HaveJobReturningTo)) { return(true); } if (!HoursWorked.Equals(checkUpdateFrom.HoursWorked)) { return(true); } if (!HouseWorkedOnHousework.Equals(checkUpdateFrom.HouseWorkedOnHousework)) { return(true); } if (!EnrolledInSchool.Equals(checkUpdateFrom.EnrolledInSchool)) { return(true); } if (!GpsLatitude.Equals(checkUpdateFrom.GpsLatitude)) { return(true); } if (!GpsLongitude.Equals(checkUpdateFrom.GpsLongitude)) { return(true); } if (!GpsPositionAccuracy.Equals(checkUpdateFrom.GpsPositionAccuracy)) { return(true); } if (!GpsAltitude.Equals(checkUpdateFrom.GpsAltitude)) { return(true); } if (!GpsAltitudeAccuracy.Equals(checkUpdateFrom.GpsAltitudeAccuracy)) { return(true); } if (!GpsHeading.Equals(checkUpdateFrom.GpsHeading)) { return(true); } if (!GpsSpeed.Equals(checkUpdateFrom.GpsSpeed)) { return(true); } if (!GpsPositionTime.Equals(checkUpdateFrom.GpsPositionTime)) { return(true); } if (!PeopleFollowUpHazardousConditions.Select(a => a.HazardousCondition).SequenceEqual(checkUpdateFrom.PeopleFollowUpHazardousConditions.Select(a => a.HazardousCondition))) { return(true); } if (!PeopleFollowUpWorkActivities.Select(a => a.WorkActivity).SequenceEqual(checkUpdateFrom.PeopleFollowUpWorkActivities.Select(a => a.WorkActivity))) { return(true); } if (!PeopleFollowUpHouseholdTasks.Select(a => a.HouseholdTask).SequenceEqual(checkUpdateFrom.PeopleFollowUpHouseholdTasks.Select(a => a.HouseholdTask))) { return(true); } if (!ExternalParentId.Equals(checkUpdateFrom.ExternalParentId)) { return(true); } return(false); }
public string GetJsonFromObject() { var sb = new StringBuilder(); var sw = new StringWriter(sb); using (JsonWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.None; writer.WriteStartObject(); writer.WritePropertyName(@"follow_up"); writer.WriteStartObject(); if (FollowUpDate != null) { var followDate = (DateTime)FollowUpDate; writer.WritePropertyName("follow_date"); writer.WriteValue(followDate.ToString("yyyy-MM-dd")); } if (HaveJobReturningTo != null) { writer.WritePropertyName("have_job_returning_to"); writer.WriteValue(HaveJobReturningTo); } if (HoursWorked != null) { writer.WritePropertyName("hours_worked"); writer.WriteValue(HoursWorked); } if (HouseWorkedOnHousework != null) { writer.WritePropertyName("hours_worked_on_housework"); writer.WriteValue(HouseWorkedOnHousework); } if (EnrolledInSchool != null) { writer.WritePropertyName("enrolled_in_school"); writer.WriteValue(EnrolledInSchool); } if (GpsLatitude != null) { writer.WritePropertyName("latitude"); writer.WriteValue(GpsLatitude); } if (GpsLongitude != null) { writer.WritePropertyName("longitude"); writer.WriteValue(GpsLongitude); } if (GpsPositionAccuracy != null) { writer.WritePropertyName("position_accuracy"); writer.WriteValue(GpsPositionAccuracy); } if (GpsAltitude != null) { writer.WritePropertyName("altitude"); writer.WriteValue(GpsAltitude); } if (GpsAltitudeAccuracy != null) { writer.WritePropertyName("altitude_accuracy"); writer.WriteValue(GpsAltitudeAccuracy); } if (GpsHeading != null) { writer.WritePropertyName("heading"); writer.WriteValue(GpsHeading); } if (GpsSpeed != null) { writer.WritePropertyName("speed"); writer.WriteValue(GpsSpeed); } if (GpsPositionTime != null) { writer.WritePropertyName("gps_recorded_at"); writer.WriteValue(GpsPositionTime); } writer.WritePropertyName("person_id"); writer.WriteValue(ExternalParentId); writer.WritePropertyName("hazardous_condition_ids"); writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleFollowUpHazardousConditions.Select(a => a.HazardousCondition))); writer.WritePropertyName("work_activity_ids"); writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleFollowUpWorkActivities.Select(a => a.WorkActivity))); writer.WritePropertyName("household_task_ids"); writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleFollowUpHouseholdTasks.Select(a => a.HouseholdTask))); writer.WriteEndObject(); writer.WriteEndObject(); } return(sw.ToString()); }