[RESOLVED]Order of an image

Hi, in my database i create a table where i held the infos of my pictures… and also the order in number format…

After i order them by my order field.. till here all ok…

the problem is that at the moment i need to fill my order field with a number, but what i would love to do is the following :

In my list of pictures i would love to show 2 link : UP and DOW

If i click on up i would love to give to that picture the order of the upper picture and the upper picture to take the other order, in this way i can put up my picture…

So if i have :

1 –> AAAA (Up / Down)

2–> BBBB (Up / Down)

3–> CCCC (Up / Down)

4–> DDDD (Up / Down)

If i click on UP for the picture CCCC i should have :

1 –> AAAA (Up / Down)

2–> CCCC (Up / Down)

3–> BBBB (Up / Down)

4–> DDDD (Up / Down)

The problem is also for the first and the last picture, that they :

can’t go up for the first

can’t go down for the last

I hope i well explain what i would love to do…

How to do?

Hi grafic,

For this requirement, please follow up these steps below:

  1. Create an action method to update the order number.
    public ActionResult Index(int id, bool isUp)
    {
       //TODO retrieve current entity
       //TODO Validate order number (first, last)
       //Base on the order number retrieve privious/next entity
       //TODO 
    }
  2. Base on the order number to get the previous or next record. (Using ElementAt method)
  3. Update current entity with previous/next record order number and update previous entity with current entity’s order number.

For the first entity, you just need to check the order number. If the value of order number is 1, then it means that record is the first one.

For the last entity, you need to check all record count, if the order number equals to all record count, it means that record is the last one.

Best Regards

Starain Chen

Hi, sorry to bother.. can i have i bit more of code… because i never done this…

Thanks

Hi grafic,

Since I don’t have your project, I think you need to do it by yourself.

If you have any questions about these steps, you could post it here.

Best Regards

Starain Chen

Leave a Reply