コード例 #1
0
        public async Task <IViewComponentResult> InvokeAsync(string idForm)
        {
            var user = await _userHandler.GetUserAsync(HttpContext.User);

            List <string> partIds = await _userHandler.GetAllowPartsForView(user, idForm);

            FilterHandler handlerFilter = new FilterHandler(_context, idForm, user, _userHandler);
            Incomer       incomer       = await handlerFilter.GetIncomerDataAsync();

            TypeQuery typeQuery = await handlerFilter.GetTypeQueryAsync();

            OutFlow outFlow = await handlerFilter.GetStackFlowAsync(incomer, typeQuery);

            IList <MtdStore> mtdStore = outFlow.MtdStores;

            decimal count = (decimal)outFlow.Count / incomer.PageSize;

            pageCount = Convert.ToInt32(Math.Round(count, MidpointRounding.AwayFromZero));
            pageCount = pageCount == 0 ? 1 : pageCount;

            IList <string> storeIds = mtdStore.Select(s => s.Id).ToList();
            IList <string> fieldIds = fieldIds = incomer.FieldForColumn.Select(x => x.Id).ToList();

            IList <string> allowFiieldIds = await _context.MtdFormPartField.Where(x => partIds.Contains(x.MtdFormPart)).Select(x => x.Id).ToListAsync();

            fieldIds = allowFiieldIds.Where(x => fieldIds.Contains(x)).ToList();

            StackHandler          handlerStack  = new StackHandler(_context);
            IList <MtdStoreStack> mtdStoreStack = await handlerStack.GetStackAsync(storeIds, fieldIds);

            IList <MtdStoreApproval> mtdStoreApprovals = await _context.MtdStoreApproval.Where(x => storeIds.Contains(x.Id)).ToListAsync();

            List <ApprovalStore> approvalStores = await ApprovalHandler.GetStoreStatusAsync(_context, storeIds, user);

            bool isApprovalForm = await ApprovalHandler.IsApprovalFormAsync(_context, idForm);

            RowsModelView rowsModel = new RowsModelView
            {
                IdForm            = idForm,
                SearchNumber      = incomer.SearchNumber,
                PageCount         = pageCount,
                MtdFormPartFields = incomer.FieldForColumn.Where(x => fieldIds.Contains(x.Id)).ToList(),
                MtdStores         = mtdStore,
                MtdStoreStack     = mtdStoreStack,
                WaitList          = incomer.WaitList == 1 ? true : false,
                ShowDate          = await handlerFilter.IsShowDate(),
                ShowNumber        = await handlerFilter.IsShowNumber(),
                ApprovalStores    = approvalStores,
                IsAppromalForm    = isApprovalForm
            };

            return(View("Default", rowsModel));
        }