public Attachment MapCreate(AttachViewModel attachViewModel)
        {
            FileUploadManager fileUploadManager = new FileUploadManager(attachViewModel.Attachment);
            var        fileByteArray            = fileUploadManager.GetByteArray();
            Attachment attachment = new Attachment()
            {
                FileContent = fileByteArray,
                FileName    = attachViewModel.Attachment.FileName,
                TableName   = attachViewModel.TableName,
                TableId     = Guid.Parse(attachViewModel.Id),
                MimeType    = attachViewModel.Attachment.ContentType
            };

            return(attachment);
        }
示例#2
0
        public ActionResult Add(Guid communityId, [FromForm] ConsumptionApiModel consumptionApiModel)
        {
            try
            {
                // Guid id = Guid.Parse(attachViewModel.Id);
                FileUploadManager fileUploadManager = new FileUploadManager(consumptionApiModel.Attachment);
                string            fileName          = fileUploadManager.FileName;

                var outputFilePath = FileUploadManager.GetTempFolderPath(Guid.NewGuid().ToString() + ".xlsx");
                var byteArray      = fileUploadManager.GetByteArray();
                var consumption    = _consumptionMapper.Map(consumptionApiModel);
                consumption.Id = Guid.NewGuid();

                ServiceFactory    serviceFactory      = new ServiceFactory(this._faciTechDbContext, this._contactId);
                ConsumptionImport communityOnboarding = new ConsumptionImport(serviceFactory, communityId, outputFilePath);
                consumption.CommunityId = communityId;
                var isValid = communityOnboarding.Import(consumption, byteArray);

                FileManager fileManager = new FileManager(outputFilePath);
                var         outputFile  = new Attachment()
                {
                    FileName    = fileName,
                    FileContent = fileManager.GetByteArray(),
                    TableName   = "Consumption",
                    TableId     = consumption.Id,
                    MimeType    = consumptionApiModel.Attachment.ContentType
                };

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