Пример #1
0
        public string GenerateUpdateJsonFromObject(Person 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(@"person");
            writer.WriteStartObject();

            if (!LastName.Equals(updateFrom.LastName))
            {
                writer.WritePropertyName("last_name");
                writer.WriteValue(updateFrom.LastName);
            }

            if (!FirstName.Equals(updateFrom.FirstName))
            {
                writer.WritePropertyName("first_name");
                writer.WriteValue(updateFrom.FirstName);
            }

            if (!MiddleName.Equals(updateFrom.MiddleName))
            {
                writer.WritePropertyName("middle_name");
                writer.WriteValue(updateFrom.MiddleName);
            }

            if (!Gender.Equals(updateFrom.Gender))
            {
                writer.WritePropertyName("sex");
                writer.WriteValue(updateFrom.Gender);
            }

            if (!DateOfBirth.Equals(updateFrom.DateOfBirth))
            {
                writer.WritePropertyName("dob");
                writer.WriteValue(updateFrom.DateOfBirth);
            }

            if (!DateOfBirthIsApproximate.Equals(updateFrom.DateOfBirthIsApproximate))
            {
                writer.WritePropertyName("is_birthdate_approximate");
                writer.WriteValue(updateFrom.DateOfBirthIsApproximate);
            }

            if (!RelationshipToHeadOfHousehold.Equals(updateFrom.RelationshipToHeadOfHousehold))
            {
                writer.WritePropertyName("relationship_id");
                writer.WriteValue(updateFrom.RelationshipToHeadOfHousehold.ExternalId);
            }

            if (!RelationshipIfOther.Equals(updateFrom.RelationshipIfOther))
            {
                writer.WritePropertyName("relationship_other");
                writer.WriteValue(updateFrom.RelationshipIfOther);
            }

            if (!IntakeDate.Equals(updateFrom.IntakeDate))
            {
                writer.WritePropertyName("intake_date");
                writer.WriteValue(updateFrom.IntakeDate);
            }

            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 (!PeopleHazardousConditions.Select(a => a.HazardousCondition).SequenceEqual(updateFrom.PeopleHazardousConditions.Select(a => a.HazardousCondition)))
            {
                writer.WritePropertyName("hazardous_condition_ids");
                writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleHazardousConditions.Select(a => a.HazardousCondition)));
            }

            if (!PeopleWorkActivities.Select(a => a.WorkActivity).SequenceEqual(updateFrom.PeopleWorkActivities.Select(a => a.WorkActivity)))
            {
                writer.WritePropertyName("work_activity_ids");
                writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleWorkActivities.Select(a => a.WorkActivity)));
            }

            if (!PeopleHouseholdTasks.Select(a => a.HouseholdTask).SequenceEqual(updateFrom.PeopleHouseholdTasks.Select(a => a.HouseholdTask)))
            {
                writer.WritePropertyName("household_task_ids");
                writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleHouseholdTasks.Select(a => a.HouseholdTask)));
            }

            if (!ExternalParentId.Equals(updateFrom.ExternalParentId))
            {
                writer.WritePropertyName("household_id");
                writer.WriteValue(updateFrom.ExternalParentId);
            }

            writer.WriteEndObject();
            writer.WriteEndObject();
            return(sw.ToString());
        }
Пример #2
0
        public void UpdateObject(Person updateFrom)
        {
            LastUpdatedAt                 = updateFrom.LastUpdatedAt;
            ExternalParentId              = updateFrom.ExternalParentId;
            LastName                      = updateFrom.LastName;
            FirstName                     = updateFrom.FirstName;
            MiddleName                    = updateFrom.MiddleName;
            Gender                        = updateFrom.Gender;
            DateOfBirth                   = updateFrom.DateOfBirth;
            DateOfBirthIsApproximate      = updateFrom.DateOfBirthIsApproximate;
            RelationshipToHeadOfHousehold = updateFrom.RelationshipToHeadOfHousehold;
            RelationshipIfOther           = updateFrom.RelationshipIfOther;
            IntakeDate                    = updateFrom.IntakeDate;
            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 (!PeopleWorkActivities.Select(a => a.WorkActivity.InternalId).SequenceEqual(updateFrom.PeopleWorkActivities.Select(a => a.WorkActivity.InternalId)))
            {
                MdpmsDatabaseContext.RemoveRange(PeopleWorkActivities);
                MdpmsDatabaseContext.SaveChanges();
                foreach (var x in updateFrom.PeopleWorkActivities.Select(a => a.WorkActivity.InternalId))
                {
                    var scQuery = MdpmsDatabaseContext.StatusCustomizationWorkActivities.Where(a => a.InternalId == x);
                    if (scQuery.Any())
                    {
                        PeopleWorkActivities.Add(new PersonWorkActivity
                        {
                            Person       = this,
                            WorkActivity = scQuery.First()
                        });
                    }
                }
                MdpmsDatabaseContext.SaveChanges();
            }
            if (!PeopleHazardousConditions.Select(a => a.HazardousCondition.InternalId).SequenceEqual(updateFrom.PeopleHazardousConditions.Select(a => a.HazardousCondition.InternalId)))
            {
                MdpmsDatabaseContext.RemoveRange(PeopleHazardousConditions);
                MdpmsDatabaseContext.SaveChanges();
                foreach (var x in updateFrom.PeopleHazardousConditions.Select(a => a.HazardousCondition.InternalId))
                {
                    var scQuery = MdpmsDatabaseContext.StatusCustomizationHazardousConditions.Where(a => a.InternalId == x);
                    if (scQuery.Any())
                    {
                        PeopleHazardousConditions.Add(new PersonHazardousCondition
                        {
                            Person             = this,
                            HazardousCondition = scQuery.First()
                        });
                    }
                }
                MdpmsDatabaseContext.SaveChanges();
            }
            if (!PeopleHouseholdTasks.Select(a => a.HouseholdTask.InternalId).SequenceEqual(updateFrom.PeopleHouseholdTasks.Select(a => a.HouseholdTask.InternalId)))
            {
                MdpmsDatabaseContext.RemoveRange(PeopleHouseholdTasks);
                MdpmsDatabaseContext.SaveChanges();
                foreach (var x in updateFrom.PeopleHouseholdTasks.Select(a => a.HouseholdTask.InternalId))
                {
                    var scQuery = MdpmsDatabaseContext.StatusCustomizationHouseholdTasks.Where(a => a.InternalId == x);
                    if (scQuery.Any())
                    {
                        PeopleHouseholdTasks.Add(new PersonHouseholdTask
                        {
                            Person        = this,
                            HouseholdTask = scQuery.First()
                        });
                    }
                }
                MdpmsDatabaseContext.SaveChanges();
            }
        }
