private void HandleCommandArgs(CommandEventArgs args) { switch (args.CommandName.ToLowerInvariant()) { case "cancel": ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = DefaultMode }).GetAwaiter().GetResult(); CurrentMode = DefaultMode; break; case "edit": ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = FormViewMode.Edit }).GetAwaiter().GetResult(); CurrentMode = FormViewMode.Edit; break; case "delete": Exception caughtException = null; try { OnItemDeleting.InvokeAsync(new FormViewDeleteEventArgs(Position)).GetAwaiter().GetResult(); } catch (Exception ex) { caughtException = ex; } // do we do the deletion? OnItemDeleted.InvokeAsync(new FormViewDeletedEventArgs(Position, caughtException)).GetAwaiter().GetResult(); CurrentMode = DefaultMode; Position = (Position == 0) ? 0 : Position - 1; break; case "insert": OnItemInserting.InvokeAsync(new FormViewInsertEventArgs("insert") { }).GetAwaiter().GetResult(); ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = FormViewMode.Insert }).GetAwaiter().GetResult(); OnItemInserted.InvokeAsync(new FormViewInsertEventArgs("insert") { }).GetAwaiter().GetResult(); CurrentMode = FormViewMode.Insert; break; case "update": OnItemUpdating.InvokeAsync(new FormViewUpdateEventArgs("update")).GetAwaiter().GetResult(); ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = DefaultMode }).GetAwaiter().GetResult(); OnItemUpdated.InvokeAsync(new FormViewUpdatedEventArgs(0, null)).GetAwaiter().GetResult(); CurrentMode = DefaultMode; break; } StateHasChanged(); }
public void Insert(int index, T item) { OnItemInserted?.Invoke(this, new ListEventArgs("ItemInserted event fired.", _list.Count)); _list.Insert(index, item); }