public async Task <DataRequestResult <WorkOrderAdapterModel> > GetAsync(DataRequest dataRequest,
                                                                                WorkOrderStatusCondition CurrentWorkOrderStatusCondition = null)
        {
            List <WorkOrderAdapterModel> data = new();
            DataRequestResult <WorkOrderAdapterModel> result = new();
            var DataSource = context.WorkOrder
                             .Include(x => x.CategoryMain)
                             .Include(x => x.CategorySub)
                             .AsNoTracking();

            #region 進行搜尋動作
            if (!string.IsNullOrWhiteSpace(dataRequest.Search))
            {
                DataSource = DataSource
                             .Where(x => x.Description.Contains(dataRequest.Search) ||
                                    x.Comment.Contains(dataRequest.Search));
            }
            #endregion

            #region 過濾派工單狀態
            if (CurrentWorkOrderStatusCondition != null)
            {
                if (CurrentWorkOrderStatusCondition.Id != -1)
                {
                    DataSource = DataSource
                                 .Where(x => x.Status == CurrentWorkOrderStatusCondition.Id);
                }
            }
            #endregion

            #region 進行排序動作
            if (dataRequest.Sorted != null)
            {
                SortCondition CurrentSortCondition = dataRequest.Sorted;
                switch (CurrentSortCondition.Id)
                {
                case (int)WorkOrderSortEnum.CreatedAtDescending:
                    DataSource = DataSource.OrderByDescending(x => x.CreatedAt);
                    break;

                case (int)WorkOrderSortEnum.CreatedAtAscending:
                    DataSource = DataSource.OrderBy(x => x.CreatedAt);
                    break;

                case (int)WorkOrderSortEnum.StartDateDescending:
                    DataSource = DataSource.OrderByDescending(x => x.StartDate);
                    break;

                case (int)WorkOrderSortEnum.StartDateAscending:
                    DataSource = DataSource.OrderBy(x => x.StartDate);
                    break;

                case (int)WorkOrderSortEnum.StatusDescending:
                    DataSource = DataSource.OrderByDescending(x => x.Status);
                    break;

                case (int)WorkOrderSortEnum.StatusAscending:
                    DataSource = DataSource.OrderBy(x => x.Status);
                    break;

                default:
                    DataSource = DataSource.OrderBy(x => x.Id);
                    break;
                }
            }
            #endregion

            #region 進行分頁
            // 取得記錄總數量,將要用於分頁元件面板使用
            result.Count = DataSource.Cast <WorkOrder>().Count();
            DataSource   = DataSource.Skip(dataRequest.Skip);
            if (dataRequest.Take != 0)
            {
                DataSource = DataSource.Take(dataRequest.Take);
            }
            #endregion

            #region 在這裡進行取得資料與與額外屬性初始化
            List <WorkOrderAdapterModel> adapterModelObjects =
                Mapper.Map <List <WorkOrderAdapterModel> >(DataSource);

            foreach (var adapterModelItem in adapterModelObjects)
            {
                await OhterDependencyData(adapterModelItem);
            }
            #endregion

            result.Result = adapterModelObjects;
            await Task.Yield();

            return(result);
        }
        public WorkOrderViewModel(IWorkOrderService CurrentService,
                                  BackendDBContext context, IMapper Mapper,
                                  TranscationResultHelper transcationResultHelper,
                                  IFlowMasterService flowMasterService,
                                  UserHelper currentUserHelper, CurrentUser currentUser,
                                  ICategoryMainService categoryMainService, ICategorySubService categorySubService)
        {
            this.CurrentService = CurrentService;
            this.context        = context;
            mapper = Mapper;
            TranscationResultHelper = transcationResultHelper;
            FlowMasterService       = flowMasterService;
            CurrentUserHelper       = currentUserHelper;
            CurrentUser             = currentUser;
            CategoryMainService     = categoryMainService;
            CategorySubService      = categorySubService;
            WorkOrderSort.Initialization(SortConditions);
            WorkOrderStatusCondition.Initialization(WorkOrderStatusConditions);
            CurrentWorkOrderStatusCondition.Id    = WorkOrderStatusConditions[0].Id;
            CurrentWorkOrderStatusCondition.Title = WorkOrderStatusConditions[0].Title;
            FilterWorkOrderStatusCondition        = CurrentWorkOrderStatusCondition.Id;
            WorkOrderStatusCondition.Initialization(WorkOrderStatusRecordConditions);
            WorkOrderStatusRecordConditions.RemoveAt(0);

            #region 工具列按鈕初始化
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdAdd,
                Text        = "新增",
                TooltipText = "新增",
                Type        = ItemType.Button,
                PrefixIcon  = "mdi mdi-plus-thick",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add(new ItemModel()
            {
                Id          = ButtonIdHelper.ButtonIdRefresh,
                Text        = "重新整理",
                TooltipText = "重新整理",
                PrefixIcon  = "mdi mdi-refresh",
                Align       = ItemAlign.Left,
            });
            Toolbaritems.Add("Search");
            #endregion

            #region 互動式彈出功能表 ContextMenu 初始化
            ContextMenuItems.Add(new ContextMenuItemModel
            {
                Text    = "送審",
                Target  = ".e-content",
                Id      = "送審",
                IconCss = "mdi mdi-send-circle",
            });
            ContextMenuItems.Add(new ContextMenuItemModel
            {
                Text    = "查看送審記錄",
                Target  = ".e-content",
                Id      = "查看送審記錄",
                IconCss = "mdi mdi-file-find",
            });
            #endregion
        }