asp.net - setting content to be viewable by friends only -


Say I have a table that contains the content:

Contents (Content ID, title, body, Privacy type)

The type of privacy can be:

public = 1 (anyone can see it) Private = 2 (only the author can see it) friend = 3 (only friends see it

User (User ID, Username)

I have a Mapping Table for User Management:

I have a User T

Friends (User ID, Mediade)

Now when I list all the content, should list the content that is either public or I'm the friend of that user (user for login)

How do I do a query for this?

Provide a field where the content author is stored, so I think that it is Content.author :

  Select WHERE public from public = 1 or (public = 3 and current (SELECT NULL FRO M friends WHERE userId = @ me AND friendID = content.author) )  

, or better than:

  Select from content WHERE public = 1 union Select all * Content from where public = 3 and current ( SELECT NULL with friends where users If your  author  field is selective and is cheaper than sorting filtering. 

Also keep in mind that if you have a similar relation (i.e. if there is a friend for any userA userB , then < Code> userB is a friend for userA ), it is better stored in a table like this:

  userA userB  

with a check barrier:

  userA < User B  

The UI always puts the user at least before id .

In this case, like your query:

  Select from content where public = 1 union select all * Content from where public = 3 and current ( Choose from friends, where user = @ m and user b = content. Select author union from all friends where userb = = m and user A = content. Author)  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -