public async Task <VerifyRecordResult> BeforeUpdateCheckAsync(MenuDataAdapterModel paraObject) { CleanTrackingHelper.Clean <MenuData>(context); var searchItem = await context.MenuData .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == paraObject.Id); if (searchItem == null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.要更新的紀錄_發生同時存取衝突_已經不存在資料庫上)); } if (paraObject.MenuRoleId == 0) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.尚未輸入功能表的角色)); } var item = await context.MenuData .AsNoTracking() .FirstOrDefaultAsync(x => x.MenuRoleId == paraObject.MenuRoleId && x.Name == paraObject.Name && x.Id != paraObject.Id); if (item != null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.該功能項目已經存在該功能表的角色)); } return(VerifyRecordResultFactory.Build(true)); }
public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) { if (args.Item.Id == ButtonIdHelper.ButtonIdAdd) { CurrentRecord = new MenuDataAdapterModel(); #region 針對新增的紀錄所要做的初始值設定商業邏輯 CurrentRecord.ForceLoad = false; #endregion EditRecordDialogTitle = "新增紀錄"; isNewRecordMode = true; IsShowEditRecord = true; CurrentRecord.MenuRoleId = Header.Id; //CurrentRecord.Name = Header.Title; } else if (args.Item.Id == ButtonIdHelper.ButtonIdRefresh) { dataGrid.RefreshGrid(); } else if (args.Item.Id == ButtonIdHelper.ButtonIdReOrder) { await CurrentService.ReorderByHeaderIDAsync(Header.Id); dataGrid.RefreshGrid(); } }
public async Task <VerifyRecordResult> UpdateAsync(MenuDataAdapterModel paraObject) { try { MenuData itemData = Mapper.Map <MenuData>(paraObject); CleanTrackingHelper.Clean <MenuData>(context); MenuData item = await context.MenuData .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == paraObject.Id); if (item == null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法修改紀錄)); } else { CleanTrackingHelper.Clean <MenuData>(context); context.Entry(itemData).State = EntityState.Modified; await context.SaveChangesAsync(); CleanTrackingHelper.Clean <MenuData>(context); return(VerifyRecordResultFactory.Build(true)); } } catch (Exception ex) { Logger.LogError(ex, "修改記錄發生例外異常"); return(VerifyRecordResultFactory.Build(false, "修改記錄發生例外異常", ex)); } }
public async Task OnCommandClicked(CommandClickEventArgs <MenuDataAdapterModel> args) { MenuDataAdapterModel item = args.RowData as MenuDataAdapterModel; if (args.CommandColumn.ButtonOption.IconCss == ButtonIdHelper.ButtonIdEdit) { #region 點選 修改紀錄 按鈕 CurrentRecord = item.Clone(); EditRecordDialogTitle = "修改紀錄"; IsShowEditRecord = true; isNewRecordMode = false; #endregion } else if (args.CommandColumn.ButtonOption.IconCss == ButtonIdHelper.ButtonIdDelete) { #region 點選 刪除紀錄 按鈕 CurrentNeedDeleteRecord = item; #region 檢查關聯資料是否存在 var checkedResult = await CurrentService .BeforeDeleteCheckAsync(CurrentNeedDeleteRecord); await Task.Delay(100); if (checkedResult.Success == false) { MessageBox.Show("400px", "200px", "警告", ErrorMessageMappingHelper.Instance.GetErrorMessage(checkedResult.MessageId), MessageBox.HiddenAsync); await Task.Yield(); await thisView.NeedRefreshAsync(); return; } #endregion #region 刪除這筆紀錄 await Task.Yield(); var checkTask = ConfirmMessageBox.ShowAsync("400px", "200px", "警告", "確認要刪除這筆紀錄嗎?", ConfirmMessageBox.HiddenAsync); await thisView.NeedRefreshAsync(); var checkAgain = await checkTask; if (checkAgain == true) { var verifyRecordResult = await CurrentService.DeleteAsync(CurrentNeedDeleteRecord.Id); await TranscationResultHelper.CheckDatabaseResult(MessageBox, verifyRecordResult); dataGrid.RefreshGrid(); } #endregion #endregion } }
public async Task <VerifyRecordResult> BeforeDeleteCheckAsync(MenuDataAdapterModel paraObject) { var searchItem = await context.MenuData .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == paraObject.Id); if (searchItem == null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法刪除紀錄_要刪除的紀錄已經不存在資料庫上)); } return(VerifyRecordResultFactory.Build(true)); }
public async Task <MenuDataAdapterModel> GetAsync(int id) { MenuData item = await context.MenuData .AsNoTracking() .Include(x => x.MenuRole) .FirstOrDefaultAsync(x => x.Id == id); MenuDataAdapterModel result = Mapper.Map <MenuDataAdapterModel>(item); await OhterDependencyData(result); return(result); }
Task OhterDependencyData(MenuDataAdapterModel data) { if (data.IsGroup == true) { data.IsGroupName = "是"; } else { data.IsGroupName = "否"; } if (data.Enable == true) { data.EnableName = "是"; } else { data.EnableName = "否"; } return(Task.FromResult(0)); }
public async Task <VerifyRecordResult> AddAsync(MenuDataAdapterModel paraObject) { try { MenuData itemParameter = Mapper.Map <MenuData>(paraObject); CleanTrackingHelper.Clean <MenuData>(context); await context.MenuData .AddAsync(itemParameter); await context.SaveChangesAsync(); CleanTrackingHelper.Clean <MenuData>(context); return(VerifyRecordResultFactory.Build(true)); } catch (Exception ex) { Logger.LogError(ex, "新增記錄發生例外異常"); return(VerifyRecordResultFactory.Build(false, "新增記錄發生例外異常", ex)); } }
public async Task EnableIt(MenuDataAdapterModel paraObject) { MenuData itemData = Mapper.Map <MenuData>(paraObject); CleanTrackingHelper.Clean <MenuData>(context); MenuData item = await context.MenuData .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == paraObject.Id); if (item == null) { } else { item.Enable = true; context.Entry(item).State = EntityState.Modified; await context.SaveChangesAsync(); CleanTrackingHelper.Clean <MenuData>(context); } }
public async Task OnCommandClicked(CommandClickEventArgs <MenuDataAdapterModel> args) { MenuDataAdapterModel item = args.RowData as MenuDataAdapterModel; if (args.CommandColumn.ButtonOption.IconCss == ButtonIdHelper.ButtonIdEdit) { #region 點選 修改紀錄 按鈕 CurrentRecord = item.Clone(); EditRecordDialogTitle = "修改紀錄"; IsShowEditRecord = true; isNewRecordMode = false; #endregion } else if (args.CommandColumn.ButtonOption.IconCss == ButtonIdHelper.ButtonIdDelete) { #region 點選 刪除紀錄 按鈕 CurrentNeedDeleteRecord = item; #region 檢查關聯資料是否存在 var checkedResult = await CurrentService .BeforeDeleteCheckAsync(CurrentNeedDeleteRecord); await Task.Delay(100); if (checkedResult.Success == false) { MessageBox.Show("400px", "200px", "警告", ErrorMessageMappingHelper.Instance.GetErrorMessage(checkedResult.MessageId)); await Task.Yield(); thisView.NeedRefresh(); return; } #endregion ConfirmMessageBox.Show("400px", "200px", "警告", "確認要刪除這筆紀錄嗎?"); #endregion } }
public async Task EnableIt(MenuDataAdapterModel item) { await CurrentService.EnableIt(item); dataGrid.RefreshGrid(); }