public void AddUserFavroutieProperty(string userId, long listingKey) { if (string.IsNullOrWhiteSpace(userId)) throw new ParamMissingException("User Id cannot be empty."); FavouriteProperty favProperty = Repository.Single<FavouriteProperty>( x => x.ListingKey == listingKey && x.UserId.Equals(userId)); if (favProperty != null) { if (favProperty.Deleted) favProperty.Deleted = false; Repository.Save(); } else { User user = Repository.Single<User>(x => x.UserId.Equals(userId) && x.Deleted != true); if (user == null) throw new InvalidValueException("The user Id provided is invalid."); Property property = Repository.Single<Property>( x => x.ListingKey == listingKey); if (property == null) throw new InvalidValueException("The property Id provided is invalid."); favProperty = new FavouriteProperty { ListingKey = listingKey, UserId = userId, }; Repository.Add<FavouriteProperty>(favProperty); Repository.Save(); } }
public FavouriteProperty addFavoriteProperty(long listingKey, string userId) { User user = Repository.Single<User>(x => x.UserId.Equals(userId) && x.Deleted != true); if (user == null) throw new InvalidValueException("No user with specified ID found."); Property property = this.GetProperty(listingKey); if (property == null) throw new InvalidValueException("No property with specified ID found."); FavouriteProperty favProperty = this.GetFavouriteProperty(listingKey, userId); // if property is already favorited if (favProperty != null) return favProperty; else { FavouriteProperty newFavoriteProperty = new FavouriteProperty(); newFavoriteProperty.ListingKey = listingKey; newFavoriteProperty.UserId = userId; newFavoriteProperty.Deleted = false; Repository.Add<FavouriteProperty>(newFavoriteProperty); Repository.Save(); return newFavoriteProperty; } }