コード例 #1
0
        private bool appendToSchools(Centre centre)
        {
            int  currentCount  = schoolsArray.Count;
            bool existsAlready = false;

            foreach (JObject sObject in schoolsArray)
            {
                //convert to string as cannot compare with JToken
                String school   = (String)sObject.GetValue(AppConstants.TAG_SCHOOL_NAME);
                String district = (String)sObject.GetValue(AppConstants.TAG_DISTRICT);

                if (school.Trim().Equals(centre.getCentreName().Trim()) &&
                    district.Trim().Equals(centre.getDistrict().Trim())
                    )
                {
                    existsAlready = true;
                }
            }

            if (!existsAlready)
            {
                School mSchool = new School(centre.getCentreName(), centre.getDistrict(), null); //define new school
                schoolsArray.Add(mSchool.toJSONObject());
                schoolCount++;                                                                   //increment school count
            }

            //if new school has been added
            if (currentCount < schoolsArray.Count)
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        private bool appendToCentres(Centre centre)
        {
            int  currentCount  = centresArray.Count;//get current centre count before add operation
            bool existsAlready = false;

            foreach (JObject cObject in centresArray)
            {
                //convert to string as cannot compare with JToken
                String cName = (String)cObject.GetValue(AppConstants.TAG_CENTRE_NAME);
                String cCode = (String)cObject.GetValue(AppConstants.TAG_CENTRE_CODE);

                //if centre name and centre code match then do not add centre as it already exists
                if (cName.Trim().Equals(centre.getCentreName().Trim()) &&
                    cCode.Trim().Equals(centre.getCentreCode().Trim())
                    )
                {
                    existsAlready = true;
                }
            }

            if (!existsAlready)                          //if centre does not already exist
            {
                centresArray.Add(centre.toJSONObject()); //add centre
                centreCount++;                           //increment centre count
            }

            //new centre has been added
            if (currentCount < centresArray.Count)
            {
                return(true);
            }

            return(false);
        }