コード例 #1
0
        public IActionResult ExportToExcel([FromBody] SearchFormDto form)
        {
            var memoryStream = _service.ExportToExcel(form);

            return(File(memoryStream, "application/vnd.ms-excel",
                        $"Export {EntityName.Pluralize()} {DateTime.Now.ToString("dd.MM.yy HH.mm")}.xlsx"));
        }
コード例 #2
0
 protected override IQueryable <TransportCompany> ApplySort(IQueryable <TransportCompany> query,
                                                            SearchFormDto form)
 {
     return(query
            .OrderBy(i => i.Title)
            .ThenBy(i => i.Id));
 }
コード例 #3
0
 protected override IQueryable <ShippingWarehouse> ApplySort(IQueryable <ShippingWarehouse> query,
                                                             SearchFormDto form)
 {
     return(query
            .OrderBy(i => i.WarehouseName)
            .ThenBy(i => i.Id));
 }
コード例 #4
0
        public Stream ExportToExcel(SearchFormDto form)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var excel = new ExcelPackage();

            var user = _userProvider.GetCurrentUser();

            string entityName        = typeof(TEntity).Name.Pluralize().ToLowerFirstLetter();
            string entityDisplayName = entityName.Translate(user.Language);
            var    workSheet         = excel.Workbook.Worksheets.Add(entityDisplayName);

            var dbSet = _dataService.GetDbSet <TEntity>();
            var query = ApplySearch(dbSet, form);

            Log.Information("{entityName}.ExportToExcel (Apply search parameters): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            var entities = ApplySort(query, form);

            Log.Information("{entityName}.ExportToExcel (Load from DB): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            entities = ApplyRestrictions(entities);

            var dtos = entities.Select(MapFromEntityToDto);

            Log.Information("{entityName}.ExportToExcel (Convert to DTO): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            dtos = FillLookupNames(dtos);
            Log.Information("{entityName}.ExportToExcel (Fill lookups): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            var excelMapper = CreateExcelMapper();

            excelMapper.FillSheet(workSheet, dtos, user.Language);
            Log.Information("{entityName}.ExportToExcel (Fill file): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);

            return(new MemoryStream(excel.GetAsByteArray()));
        }
コード例 #5
0
        public SearchResult <TListDto> Search(SearchFormDto form)
        {
            string    entityName = typeof(TEntity).Name;
            Stopwatch sw         = new Stopwatch();

            sw.Start();

            var dbSet = _dataService.GetDbSet <TEntity>();
            var query = this.ApplySearch(dbSet, form);

            query = ApplyRestrictions(query);

            Log.Information("{entityName}.Search (Apply search parameters): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            if (form.Take == 0)
            {
                form.Take = 1000;
            }

            var totalCount = query.Count();
            var entities   = ApplySort(query, form)
                             .Skip(form.Skip)
                             .Take(form.Take).ToList();

            Log.Information("{entityName}.Search (Load from DB): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            var a = new SearchResult <TListDto>
            {
                TotalCount = totalCount,
                Items      = entities.Select(entity => MapFromEntityToDto(entity)).ToList()
            };

            Log.Information("{entityName}.Search (Convert to DTO): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            a.Items = FillLookupNames(a.Items).ToList();
            Log.Information("{entityName}.Search (Fill lookups): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);

            return(a);
        }
コード例 #6
0
 protected virtual IQueryable <TEntity> ApplySort(IQueryable <TEntity> query, SearchFormDto form)
 {
     return(query.OrderBy(i => i.Id));
 }
コード例 #7
0
        protected virtual IQueryable <TEntity> ApplySearch(IQueryable <TEntity> query, SearchFormDto form)
        {
            if (string.IsNullOrEmpty(form.Search))
            {
                return(query);
            }

            var stringProperties = typeof(TEntity).GetProperties()
                                   .Where(prop => prop.PropertyType == form.Search.GetType());

            return(query.Where(customer =>
                               stringProperties.Any(prop =>
                                                    ((string)prop.GetValue(customer, null) ?? "").ToLower().Contains(form.Search.ToLower()))));
        }
コード例 #8
0
 protected override IQueryable <User> ApplySort(IQueryable <User> query, SearchFormDto form)
 {
     return(query
            .OrderBy(i => i.Email)
            .ThenBy(i => i.Id));
 }
コード例 #9
0
 protected override IQueryable <ProductType> ApplySort(IQueryable <ProductType> query, SearchFormDto form)
 {
     return(query
            .OrderBy(i => i.Name)
            .ThenBy(i => i.Id));
 }
コード例 #10
0
//        private Guid? GetBodyTypeIdByName(string name)
//        {
//            var entry = _dataService.GetDbSet<BodyType>().Where(t => t.Name == name).FirstOrDefault();
//            return entry?.Id;
//        }

        protected override IQueryable <Tariff> ApplySearch(IQueryable <Tariff> query, SearchFormDto form)
        {
            if (string.IsNullOrEmpty(form.Search))
            {
                return(query);
            }

            var search = form.Search.ToLower();

            var transportCompanies = this._dataService.GetDbSet <TransportCompany>()
                                     .Where(i => i.Title.ToLower().Contains(search))
                                     .Select(i => i.Id);

            var providers = this._dataService.GetDbSet <Provider>()
                            .Where(i => i.Name.ToLower().Contains(search))
                            .Select(i => i.Id);

            var shippingWarehouses = this._dataService.GetDbSet <ShippingWarehouse>()
                                     .Where(i => i.WarehouseName.ToLower().Contains(search))
                                     .Select(i => i.Id);

            var deliveryWarehouses = this._dataService.GetDbSet <Warehouse>()
                                     .Where(i => i.WarehouseName.ToLower().Contains(search))
                                     .Select(i => i.Id);

            var vehicleTypes = this._dataService.GetDbSet <VehicleType>()
                               .Where(i => i.Name.Contains(search, StringComparison.InvariantCultureIgnoreCase))
                               .Select(i => i.Id).ToList();

//            var tarifficationTypeNames = Enum.GetNames(typeof(TarifficationType)).Select(i => i.ToLower());

//            var tarifficationTypes = this._dataService.GetDbSet<Translation>()
//                .Where(i => tarifficationTypeNames.Contains(i.Name.ToLower()))
//                .WhereTranslation(search)
//                .Select(i => (TarifficationType?)Enum.Parse<TarifficationType>(i.Name, true))
//                .ToList();

            var searchDateFormat = "dd.MM.yyyy HH:mm";

            return(query.Where(i =>
                               transportCompanies.Any(t => t == i.CarrierId) ||
                               vehicleTypes.Any(t => t == i.VehicleTypeId) ||
                               i.StartWinterPeriod.HasValue && i.StartWinterPeriod.Value.ToString(searchDateFormat).Contains(search) ||
                               i.EndWinterPeriod.HasValue && i.EndWinterPeriod.Value.ToString(searchDateFormat).Contains(search) ||
                               providers.Contains(i.ProviderId.Value) ||
                               shippingWarehouses.Contains(i.ShippingWarehouseId) ||
                               deliveryWarehouses.Contains(i.DeliveryWarehouseId)
                               ));
        }
コード例 #11
0
        protected override IQueryable <Warehouse> ApplySearch(IQueryable <Warehouse> query, SearchFormDto form)
        {
            if (string.IsNullOrEmpty(form.Search))
            {
                return(query);
            }

            var search = form.Search.ToLower();

            var isInt = int.TryParse(search, out int searchInt);

            return(query.Where(i =>
                               i.WarehouseName.ToLower().Contains(search) ||
                               i.Region.ToLower().Contains(search) ||
                               i.City.ToLower().Contains(search) ||
                               i.Address.ToLower().Contains(search) ||
                               i.Latitude.Contains(search) ||
                               i.Longitude.Contains(search) ||
                               isInt && i.LeadtimeDays == searchInt
                               ));
        }
コード例 #12
0
 public SearchResult <TDto> Search([FromBody] SearchFormDto form)
 {
     return(_service.Search(form));
 }
コード例 #13
0
 public async Task <IActionResult> Search(SearchFormDto search)
 {
     return(this.GenerateResponse(await _formService.Search(search)));
 }
コード例 #14
0
ファイル: FormService.cs プロジェクト: jriley15/jforms
 public Task <Response> Search(SearchFormDto search)
 {
     throw new NotImplementedException();
 }
コード例 #15
0
//        public override IQueryable<Article> ApplyRestrictions(IQueryable<Article> query)
//        {
//            var currentUserId = _userProvider.GetCurrentUserId();
//            var user = _dataService.GetById<User>(currentUserId.Value);
//
//            // Local user restrictions
//
//            if (user?.CompanyId != null)
//            {
//                query = query.Where(i => i.CompanyId == user.CompanyId || i.CompanyId == null);
//            }
//
//            return query;
//        }

        protected override IQueryable <Article> ApplySort(IQueryable <Article> query, SearchFormDto form)
        {
            return(query
                   .OrderBy(i => i.Description)
                   .ThenBy(i => i.Id));
        }