#region 刪除 /// <summary> /// 刪除 /// </summary> /// <param name="inputViewModel">刪除參數</param> /// <returns></returns> public ReturnedDataResult Delete(InputViewModel<int> inputViewModel) { if (inputViewModel == null) { return new ReturnedDataResult() { Status = ReturnedStatus.Error, Message = ResourceHelper.GetResourceValue("Common", "Common", "zh_cn", "DeleteFailByInputViewIsNull", "刪除失敗,失敗緣由:刪除條件爲空!") }; } var moduleList = _sysModuleRepository.GetList(); var idList = GetMenuIdList(inputViewModel.InputView, moduleList); idList.Add(inputViewModel.InputView); _sysModuleRepository.Delete(idList); return new ReturnedDataResult() { Data = new List<int> { inputViewModel.InputView }, Status = ReturnedStatus.Success, Message = ResourceHelper.GetResourceValue("Common", "Common", inputViewModel.Language, "DeleteSuccess", "刪除成功!") }; } #endregion
#region 獲取刪除菜單的ID集合 /// <summary> /// 獲取刪除菜單的ID集合 /// </summary> /// <param name="parentId"></param> /// <param name="modules"></param> /// <returns></returns> private static List<int> GetMenuIdList(int parentId, List<Sys_Module> modules) { List<int> idlist = new List<int>(); var ids = modules.Where(s => s.ParentId == parentId).Select(s => s.Id).ToList(); foreach (var id in ids) { idlist.Add(id); List<int> childList = GetMenuIdList(id, modules); idlist.AddRange(childList); } return idlist; } #endregion