Пример #3
0
 public bool GetObjectNeedsUpate(Person checkUpdateFrom)
 {
     if (!LastName.Equals(checkUpdateFrom.LastName))
     {
         return(true);
     }
     if (!FirstName.Equals(checkUpdateFrom.FirstName))
     {
         return(true);
     }
     if (!MiddleName.Equals(checkUpdateFrom.MiddleName))
     {
         return(true);
     }
     if (!Gender.Equals(checkUpdateFrom.Gender))
     {
         return(true);
     }
     if (!DateOfBirth.Equals(checkUpdateFrom.DateOfBirth))
     {
         return(true);
     }
     if (!DateOfBirthIsApproximate.Equals(checkUpdateFrom.DateOfBirthIsApproximate))
     {
         return(true);
     }
     if (!RelationshipToHeadOfHousehold.Equals(checkUpdateFrom.RelationshipToHeadOfHousehold))
     {
         return(true);
     }
     if (!RelationshipIfOther.Equals(checkUpdateFrom.RelationshipIfOther))
     {
         return(true);
     }
     if (!IntakeDate.Equals(checkUpdateFrom.IntakeDate))
     {
         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 (!PeopleHazardousConditions.Select(a => a.HazardousCondition).SequenceEqual(checkUpdateFrom.PeopleHazardousConditions.Select(a => a.HazardousCondition)))
     {
         return(true);
     }
     if (!PeopleWorkActivities.Select(a => a.WorkActivity).SequenceEqual(checkUpdateFrom.PeopleWorkActivities.Select(a => a.WorkActivity)))
     {
         return(true);
     }
     if (!PeopleHouseholdTasks.Select(a => a.HouseholdTask).SequenceEqual(checkUpdateFrom.PeopleHouseholdTasks.Select(a => a.HouseholdTask)))
     {
         return(true);
     }
     if (!ExternalParentId.Equals(checkUpdateFrom.ExternalParentId))
     {
         return(true);
     }
     return(false);
 }
Пример #4
0
        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(@"person");
                writer.WriteStartObject();
                writer.WritePropertyName("first_name");
                writer.WriteValue(FirstName ?? @"");
                writer.WritePropertyName("last_name");
                writer.WriteValue(LastName ?? @"");

                if (MiddleName != null)
                {
                    writer.WritePropertyName("middle_name");
                    writer.WriteValue(MiddleName);
                }

                writer.WritePropertyName("sex");
                writer.WriteValue(Gender.DpmsGenderNumber);

                if (DateOfBirth != null)
                {
                    var dob = (DateTime)DateOfBirth;
                    writer.WritePropertyName("dob");
                    writer.WriteValue(dob.ToString("yyyy-MM-dd"));
                }

                if (IntakeDate != null)
                {
                    var intakeDate = (DateTime)IntakeDate;
                    writer.WritePropertyName("intake_date");
                    writer.WriteValue(intakeDate.ToString("yyyy-MM-dd"));
                }

                if (RelationshipToHeadOfHousehold != null)
                {
                    writer.WritePropertyName("relationship_id");
                    writer.WriteValue(RelationshipToHeadOfHousehold.GetExternalId());
                }

                if (RelationshipIfOther != null)
                {
                    writer.WritePropertyName("relationship_other");
                    writer.WriteValue(RelationshipIfOther);
                }

                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 (DateOfBirthIsApproximate != null)
                {
                    writer.WritePropertyName("is_birthdate_approximate");
                    writer.WriteValue(DateOfBirthIsApproximate);
                }

                writer.WritePropertyName("household_id");
                writer.WriteValue(ExternalParentId);

                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("hazardous_condition_ids");
                writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleHazardousConditions.Select(a => a.HazardousCondition)));

                writer.WritePropertyName("work_activity_ids");
                writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleWorkActivities.Select(a => a.WorkActivity)));

                writer.WritePropertyName("household_task_ids");
                writer.WriteRawValue(GetStatusArrayAsJsonString(PeopleHouseholdTasks.Select(a => a.HouseholdTask)));

                writer.WriteEndObject();
                writer.WriteEndObject();
            }
            return(sw.ToString());
        }