I have a table called Ad
(advertisement):
public class Ad
{
public long AdId { get; set; }
public long UserId { get; set; } // <-- this is advertiser not currentUser
public string Description { get; set; }
}
Users can add zero or more advertisements to their favourites list, so I have created another table called Favourite
:
public class Favourite
{
public long FavouriteId { get; set; }
public long AdId { get; set; }
public long UserId { get; set; }
}
And I have a table called User
:
public class User
{
public long UserId { get; set; }
public string Name { get; set; }
}
This is how I retrieve an ad, given currentUserId
and adId
:
public TEntity GetAd(long currentUser, long adId)
{
return Context.Ad
.Where(r.AdId == adId)
// include a flag indicating the pair (adId and currentUserId) exist in Favouries table
.FirstOrDefault();
}
What I want to include in the result is a flag, indicating if the ad is added to the favourites list or not?