Esempio n. 1
0
        public async Task <IActionResult> Delete([FromRoute] int id)
        {
            APIResult apiResult;
            var       record = await OrderService.GetAsync(id);

            var result = mapper.Map <OrderMasterDto>(record);

            if (record != null && record.Id != 0)
            {
                #region 刪除記錄前的紀錄完整性檢查
                VerifyRecordResult verify = await OrderService.BeforeDeleteCheckAsync(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 OrderService.DeleteAsync(id);

                if (verifyRecordResult.Success)
                {
                    apiResult = APIResultFactory.Build(true, StatusCodes.Status202Accepted,
                                                       ErrorMessageEnum.None, payload: null);
                }
                else
                {
                    if (verifyRecordResult.MessageId == ErrorMessageEnum.客製化文字錯誤訊息)
                    {
                        if (verifyRecordResult.Exception == null)
                        {
                            apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                               verifyRecordResult.Message, payload: result);
                        }
                        else
                        {
                            apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                               verifyRecordResult.Message, payload: result,
                                                               exceptionMessage: verifyRecordResult.Exception.Message,
                                                               replaceExceptionMessage: true);
                        }
                    }
                    else
                    {
                        apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                           verifyRecordResult.MessageId, payload: result);
                    }
                }
            }
            else
            {
                apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                   ErrorMessageEnum.沒有任何符合資料存在, payload: result);
            }
            return(Ok(apiResult));
        }
Esempio n. 2
0
        public async Task OnCommandClicked(CommandClickEventArgs <OrderMasterAdapterModel> args)
        {
            OrderMasterAdapterModel item = args.RowData as OrderMasterAdapterModel;

            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
            }
            else if (args.CommandColumn.ButtonOption.IconCss == ButtonIdHelper.ButtonIdShowDetailOfMaster)
            {
                #region 點選 開啟多筆 CRUD 對話窗 按鈕
                IsShowMoreDetailsRecord          = true;
                ShowMoreDetailsRecordDialogTitle = MagicHelper.訂單明細管理功能名稱;
                MasterRecord masterRecord = new MasterRecord()
                {
                    Id = item.Id
                };
                Header = masterRecord;
                if (ShowMoreDetailsGrid != null)
                {
                    await Task.Delay(100); // 使用延遲,讓 Header 的資料綁定可以成功

                    ShowMoreDetailsGrid.RefreshGrid();
                }
                #endregion
            }
        }