public async Task <BaseResponse <bool> > InsertFromFileAsync(MemoryStream stream, int userId)
        {
            var result = await ReadXlsxFile(stream);

            if (result.IsSuccess == false || result.Data == null)
            {
                return(new BaseResponse <bool>(result.Message, false, false));
            }
            if (result.Data == null || !result.Data.Any())
            {
                return(new BaseResponse <bool>("Không có dữ liệu hoặc không thể import", false, false));
            }
            foreach (var param in result.Data)
            {
                await _rpRevokeDebt.InsertManyByParameterAsync(param, userId);
            }
            return(new BaseResponse <bool>($"Đã import thành công {result.Data.Count} dòng", true, true));
        }
Beispiel #2
0
        public async Task <string> InsertFromFileAsync(IFormFile file)
        {
            if (file == null)
            {
                return(ToResponse(string.Empty, Errors.file_cannot_be_null));
            }
            var bizCommon   = _svProvider.GetService <ICommonBusiness>();
            var inputParams = null as List <DynamicParameters>;

            using (var stream = new MemoryStream())
            {
                await file.CopyToAsync(stream);

                inputParams = await bizCommon.ReadXlsxFileAsync(stream, Entities.Commons.Enums.ProfileType.RevokeDebt, 2, 20);
            }
            if (inputParams == null)
            {
                return($"Đã import thành công {0} dòng");
            }

            var result = await _rpRevoke.InsertManyByParameterAsync(inputParams, _process.User.Id);

            return($"Đã import thành công {result} dòng");
        }