/// <summary> /// 更新排序 /// </summary> /// <param name="items"></param> private void UpdateSort(ItemCollection items) { foreach (var i in items) { var item = (TreeViewItem)i; var model = (TopMenus)item.DataContext; if (model.DisplayName == Config.RootDisplayName) { continue; } var requestModel = new TopMenusUpdateSortRequestModel { DisplayName = model.DisplayName, Sort = model.Sort, Timestamp = _topMenusManage.ServerTime.ToUnixTimestamp() }; var result = _topMenusManage.UpdateSort(model.Id, model.Timestamp, requestModel); if (result.ResultStatus == ResultStatus.Success) { model.Timestamp = result.Data.Timestamp; } else { _metroWindow.ShowMessageAsync("更新节点排序失败", result.Message); } if (item.HasItems) { UpdateSort(item.Items); } } }
public CommandResult <TopMenus> UpdateSort(int topMenuId, long timestamp, TopMenusUpdateSortRequestModel requestModel) { var result = new CommandResult <TopMenus>(); if (!Exist(a => a.Id == topMenuId)) { result.Message = $"节点名称“{requestModel.DisplayName}”在系统中已不存在"; } else if (!Exist(a => a.Id == topMenuId && a.Timestamp == timestamp)) { result.Message = $"节点名称为“{requestModel.DisplayName}”的节点排序已在别处被修改"; } else { using (var db = new FrameContext()) { var entity = BaseService.Find(db, a => a.Id == topMenuId); entity.Sort = requestModel.Sort; entity.Timestamp = requestModel.Timestamp; if (!BaseService.Update(db, entity)) { result.Message = "系统出现未知原因,节点排序更新失败!"; } else { result.ResultStatus = ResultStatus.Success; result.Message = "节点排序更新成功"; result.Data = entity; } } } return(result); }
private void AddTreeViewItem(TreeView treeView, ItemCollection items, TreeViewItem selectedItem, TopMenus topMenus) { if (topMenus.ParentId == 0) { treeView.Items.Add(GenerateTreeViewItem(selectedItem)); selectedItem.IsSelected = true; return; } foreach (var i in items) { var item = (TreeViewItem)i; if (((TopMenus)item.DataContext).Id == topMenus.ParentId) { item.Items.Add(GenerateTreeViewItem(selectedItem)); selectedItem.IsSelected = true; item.IsExpanded = true; var requestModel = new TopMenusUpdateSortRequestModel { DisplayName = topMenus.DisplayName, Sort = int.MaxValue, Timestamp = _topMenusManage.ServerTime.ToUnixTimestamp() }; var result = _topMenusManage.UpdateSort(topMenus.Id, Timestamp, requestModel); if (result.ResultStatus == ResultStatus.Success) { topMenus.DisplayName = result.Data.DisplayName; topMenus.Sort = result.Data.Sort; topMenus.Timestamp = result.Data.Timestamp; } else { _metroWindow.ShowMessageAsync("更新节点排序失败", result.Message); } break; } if (item.HasItems) { AddTreeViewItem(treeView, item.Items, selectedItem, topMenus); } } }