Exemple #1
0
        public async Task <IActionResult> OnPostAsync(string queryString)
        {
            ViewData["QueryString"] = queryString;

            Towns  = (await _townService.GetAvailableTownsEagerAsync(HttpContext.User));
            Groups = (await _groupService.ListAwailableGroupEagerAsync(HttpContext.User));
            ViewData["TownList"]  = new SelectList(Towns, "Id", "Name");
            ViewData["GroupList"] = new SelectList(Groups, "Id", "Name");

            ISpecification <VehicleItem> canFetch = await Vehicle4UserSpecification.CreateAsync(HttpContext.User, _userManager);

            canFetch = canFetch.And(FilterModel.ToExpression());
            canFetch.Includes.Add(t => t.Driver);
            canFetch.Includes.Add(t => t.Town);
            canFetch.Includes.Add(t => t.Group);
            canFetch.OrderBy(t => t.IsValid());

            var items = await _vehicleService.ListAsync(canFetch);

            if (FilterModel.ExportExcel == true)
            {
                var sigStr = $"::{HttpContext.User.Identity.Name}::socona.imvehicle.vehicle.export?search::{DateTime.Now.ToString("yyyyMMdd.HHmmss")}";
                var stream = ExcelHelper.ExportVehicles(items, sigStr);
                return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"exported{DateTime.Now.ToString("yyyyMMdd.HHmmss")}.xlsx"));
            }


            Vehicles = items.Select(t => new VehicleListViewModel(t)).ToList();

            return(Page());
        }