Ejemplo n.º 1
0
        public async Task OnCommandClicked(CommandClickEventArgs <TravelExpenseAdapterModel> args)
        {
            TravelExpenseAdapterModel item = args.RowData as TravelExpenseAdapterModel;

            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", "警告", "確認要刪除這筆紀錄嗎?");
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Delete([FromRoute] int id)
        {
            APIResult apiResult;
            var       record = await TravelExpenseService.GetAsync(id);

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

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

                if (verifyRecordResult.Success)
                {
                    apiResult = APIResultFactory.Build(true, StatusCodes.Status202Accepted,
                                                       ErrorMessageEnum.None, payload: null);
                }
                else
                {
                    apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                       ErrorMessageEnum.無法刪除紀錄, payload: result);
                }
            }
            else
            {
                apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                   ErrorMessageEnum.沒有任何符合資料存在, payload: result);
            }
            return(Ok(apiResult));
        }