public void MergeWith(RoomAvailability otherAvailability) { if (!otherAvailability.RoomNumber.Equals(RoomNumber)) { throw new Exception("Error: Cannot merge availabilities for different rooms into one object"); } foreach (KeyValuePair <DateTime, AvailabilityType> otherEntry in otherAvailability.TotalAvailability) { DateTime otherKey = otherEntry.Key; AvailabilityType otherValue = otherEntry.Value; if (TotalAvailability.ContainsKey(otherKey)) { AvailabilityType existingValue = TotalAvailability[otherKey]; if (otherValue.Equals(AvailabilityType.NOT_SET) ^ existingValue.Equals(AvailabilityType.NOT_SET)) { throw new Exception("Error when merging room availabilities for date " + otherKey.ToLongDateString() + "; One value was set and the other was null"); } else if (!otherValue.Equals(AvailabilityType.NOT_SET) && !existingValue.Equals(AvailabilityType.NOT_SET) && !otherValue.Equals(existingValue)) { throw new Exception("Error when merging room availabilities for date " + otherKey.ToLongDateString() + "; One value was " + otherValue.ToString() + " and the other was " + existingValue.ToString()); } } else { TotalAvailability.Add(otherKey, otherEntry.Value); } } }
/// <summary> /// Returns true if AvailabilitiesAvailability instances are equal /// </summary> /// <param name="other">Instance of AvailabilitiesAvailability to be compared</param> /// <returns>Boolean</returns> public bool Equals(AvailabilitiesAvailability other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Date == other.Date || Date != null && Date.Equals(other.Date) ) && ( AvailabilityType == other.AvailabilityType || AvailabilityType != null && AvailabilityType.Equals(other.AvailabilityType) ) && ( Start == other.Start || Start != null && Start.Equals(other.Start) ) && ( End == other.End || End != null && End.Equals(other.End) ) && ( NumberOfOccurrences == other.NumberOfOccurrences || NumberOfOccurrences.Equals(other.NumberOfOccurrences) ) && ( Notes == other.Notes || Notes != null && Notes.Equals(other.Notes) )); }