Пример #1
0
        public async Task <IActionResult> Numbering([Bind(Prefix = nameof(NumberingSearchViewModel.Search))] NpSearch search, int page = 1)
        {
            var query = NumberingQuery(search);
            var model = new NumberingSearchViewModel
            {
                PageInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = Settings.PageSize,
                    TotalItems   = await query.CountAsync(),
                    From         = (page - 1) * Settings.PageSize,
                    To           = (page - 1) * Settings.PageSize + Settings.PageSize
                },
                Search      = search,
                Miscs       = await repository.Miscs.OrderBy(x => x.Name).ToArrayAsync(),
                ExcelSearch = search,
                Results     = await query
                              .Skip((page - 1) *Settings.PageSize)
                              .Take(Settings.PageSize)
                              .Include(x => x.NumberingPoolNetworkElements)
                              .ThenInclude(x => x.Element).ToArrayAsync()
            };

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> NumberingExcel([Bind(Prefix = nameof(ViewModels.NumberingSearchViewModel.ExcelSearch))] NpSearch search)
        {
            var    nps        = NumberingQuery(search);
            string tempFolder = Path.GetTempPath();
            var    fileName   = $"Numbering {Settings.GetDateTimeNowFile()}.xlsx";
            string path       = Path.Combine(tempFolder, fileName);

            Infrastructure.ReportGenerator report = new Infrastructure.ReportGenerator(User.Identity.Name, path);
            report.Numbering(nps);
            var memory = new MemoryStream();

            using (var stream = new FileStream(path, FileMode.Open))
            {
                await stream.CopyToAsync(memory);
            }
            memory.Position = 0;
            return(File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName));
        }
Пример #3
0
        private IQueryable <NumberingPool> NumberingQuery(NpSearch search)
        {
            var query = repository.GetNps();

            if (!string.IsNullOrEmpty(search.Prefix))
            {
                switch (search.PrefixMode)
                {
                case QueryMode.RightMatch:
                    query = query.Where(x => x.Prefix.StartsWith(search.Prefix));
                    break;

                case QueryMode.Exact:
                    query = query.Where(x => x.Prefix == search.Prefix);
                    break;

                case QueryMode.Like:
                    query = query.Where(x => x.Prefix.Contains(search.Prefix));
                    break;

                default:
                    break;
                }
            }

            if (!string.IsNullOrEmpty(search.Abb))
            {
                query = query.Where(x => x.Abb == search.Abb);
            }

            if (search.ChargingCases != null)
            {
                query = query.Where(x => search.ChargingCases.Contains(x.ChargingCase));
            }

            if (search.Directions != null)
            {
                query = query.Where(x => search.Directions.Contains(x.Direction.Value));
            }

            if (search.Max != null)
            {
                query = query.Where(x => x.Max == search.Max);
            }

            if (search.Min != null)
            {
                query = query.Where(x => x.Min == search.Min);
            }

            if (search.Owners != null)
            {
                query = query.Where(x => search.Owners.Contains(x.Owner));
            }

            if (search.RondTypes != null)
            {
                query = query.Where(x => search.RondTypes.Contains(x.Rond));
            }

            if (search.Statuses != null)
            {
                query = query.Where(x => search.Statuses.Contains(x.Status));
            }

            if (!string.IsNullOrEmpty(search.SubscriberName))
            {
                search.SubscriberName = search.SubscriberName.Replace('ي', 'ی').Replace('ك', 'ک');
                query = query.Where(x => x.NormalizedSubscriberName.Contains(search.SubscriberName.Replace(" ", "")));
            }

            if (search.RondTypes != null)
            {
                query = query.Where(x => search.RondTypes.Contains(x.Rond));
            }

            if (search.NumberTypes != null)
            {
                query = query.Where(x => search.NumberTypes.Contains(x.NumberType));
            }
            if (search.LinkTypes != null)
            {
                query = query.Where(x => search.LinkTypes.Contains(x.Link.Value));
            }
            if (search.Areas != null)
            {
                query = query.Where(x => search.Areas.Contains(x.Area.Value));
            }

            return(query);
        }