public async Task OnCommandClicked(CommandClickEventArgs <ProductAdapterModel> args) { ProductAdapterModel item = args.RowData as ProductAdapterModel; if (args.CommandColumn.ButtonOption.IconCss == ButtonIdHelper.ButtonIdEdit) { CurrentRecord = item.Clone(); EditRecordDialogTitle = "修改紀錄"; IsShowEditRecord = true; isNewRecordMode = false; } else if (args.CommandColumn.ButtonOption.IconCss == ButtonIdHelper.ButtonIdDelete) { 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(); thisRazorComponent.NeedRefresh(); return; } #endregion ConfirmMessageBox.Show("400px", "200px", "警告", "確認要刪除這筆紀錄嗎?"); } }
public async Task <VerifyRecordResult> UpdateAsync(ProductAdapterModel paraObject) { try { Product itemData = Mapper.Map <Product>(paraObject); CleanTrackingHelper.Clean <Product>(context); Product item = await context.Product .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == paraObject.Id); if (item == null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法修改紀錄)); } else { CleanTrackingHelper.Clean <Product>(context); context.Entry(itemData).State = EntityState.Modified; await context.SaveChangesAsync(); CleanTrackingHelper.Clean <Product>(context); return(VerifyRecordResultFactory.Build(true)); } } catch (Exception ex) { Logger.LogError(ex, "修改記錄發生例外異常"); return(VerifyRecordResultFactory.Build(false, "修改記錄發生例外異常", ex)); } }
public void OnPickerCompletion(ProductAdapterModel e) { if (e != null) { CurrentRecord.ProductId = e.ProductId; CurrentRecord.ProductName = e.Name; } ShowAontherRecordPicker = false; }
public async Task OnCommandClicked(CommandClickEventArgs <ProductAdapterModel> args) { ProductAdapterModel item = args.RowData as ProductAdapterModel; 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(); thisView.NeedRefresh(); return; } #endregion #region 刪除這筆紀錄 await Task.Yield(); var checkTask = ConfirmMessageBox.ShowAsync("400px", "200px", "警告", "確認要刪除這筆紀錄嗎?", ConfirmMessageBox.HiddenAsync); thisView.NeedRefresh(); 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> BeforeAddCheckAsync(ProductAdapterModel paraObject) { var searchItem = await context.Product .AsNoTracking() .FirstOrDefaultAsync(x => x.Name == paraObject.Name); if (searchItem != null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.要新增的紀錄已經存在無法新增)); } return(VerifyRecordResultFactory.Build(true)); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] ProductDto data) { APIResult apiResult; #region 驗證 DTO 物件的資料一致性 if (!ModelState.IsValid) { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, ErrorMessageEnum.傳送過來的資料有問題, payload: data); return(Ok(apiResult)); } #endregion var record = await ProductService.GetAsync(id); if (record != null && record.Id != 0) { ProductAdapterModel recordTarget = mapper.Map <ProductAdapterModel>(data); recordTarget.Id = id; var result = mapper.Map <ProductDto>(recordTarget); #region 修改記錄前的紀錄完整性檢查 VerifyRecordResult verify = await ProductService.BeforeUpdateCheckAsync(record); if (verify.Success == false) { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, ErrorMessageMappingHelper.Instance.GetErrorMessage(verify.MessageId), payload: result); return(Ok(apiResult)); } #endregion var verifyRecordResult = await ProductService.UpdateAsync(recordTarget); if (verifyRecordResult.Success) { apiResult = APIResultFactory.Build(true, StatusCodes.Status202Accepted, ErrorMessageEnum.None, payload: null); } else { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, verifyRecordResult.MessageId, payload: result); } } else { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, ErrorMessageEnum.沒有任何符合資料存在, payload: data); } return(Ok(apiResult)); }
public async Task <ProductAdapterModel> GetAsync(int id) { Product item = await context.Product .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == id); ProductAdapterModel result = Mapper.Map <ProductAdapterModel>(item); await OhterDependencyData(result); return(result); }
public async Task <VerifyRecordResult> BeforeDeleteCheckAsync(ProductAdapterModel paraObject) { CleanTrackingHelper.Clean <OrderItem>(context); OrderItem item = await context.OrderItem .AsNoTracking() .FirstOrDefaultAsync(x => x.ProductId == paraObject.Id); if (item != null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.該紀錄無法刪除因為有其他資料表在使用中)); } return(VerifyRecordResultFactory.Build(true)); }
public async Task <VerifyRecordResult> AddAsync(ProductAdapterModel paraObject) { Product itemParameter = Mapper.Map <Product>(paraObject); CleanTrackingHelper.Clean <Product>(context); await context.Product .AddAsync(itemParameter); await context.SaveChangesAsync(); CleanTrackingHelper.Clean <Product>(context); return(VerifyRecordResultFactory.Build(true)); }
public void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) { if (args.Item.Text == "新增") { CurrentRecord = new ProductAdapterModel(); EditRecordDialogTitle = "新增紀錄"; isNewRecordMode = true; IsShowEditRecord = true; } else if (args.Item.Text == "重新整理") { dataGrid.RefreshGrid(); } }
public async Task <IActionResult> Post([FromBody] ProductDto data) { APIResult apiResult; #region 驗證 DTO 物件的資料一致性 if (!ModelState.IsValid) { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, ErrorMessageEnum.傳送過來的資料有問題, payload: null); return(Ok(apiResult)); } #endregion ProductAdapterModel record = mapper.Map <ProductAdapterModel>(data); if (record != null) { var result = mapper.Map <ProductDto>(record); #region 新增記錄前的紀錄完整性檢查 VerifyRecordResult verify = await ProductService.BeforeAddCheckAsync(record); if (verify.Success == false) { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, ErrorMessageMappingHelper.Instance.GetErrorMessage(verify.MessageId), payload: result); return(Ok(apiResult)); } #endregion var verifyRecordResult = await ProductService.AddAsync(record); if (verifyRecordResult.Success) { apiResult = APIResultFactory.Build(true, StatusCodes.Status201Created, ErrorMessageEnum.None, payload: result); } else { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, verifyRecordResult.MessageId, payload: result); } } else { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, ErrorMessageEnum.傳送過來的資料有問題, payload: data); } return(Ok(apiResult)); }
public void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) { if (args.Item.Id == ButtonIdHelper.ButtonIdAdd) { CurrentRecord = new ProductAdapterModel(); #region 針對新增的紀錄所要做的初始值設定商業邏輯 #endregion EditRecordDialogTitle = "新增紀錄"; isNewRecordMode = true; IsShowEditRecord = true; } else if (args.Item.Id == ButtonIdHelper.ButtonIdRefresh) { dataGrid.RefreshGrid(); } }
public void OnCommandClicked(CommandClickEventArgs <ProductAdapterModel> args) { ProductAdapterModel item = args.RowData as ProductAdapterModel; if (args.CommandColumn.ButtonOption.Content == "修改") { CurrentRecord = item; EditRecordDialogTitle = "修改紀錄"; IsShowEditRecord = true; isNewRecordMode = false; } else if (args.CommandColumn.ButtonOption.Content == "刪除") { #region 檢查關聯資料是否存在 #endregion CurrentNeedDeleteRecord = item; ConfirmMessageBox.Show("400px", "200px", "警告", "確認要刪除這筆紀錄嗎?"); } }
public async Task <VerifyRecordResult> AddAsync(ProductAdapterModel paraObject) { try { Product itemParameter = Mapper.Map <Product>(paraObject); CleanTrackingHelper.Clean <Product>(context); await context.Product .AddAsync(itemParameter); await context.SaveChangesAsync(); CleanTrackingHelper.Clean <Product>(context); return(VerifyRecordResultFactory.Build(true)); } catch (Exception ex) { Logger.LogError(ex, "新增記錄發生例外異常"); return(VerifyRecordResultFactory.Build(false, "新增記錄發生例外異常", ex)); } }
public async Task <VerifyRecordResult> BeforeUpdateCheckAsync(ProductAdapterModel paraObject) { var searchItem = await context.Product .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == paraObject.Id); if (searchItem == null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.要更新的紀錄_發生同時存取衝突_已經不存在資料庫上)); } searchItem = await context.Product .AsNoTracking() .FirstOrDefaultAsync(x => x.Name == paraObject.Name && x.Id != paraObject.Id); if (searchItem != null) { return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.要修改的紀錄已經存在無法修改)); } return(VerifyRecordResultFactory.Build(true)); }
Task OhterDependencyData(ProductAdapterModel data) { return(Task.FromResult(0)); }