Esempio n. 1
0
        public MailQueueViewModel(IMailQueueService CurrentService,
                                  BackendDBContext context, IMapper Mapper,
                                  TranscationResultHelper transcationResultHelper)
        {
            this.CurrentService = CurrentService;
            this.context        = context;
            mapper = Mapper;
            TranscationResultHelper = transcationResultHelper;
            MailQueueSort.Initialization(SortConditions);
            MailQueueStatusCondition.Initialization(MailQueueStatusConditions);
            CurrentMailQueueStatusCondition.Id    = MailQueueStatusConditions[0].Id;
            CurrentMailQueueStatusCondition.Title = MailQueueStatusConditions[0].Title;
            FilterMailQueueStatusCondition        = CurrentMailQueueStatusCondition.Id;

            #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
        }
Esempio n. 2
0
        public async Task <DataRequestResult <MailQueueAdapterModel> > GetAsync(DataRequest dataRequest,
                                                                                MailQueueStatusCondition CurrentMailQueueStatusCondition = null)
        {
            List <MailQueueAdapterModel> data = new();
            DataRequestResult <MailQueueAdapterModel> result = new();
            var DataSource = context.MailQueue
                             .AsNoTracking();

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

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

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

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

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

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

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

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

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

            return(result);
        }