public async Task <IActionResult> PostExportAsync() { var data = Request.Form["InputFormForExport"]; if (data.FirstOrDefault() == null || data.FirstOrDefault().Equals(string.Empty)) { return(NotFound()); } string idForm = data.FirstOrDefault(); var user = await _userHandler.GetUserAsync(User); List <string> partIds = await _userHandler.GetAllowPartsForView(user, idForm); FilterHandler handlerFilter = new FilterHandler(_context, idForm, user, _userHandler); MtdFilter mtdFilter = await handlerFilter.GetFilterAsync(); if (mtdFilter == null) { return(NotFound()); } Incomer incomer = await handlerFilter.GetIncomerDataAsync(); TypeQuery typeQuery = await handlerFilter.GetTypeQueryAsync(); incomer.PageSize = 1000; OutFlow outFlow = await handlerFilter.GetStackFlowAsync(incomer, typeQuery); IList <MtdStore> mtdStore = outFlow.MtdStores; IList <string> storeIds = mtdStore.Select(s => s.Id).ToList(); IList <string> fieldIds = incomer.FieldForColumn.Select(x => x.Id).ToList(); IList <string> allowFiieldIds = await _context.MtdFormPartField.Where(x => partIds.Contains(x.MtdFormPart)).Select(x => x.Id).ToListAsync(); fieldIds = allowFiieldIds.Where(x => fieldIds.Contains(x)).ToList(); StackHandler handlerStack = new StackHandler(_context); IList <MtdStoreStack> mtdStoreStack = await handlerStack.GetStackAsync(storeIds, fieldIds); IList <MtdFormPartField> columns = incomer.FieldForColumn.Where(x => fieldIds.Contains(x.Id)).ToList(); IWorkbook workbook = CreateWorkbook(mtdStore, columns, mtdStoreStack); workbook.WriteExcelToResponse(HttpContext, "OrderMakerList.xlsx"); return(Ok()); }
public async Task <IActionResult> PostExportAsync() { IFormCollection requestForm = await Request.ReadFormAsync(); var data = requestForm["InputFormForExport"]; if (data.FirstOrDefault() == null || data.FirstOrDefault().Equals(string.Empty)) { return(NotFound()); } string idForm = data.FirstOrDefault(); var user = await _userHandler.GetUserAsync(User); List <string> partIds = await _userHandler.GetAllowPartsForView(user, idForm); FilterHandler handlerFilter = new FilterHandler(_context, idForm, user, _userHandler); MtdFilter mtdFilter = await handlerFilter.GetFilterAsync(); if (mtdFilter == null) { return(NotFound()); } Incomer incomer = await handlerFilter.GetIncomerDataAsync(); TypeQuery typeQuery = await handlerFilter.GetTypeQueryAsync(); incomer.PageSize = 1000; OutFlow outFlow = await handlerFilter.GetStackFlowAsync(incomer, typeQuery); IList <MtdStore> mtdStore = outFlow.MtdStores; IList <string> storeIds = mtdStore.Select(s => s.Id).ToList(); IList <string> fieldIds = incomer.FieldForColumn.Select(x => x.Id).ToList(); IList <string> allowFiieldIds = await _context.MtdFormPartField.Where(x => partIds.Contains(x.MtdFormPart)).Select(x => x.Id).ToListAsync(); fieldIds = allowFiieldIds.Where(x => fieldIds.Contains(x)).ToList(); StackHandler handlerStack = new StackHandler(_context); IList <MtdStoreStack> mtdStoreStack = await handlerStack.GetStackAsync(storeIds, fieldIds); IList <MtdFormPartField> columns = incomer.FieldForColumn.Where(x => fieldIds.Contains(x.Id)).ToList(); IWorkbook workbook = CreateWorkbook(mtdStore, columns, mtdStoreStack); var ms = new NpoiMemoryStream { AllowClose = false }; workbook.Write(ms); ms.Flush(); ms.Seek(0, SeekOrigin.Begin); ms.AllowClose = true; return(new FileStreamResult(ms, new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { FileDownloadName = $"{DateTime.UtcNow:yyyyMMddHHmmss}.xlsx" }); return(Ok()); }