Ejemplo n.º 1
0
        public async Task <OutFlow> GetDataForFieldAsync(Incomer incomer)
        {
            IList <string> storeIds = null;

            if (incomer.SearchText.Length > 0)
            {
                List <string> fieldsIds = incomer.FieldForColumn.Select(x => x.Id).ToList();
                storeIds = await FindStoreIdsForText(fieldsIds, incomer.SearchText, 4);
            }

            if (incomer.FieldForFilter != null && incomer.FieldForFilter.Count > 0)
            {
                foreach (var item in incomer.FieldForFilter)
                {
                    int           fieldType = item.MtdFormPartFieldNavigation.MtdSysType;
                    List <string> field     = new List <string> {
                        item.MtdFormPartField
                    };

                    switch (fieldType)
                    {
                    case 2:
                    case 12:
                    {
                        int valueInt = int.Parse(item.Value);
                        storeIds = await FindStoreIdsForInt(field, valueInt, item.MtdTerm, storeIds);

                        break;
                    }

                    case 3:
                    {
                        decimal valueDecimal = decimal.Parse(item.Value);
                        storeIds = await FindStoreIdsForDecimal(field, valueDecimal, item.MtdTerm, storeIds);

                        break;
                    }

                    case 5:
                    {
                        bool ok = DateTime.TryParse(item.Value, out DateTime dateTime);
                        if (ok)
                        {
                            storeIds = await FindStoreIdsForDate(field, dateTime.Date, item.MtdTerm, storeIds);
                        }
                        break;
                    }

                    case 6:
                    {
                        bool ok = DateTime.TryParse(item.Value, out DateTime dateTime);
                        if (ok)
                        {
                            storeIds = await FindStoreIdsForDateTime(field, dateTime, item.MtdTerm, storeIds);
                        }
                        break;
                    }

                    case 11:
                    {
                        storeIds = await FindStoreIdsForList(field, item.Value, item.MtdTerm, storeIds);

                        break;
                    }

                    default:
                    {
                        storeIds = await FindStoreIdsForText(field, item.Value, item.MtdTerm, storeIds);

                        break;
                    }
                    }
                }
                ;
            }

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

            return(paramOut);
        }
Ejemplo n.º 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);
        }