Example #1
0
        /// <summary>
        ///     Merges the weather data collections.
        /// </summary>
        /// <param name="currentDataCollection">The old weather data collection.</param>
        /// <param name="newWeatherData">The new weather data collection.</param>
        /// <returns> the collection with the data</returns>
        public async Task <WeatherDataCollection> MergeWeatherDataCollections(
            WeatherDataCollection currentDataCollection, WeatherDataCollection newWeatherData)
        {
            this.oldWeatherDataCollection = currentDataCollection ??
                                            throw new ArgumentNullException(nameof(this.oldWeatherDataCollection), "Current collection cannot be null.");
            this.newWeatherDataCollection = newWeatherData ??
                                            throw new ArgumentNullException(nameof(newWeatherData), "New collection cannot be null.");


            var updatedWeatherDataCollection = new WeatherDataCollection();

            this.addNonConflictingData(updatedWeatherDataCollection);

            foreach (var conflictingDay in this.newWeatherDataCollection)
            {
                if (this.oldWeatherDataCollection.Any(oldDay => oldDay.Date.Equals(conflictingDay.Date)) &&
                    !this.isDoForAllChecked)
                {
                    var keepOrReplace = new ReplaceOrKeepDialog(conflictingDay, newWeatherData.Count);
                    this.chosenResult = await keepOrReplace.ShowAsync();

                    this.isDoForAllChecked = keepOrReplace.IsDoForAllChecked;
                }

                this.addConflictingDayToUpdatedCollection(conflictingDay, updatedWeatherDataCollection);
            }

            var tempWeatherDataCollection = updatedWeatherDataCollection.ToList();

            tempWeatherDataCollection.Sort();
            updatedWeatherDataCollection.Clear();

            foreach (var day in tempWeatherDataCollection)
            {
                updatedWeatherDataCollection.Add(day);
            }
            return(updatedWeatherDataCollection);
        }