void IListBoxController.Update(IReadOnlyList <IListItem> newList) { bool updateBegun = false; void BeginUpdate() { if (!updateBegun) { // Call ListBox's BeginUpdate/EndUpdate only when needed // tree structure changed to avoid flickering when only selection changes. listBox.BeginUpdate(); updateBegun = true; } } updating = true; try { var edits = ListEdit.GetListEdits(currentList, newList); currentList = newList; foreach (var e in edits) { switch (e.Type) { case ListEdit.EditType.Insert: BeginUpdate(); listBox.Items.Insert(e.Index, e.Item); OnUpdateRow?.Invoke(e.Item, e.Index, null); break; case ListEdit.EditType.Delete: BeginUpdate(); listBox.Items.RemoveAt(e.Index); break; case ListEdit.EditType.Reuse: listBox.Items[e.Index] = e.Item; OnUpdateRow?.Invoke(e.Item, e.Index, e.OldItem); break; case ListEdit.EditType.Select: listBox.SelectedIndices.Add(e.Index); break; case ListEdit.EditType.Deselect: listBox.SelectedIndices.Remove(e.Index); break; } } } finally { if (updateBegun) { listBox.EndUpdate(); } updating = false; } }
void UpdateStructure(IReadOnlyList <Item> newList) { var edits = ListEdit.GetListEdits(items, newList); items = newList; var columns = tableView.TableColumns(); NSIndexSet allColumnsSet = null; foreach (var e in edits) { switch (e.Type) { case ListEdit.EditType.Insert: using (var set = new NSIndexSet(e.Index)) tableView.InsertRows(set, NSTableViewAnimation.None); break; case ListEdit.EditType.Delete: using (var set = new NSIndexSet(e.Index)) tableView.RemoveRows(set, NSTableViewAnimation.None); break; case ListEdit.EditType.Reuse: if (owner.OnUpdateView != null && owner.OnCreateView != null) { for (int col = 0; col < columns.Length; ++col) { var existingView = tableView.GetView(col, e.Index, makeIfNecessary: false); if (existingView != null) { owner.OnUpdateView((Item)e.Item, columns[col], existingView, (Item)e.OldItem); } } } else { if (allColumnsSet == null) { allColumnsSet = NSIndexSet.FromArray(Enumerable.Range(0, columns.Length).ToArray()); } using (var set = new NSIndexSet(e.Index)) tableView.ReloadData(set, allColumnsSet); } break; } } allColumnsSet?.Dispose(); }
public IHttpActionResult Put(ListEdit movieList) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateMovieListService(); if (!service.UpdateMovieOnList(movieList)) { return(InternalServerError()); } return(Ok()); }
public bool UpdateMovieOnList(ListEdit model) { using (var movieList = new ApplicationDbContext()) { var entity = movieList .MovieOnLists .Single(e => e.ListId == model.ListId && e.MyMoviesCollection.User.OwnerId == _ownerId); entity.MovieId = model.MovieId; entity.CollectionId = model.CollectionId; entity.Comment = model.Comment; return(movieList.SaveChanges() == 1); } }