예제 #1
0
        public void ImportUsers(Stream stream, int organizationId)
        {
            var scope = new TransactionScope(TransactionScopeOption.RequiresNew);

            using (scope)
            {
                var errors = new List <ExcelImportError>();
                var set    = _excelHandler.Import(stream);

                // importing org units
                var userTable = set.Tables[0];
                errors.AddRange(ImportUsersTransaction(userTable, organizationId));

                // then finally, did we notice any errors?
                if (errors.Any())
                {
                    throw new ExcelImportException()
                          {
                              Errors = errors
                          }
                }
                ;

                // if we got here, we're home frreeeee
                scope.Complete();
            }
        }
예제 #2
0
        public async Task <IResultModel> Import(IFormFile formFile)
        {
            var oldData = await _repository.GetListAsync(m => m.IsDel == false);

            var data     = _excelHandler.Import <MediaTypeImportModel>(formFile);
            var entities = _mapper.Map <List <MediaTypeEntity> >(data)
                           .Where(m => !oldData.Select(m => m.Ext).Contains(m.Ext)).ToList();

            var result = await _repository.InsertRangeAsync(entities);

            return(ResultModel.Result(result));
        }
        public async Task <IResultModel> Import(DictionaryItemAddModel model, IFormFile formFile)
        {
            var data     = _excelHandler.Import <DictionaryItemImportModel>(formFile);
            var entities = _mapper.Map <List <DictionaryItemEntity> >(data);

            entities.ForEach(m =>
            {
                m.GroupCode = model.GroupCode;
                m.DictCode  = model.DictCode;
                m.ParentId  = model.ParentId;
            });

            var result = await _repository.InsertRangeAsync(entities);

            return(ResultModel.Result(result));
        }