Exemplo n.º 1
0
        public void TestCommunityOnboardingSuccess()
        {
            using (var dbContext = GetConnection())
            {
                string path           = GetDataPath("community bulk sheet.xlsx");
                Guid   communityId    = Guid.Parse("6B8CC193-1F72-4B50-AD49-65C470405186");
                Guid   contactId      = Guid.Parse("862c17f4-6522-4806-9c63-b345bd4e4c07");
                var    serviceFactory = new ServiceFactory(dbContext, contactId);

                CommunityImport communityOnboarding = new CommunityImport(serviceFactory, communityId, "");
                communityOnboarding.Import(path);
            }
        }
        public ActionResult Import(Guid communityId, [FromForm] AttachViewModel attachViewModel)
        {
            try
            {
                Guid id = Guid.Parse(attachViewModel.Id);
                FileUploadManager fileUploadManager = new FileUploadManager(attachViewModel.Attachment);
                string            fileName          = fileUploadManager.FileName;

                var outputFilePath = FileUploadManager.GetTempFolderPath(Guid.NewGuid().ToString() + ".xlsx");
                var byteArray      = fileUploadManager.GetByteArray();


                ServiceFactory  serviceFactory      = new ServiceFactory(this._faciTechDbContext, this._contactId);
                CommunityImport communityOnboarding = new CommunityImport(serviceFactory, id, outputFilePath);
                var             isValid             = communityOnboarding.Import(byteArray);

                FileManager fileManager = new FileManager(outputFilePath);
                var         outputFile  = new Attachment()
                {
                    FileName    = fileName,
                    FileContent = fileManager.GetByteArray(),
                    TableName   = "Community",
                    TableId     = _communityId,
                    MimeType    = attachViewModel.Attachment.ContentType
                };

                _attachmentService.Create(outputFile, true);
                _communityService.UpdateLastUpload(communityId, fileName);
                fileUploadManager.DeleteFile();
                return(Ok(new ApiResponse(new { IsAllValid = isValid, FileName = fileName }, ApiStatus.Success)));
            }
            catch (Exception ex)
            {
                return(new UnknownErrorResult(ex, base._errorEnabled));
            }
        }