Esempio n. 1
0
        public async Task OnRecordEditConfirm()
        {
            #region 進行 Form Validation 檢查驗證作業
            if (LocalEditContext.Validate() == false)
            {
                return;
            }
            #endregion

            #region 檢查資料完整性
            if (isNewRecordMode == true)
            {
                var checkedResult = await CurrentService
                                    .BeforeAddCheckAsync(CurrentRecord);

                if (checkedResult.Success == false)
                {
                    MessageBox.Show("400px", "200px", "警告",
                                    ErrorMessageMappingHelper.Instance.GetErrorMessage(checkedResult.MessageId));
                    thisRazorComponent.NeedRefresh();
                    return;
                }
            }
            else
            {
                var checkedResult = await CurrentService
                                    .BeforeUpdateCheckAsync(CurrentRecord);

                if (checkedResult.Success == false)
                {
                    MessageBox.Show("400px", "200px", "警告",
                                    ErrorMessageMappingHelper.Instance.GetErrorMessage(checkedResult.MessageId));
                    thisRazorComponent.NeedRefresh();
                    return;
                }
            }
            #endregion

            if (IsShowEditRecord == true)
            {
                if (isNewRecordMode == true)
                {
                    await CurrentService.AddAsync(CurrentRecord);

                    dataGrid.RefreshGrid();
                }
                else
                {
                    await CurrentService.UpdateAsync(CurrentRecord);

                    dataGrid.RefreshGrid();
                }
                IsShowEditRecord = false;
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Post([FromBody] MyUserDto data)
        {
            APIResult apiResult;

            #region 驗證 DTO 物件的資料一致性
            if (!ModelState.IsValid)
            {
                apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                   ErrorMessageEnum.傳送過來的資料有問題, payload: data);
                return(Ok(apiResult));
            }
            #endregion

            MyUserAdapterModel record = mapper.Map <MyUserAdapterModel>(data);
            if (record != null)
            {
                var result = mapper.Map <MyUserDto>(record);

                #region 新增記錄前的紀錄完整性檢查
                VerifyRecordResult verify = await myUserService.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 myUserService.AddAsync(record);

                if (verifyRecordResult.Success)
                {
                    apiResult = APIResultFactory.Build(true, StatusCodes.Status200OK,
                                                       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));
        }
Esempio n. 3
0
        public async Task OnRecordEditConfirm()
        {
            #region 進行 Form Validation 檢查驗證作業
            if (LocalEditContext.Validate() == false)
            {
                return;
            }
            #endregion

            #region 檢查資料完整性
            if (isNewRecordMode == true)
            {
                if (string.IsNullOrEmpty(CurrentRecord.PasswordPlaintext))
                {
                    MessageBox.Show("400px", "200px", "警告",
                                    ErrorMessageMappingHelper.Instance.GetErrorMessage(ErrorMessageEnum.密碼不能為空白),
                                    MessageBox.HiddenAsync);
                    thisView.NeedRefresh();
                    return;
                }
                var checkedResult = await CurrentService
                                    .BeforeAddCheckAsync(CurrentRecord);

                if (checkedResult.Success == false)
                {
                    MessageBox.Show("400px", "200px", "警告",
                                    VerifyRecordResultHelper.GetMessageString(checkedResult), MessageBox.HiddenAsync);
                    thisView.NeedRefresh();
                    return;
                }
                CurrentRecord.Salt     = Guid.NewGuid().ToString();
                CurrentRecord.Password =
                    PasswordHelper.GetPasswordSHA(CurrentRecord.Salt, CurrentRecord.PasswordPlaintext);
            }
            else
            {
                var checkedResult = await CurrentService
                                    .BeforeUpdateCheckAsync(CurrentRecord);

                if (checkedResult.Success == false)
                {
                    MessageBox.Show("400px", "200px", "警告",
                                    VerifyRecordResultHelper.GetMessageString(checkedResult), MessageBox.HiddenAsync);
                    thisView.NeedRefresh();
                    return;
                }
                if (string.IsNullOrEmpty(CurrentRecord.PasswordPlaintext) == false)
                {
                    CurrentRecord.Password =
                        PasswordHelper.GetPasswordSHA(CurrentRecord.Salt, CurrentRecord.PasswordPlaintext);
                }
            }
            #endregion

            if (IsShowEditRecord == true)
            {
                if (isNewRecordMode == true)
                {
                    var verifyRecordResult = await CurrentService.AddAsync(CurrentRecord);

                    await TranscationResultHelper.CheckDatabaseResult(MessageBox, verifyRecordResult);

                    dataGrid.RefreshGrid();
                }
                else
                {
                    var verifyRecordResult = await CurrentService.UpdateAsync(CurrentRecord);

                    await TranscationResultHelper.CheckDatabaseResult(MessageBox, verifyRecordResult);

                    dataGrid.RefreshGrid();
                }
                IsShowEditRecord = false;
            }
        }