Exemple #1
0
        public async Task <IViewComponentResult> InvokeAsync(string idForm)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var mtdFormList = await ApprovalHandler.GetWaitStoreIds(_context, user, idForm);

            int pending = mtdFormList.Count();

            string    searchText = "";
            bool      whiteList  = false;
            MtdFilter filter     = await _context.MtdFilter.FirstOrDefaultAsync(x => x.IdUser == user.Id && x.MtdForm == idForm);

            if (filter != null)
            {
                searchText = filter.SearchText;
                whiteList  = filter.WaitList == 0 ? false : true;
            }

            HeaderModelView headerModelView = new HeaderModelView
            {
                IdForm         = idForm,
                SearchText     = searchText,
                WaitList       = whiteList,
                Pending        = pending,
                IsApprovalForm = await ApprovalHandler.IsApprovalFormAsync(_context, idForm)
            };

            return(View("Default", headerModelView));
        }
Exemple #2
0
        public async Task <OutFlow> GetStackFlowAsync(Incomer incomer, TypeQuery typeQuery)
        {
            OutFlow outFlow = new OutFlow();

            if (incomer.WaitList == 1)
            {
                List <string> storesForUser = await ApprovalHandler.GetWaitStoreIds(_context, _user, incomer.IdForm);

                queryMtdStore = queryMtdStore.Where(x => storesForUser.Contains(x.Id));
                outFlow       = new OutFlow
                {
                    Count     = queryMtdStore.Count(),
                    MtdStores = await queryMtdStore.OrderByDescending(x => x.Sequence).Skip((incomer.Page - 1) * incomer.PageSize).Take(incomer.PageSize).ToListAsync()
                };

                return(outFlow);
            }

            IList <MtdFilterScript> scripts = await GetScriptsAsync();

            if (scripts != null && scripts.Count > 0)
            {
                foreach (var fs in scripts)
                {
                    if (fs.Apply == 1)
                    {
                        queryMtdStore = queryMtdStore.FromSql(fs.Script);
                    }
                }
            }

            IList <Claim> claims = await _userHandler.GetClaimsAsync(_user);

            bool ownOnly = claims.Where(x => x.Type == incomer.IdForm && x.Value.Contains("view-own")).Any();

            if (ownOnly)
            {
                IList <string> storeIds = await _context.MtdStoreOwner.Where(x => x.UserId == _user.Id).Select(x => x.Id).ToListAsync();

                queryMtdStore = queryMtdStore.Where(x => storeIds.Contains(x.Id));
            }

            bool groupView = claims.Where(x => x.Type == incomer.IdForm && x.Value.Contains("view-group")).Any();

            if (groupView)
            {
                IList <WebAppUser> appUsers = await _userHandler.GetUsersInGroupsAsync(_user);

                List <string>  userIds  = appUsers.Select(x => x.Id).ToList();
                IList <string> storeIds = await _context.MtdStoreOwner.Where(x => userIds.Contains(x.UserId)).Select(x => x.Id).ToListAsync();

                queryMtdStore = queryMtdStore.Where(x => storeIds.Contains(x.Id));
            }

            switch (typeQuery)
            {
            case TypeQuery.number:
            {
                outFlow = await GetDataForNumberAsync(incomer);

                break;
            }

            case TypeQuery.text:
            {
                outFlow = await GetDataForTextAsync(incomer);

                break;
            }

            case TypeQuery.field:
            case TypeQuery.textField:
            {
                outFlow = await GetDataForFieldAsync(incomer);

                break;
            }

            default:
            {
                outFlow = await GetDataForEmptyAsync(incomer);

                break;
            }
            }

            return(outFlow);
        }