示例#1
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] LeaveFormDto data)
        {
            APIResult apiResult;

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

            var record = await LeaveFormService.GetAsync(id);

            if (record != null)
            {
                LeaveFormAdapterModel recordTarget = mapper.Map <LeaveFormAdapterModel>(data);
                recordTarget.Id = id;
                var result = mapper.Map <LeaveFormDto>(recordTarget);

                #region 修改記錄前的紀錄完整性檢查
                VerifyRecordResult verify = await LeaveFormService.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 LeaveFormService.UpdateAsync(recordTarget);

                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: data);
            }
            return(Ok(apiResult));
        }
示例#2
0
        public async Task <IActionResult> Post([FromBody] LeaveFormDto data)
        {
            APIResult apiResult;

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

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

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

                if (verifyRecordResult.Success)
                {
                    apiResult = APIResultFactory.Build(true, StatusCodes.Status201Created,
                                                       ErrorMessageEnum.None, payload: result);
                }
                else
                {
                    apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                       ErrorMessageEnum.無法新增紀錄, payload: result);
                }
            }
            else
            {
                apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                   ErrorMessageEnum.傳送過來的資料有問題, payload: data);
            }
            return(Ok(apiResult));
        }
示例#3
0
        public LeaveFormPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                      LeaveFormService leaveFormService, LeaveCategoryService leaveCategoryService,
                                      MyUserService myUserService,
                                      RefreshTokenService refreshTokenService,
                                      SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService    = navigationService;
            this.dialogService        = dialogService;
            this.leaveFormService     = leaveFormService;
            this.leaveCategoryService = leaveCategoryService;
            this.myUserService        = myUserService;
            this.refreshTokenService  = refreshTokenService;
            this.systemStatusService  = systemStatusService;
            this.appStatus            = appStatus;

            #region 新增紀錄
            AddCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject          = new LeaveFormDto();
                fooObject.FormDate     = DateTime.Now.Date;
                fooObject.BeginDate    = DateTime.Now.AddDays(1).Date + new TimeSpan(09, 00, 00);
                fooObject.CompleteDate = DateTime.Now.AddDays(1).Date + new TimeSpan(18, 00, 00);
                fooObject.Hours        = 8.0m;

                #region 設定該使用者為預設紀錄申請者
                var myUser = myUserService.Items
                             .FirstOrDefault(x => x.Id == appStatus.SystemStatus.UserID);
                if (myUser != null)
                {
                    fooObject.MyUserId   = myUser.Id;
                    fooObject.MyUserName = myUser.Name;
                }
                #endregion

                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudAddAction);
                await navigationService.NavigateAsync("LeaveFormRecordPage", paras);
            });
            #endregion

            #region 點選某筆紀錄觸發命令
            ItemTappedCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject = SelectedItem.Clone();
                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudEditAction);
                await navigationService.NavigateAsync("LeaveFormRecordPage", paras);
            });
            #endregion

            #region 更新遠端紀錄命令
            RefreshCommand = new DelegateCommand(async() =>
            {
                IsRefresh = true;
                await ReloadData();
                IsRefresh = false;
            });
            #endregion
        }