Exemple #1
0
        public async Task <List <CameraDto> > PostExcelToCameraInfoAsync(IFormFile files)
        {
            if (files.Length == 0)
            {
                return(null);
            }

            DataTable dt = new DataTable();


            var data = ExcelHelper.ExcelToDataTable(files.OpenReadStream(), Path.GetExtension(files.FileName), "Sheet", true);

            var list = ListToDataTable.tolist <UpdateCameraDto>(data);
            List <CameraDto> listcamera = new List <CameraDto>();

            foreach (var item in list)
            {
                var camera = await _cameraAppService.GetListByCondition(new CameraCondition()
                {
                    Camera_ID = item.Camera_ID
                }, null);



                if (camera.TotalCount == 0)
                {
                    var Cameradata = await _cameraAppService.CreateAsync(item);

                    listcamera.Add(Cameradata);
                }
            }


            return(listcamera);
        }
Exemple #2
0
        public IActionResult GetOutExcel(CameraCondition condition)
        {
            PagedSortedRequestDto resultRequestDto = new PagedSortedRequestDto()
            {
                MaxResultCount = 200000, SkipCount = 0
            };
            var data = _cameraAppService.GetListByCondition(condition, resultRequestDto);
            var list = data.Result.Items.ToList();

            DataTable dataTable  = ListToDataTable.toDataTable <CameraDto>(list);
            var       pathname   = $"{System.AppDomain.CurrentDomain.BaseDirectory}Basics\\OutExcel.xlsx";
            var       requst     = ExcelHelper.DataTableToExcel(dataTable, pathname, "Sheet1", true);
            var       stream     = System.IO.File.OpenRead(pathname);
            string    fileExt    = Path.GetExtension(pathname);
            var       provider   = new FileExtensionContentTypeProvider();
            var       meni       = provider.Mappings[fileExt];
            var       returnFile = File(stream, meni, Path.GetFileName(pathname));

            return(returnFile);
        }