/// <summary> /// Returns true if the repository containsthe provided <see cref="Fav"/> /// </summary> /// <param name="target"><see cref="Fav"/> to find ; cannot be null</param> /// <exception cref="ArgumentNullException"> when the parameter is null</exception> /// <returns>true if the repository a matching <see cref="Fav"/>, false otherwise</returns> public bool Contains(Fav target) { if (target == null) { throw new ArgumentNullException(); } return(this.favs.Where(fav => fav.Name == target.Name && fav.Uri.AbsoluteUri == target.Uri.AbsoluteUri).Any()); }
/// <summary> /// Return a <see cref="Fav"/> matching the provided one, or null if no record was found /// </summary> /// <param name="target"><see cref="Fav"/> to find ; cannot be null</param> /// <exception cref="ArgumentNullException"> when the parameter is null</exception> /// <returns>Matching <see cref="Fav"/> or null</returns> public Fav Find(Fav target) { if (target == null) { throw new ArgumentNullException(); } return(this.Contains(target) ? this.favs.Where(fav => fav.Name == target.Name && fav.Uri.AbsoluteUri == target.Uri.AbsoluteUri).Single() : null); }
/// <summary> /// Adds a new <see cref="Fav"/> to the favorites repository /// Throws a <see cref="FavAlreadyExistsException"/> if the provided <see cref="Fav"/> already exists in the respository /// </summary> /// <exception cref="FavAlreadyExistsException"/> /// <exception cref="ArgumentNullException"> when the parameter is null</exception> /// <param name="fav"><see cref="Fav"/> to add to the repository ; cannot be null</param> public void Add(Fav fav) { if (fav == null) { throw new ArgumentNullException(); } if (this.Contains(fav)) { throw new FavAlreadyExistsException(); } this.favs.Add(fav); }
/// <summary> /// Removes a <see cref="Fav"/> from the repository /// Throws a <see cref="FavDoesntExistException"/> if the provided <see cref="Fav"/> doesn't exist in the repository /// </summary> /// <exception cref="FavDoesntExistException"/> /// <param name="fav"><see cref="Fav"/> to remove ; cannot be null</param> /// <exception cref="ArgumentNullException"> when the parameter is null</exception> public void Remove(Fav fav) { if (fav == null) { throw new ArgumentNullException(); } if (!this.Contains(fav)) { throw new FavDoesntExistException(); } this.favs.Remove(fav); }