Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sounds more like an architectural challenge to me.</p> <p>I recommend using a <a href="http://msdn.microsoft.com/en-us/library/7977ey2c.aspx" rel="nofollow">Queue</a>. This is a collection type following a <a href="http://en.wikipedia.org/wiki/FIFO" rel="nofollow">first-in, first-out</a> (FIFO) approach. You put objects into the queue and get them back out <strong>in the same order</strong>. An object that was received out of this queue is automatically is removed from the queue, so you can be sure that you do not handle the same element twice.</p> <p>Your described workflow then would work as these simple steps:</p> <ol> <li>Whenever a message arrives, you put the object <a href="http://msdn.microsoft.com/en-us/library/t249c2y7.aspx" rel="nofollow">into your queue</a>.</li> <li>When the admin clicks on the <code>next button</code>, you request the first object <a href="http://msdn.microsoft.com/en-us/library/1c8bzx97.aspx" rel="nofollow">out of the queue</a>.</li> <li>Your admin does his administrative tasks and approves the message.</li> <li>Clicking on <code>Next</code> start with above item 1 again.</li> </ol> <p><strong>[EDIT]</strong></p> <p>Oops, I realized that my <code>Queue</code> approach would not allow for navigating back to previous items.</p> <p>In this case I suggest using a simple <code>List</code> collection. This list can be accessed via the 0-based position in the list. This makes it easy to implement a forward/ backward navigation.</p> <p>For my sample code, please bear in mind that there is a lot that I cannot know about your environment, so my code make a lot assumptions here.</p> <p>You need to somwhere store a collection that contains your messages to be approved:</p> <pre><code>private IList&lt;videomessage&gt; _messagesToApprove = new List&lt;videomessage&gt;(); </code></pre> <p>You will also need some variable that keeps track of the current position in your collection:</p> <pre><code>// Store the index of the current message // Initial value depends on your environment. :-) private int _currentIndex = 0; </code></pre> <p>To begin with, you will need a starting point where new messages are added to that collection, like subscribing to some event or so. Whenever a message arrives, add it to the collection by calling a method like:</p> <pre><code>// I made this method up because I do not know where your messages really come from. // =&gt; ADJUST TO YOUR NEEDS. private void onNewMessageArriving(string messageId) { videomessage arrivingMessage = new videomessage(messageId); _messagesToApprove.Add(arrivingMessage); } </code></pre> <p>The you can easily implement the navigation by incrementing/ decrementing the position index:</p> <pre><code>private void previous_Click(object sender, EventArgs e) { // Check that we do not go back further than the beginning of the list if ((_currentIndex - 1) &gt;= 0) { _currentIndex--; this.currentMessage = this._messagesToApprove[_currentIndex]; } else { // Do nothing if the position would be invalid return; } } private void next_Click(object sender, EventArgs e) { // Check if we have new messages to approve in our list. if ((_currentIndex + 1) &lt; _messagesToApprove.Count) { _currentIndex++; currentMessage = _messagesToApprove[_currentIndex]; } else { // Do nothing if the position would be invalid return; } } private void approve_Click(object sender, EventArgs e) { // Sorry, I don't know where exactly this comes from, needs to be adjusted to your environment status.SelectedValue = "1"; this.currentMessage.status = "1"; this.currentMessage.Save(); // If you want to remove items that have been checked by the admin, delete it from the approval list. // Otherwise remove this line :-) this._messagesToApprove.RemoveAt(_currentIndex); } private void remove_Click(object sender, EventArgs e) { // Sorry, I don't know where exactly this comes from, needs to be adjusted to your environment status.SelectedValue = "2"; this.currentMessage.status = "2"; this.currentMessage.Save(); // If you want to remove items that have been checked by the admin, delete it from the approval list. // Otherwise remove this line :-) this._messagesToApprove.RemoveAt(_currentIndex); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload