/// <summary> /// Handles the ItemReorder event of the Items control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Items_ItemReorder(object sender, EventArgs e) { ImageButton theButton = sender as ImageButton; Query query = new Query(Store.Image.Schema).WHERE(Store.Image.Columns.ProductId, productId).ORDER_BY(Store.Image.Columns.SortOrder); Store.ImageCollection imageCollection = new Store.ImageController().FetchByQuery(query); if (imageCollection != null) { int imageId = 0; int.TryParse(theButton.CommandArgument, out imageId); if (imageId > 0) { Store.Image imageMoved = imageCollection.Find(delegate(Store.Image image) { return(image.ImageId == imageId); }); int index = imageCollection.IndexOf(imageMoved); imageCollection.RemoveAt(index); if (theButton.CommandName.ToLower() == "up") { imageCollection.Insert(index - 1, imageMoved); } else if (theButton.CommandName.ToLower() == "down") { imageCollection.Insert(index + 1, imageMoved); } int i = 1; foreach (Store.Image image in imageCollection) { image.SortOrder = i++; } imageCollection.SaveAll(WebUtility.GetUserName()); LoadProductImages(); } } }
/// <summary> /// Handles the ItemReorder event of the Items control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Items_ItemReorder(object sender, EventArgs e) { ImageButton theButton = sender as ImageButton; Query query = new Query(Store.Image.Schema).WHERE(Store.Image.Columns.ProductId, productId).ORDER_BY(Store.Image.Columns.SortOrder); Store.ImageCollection imageCollection = new Store.ImageController().FetchByQuery(query); if (imageCollection != null) { int imageId = 0; int.TryParse(theButton.CommandArgument, out imageId); if (imageId > 0) { Store.Image imageMoved = imageCollection.Find(delegate(Store.Image image) { return image.ImageId == imageId; }); int index = imageCollection.IndexOf(imageMoved); imageCollection.RemoveAt(index); if (theButton.CommandName.ToLower() == "up") { imageCollection.Insert(index - 1, imageMoved); } else if (theButton.CommandName.ToLower() == "down") { imageCollection.Insert(index + 1, imageMoved); } int i = 1; foreach (Store.Image image in imageCollection) { image.SortOrder = i++; } imageCollection.SaveAll(WebUtility.GetUserName()); LoadProductImages(); } } }