コード例 #1
0
        public static async Task <FileAttachmentModel> ReadToFileAttachmentModel(this IFormFile file)
        {
            var inputStream = file.OpenReadStream();

            byte[] content = null;

            var buffer = new byte[file.Length];

            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = await inputStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                content = ms.ToArray();
            }

            var fileAttachmentModel = new FileAttachmentModel
            {
                Content      = content,
                FileName     = Path.GetFileName(file.FileName),
                FileFormatId = 1 ////TODO Misssing mapping
            };

            return(fileAttachmentModel);
        }
コード例 #2
0
 internal FileAttachment(Api api, FileAttachmentModel model)
 {
     _api        = api;
     ContentType = model.ContentType;
     Url         = model.Url;
     Filename    = model.Filename;
     DisplayName = model.DisplayName;
 }
コード例 #3
0
        public FileAttachmentModel GetDocument(FileAttachmentModel fileAttachmentModel)
        {
            FileAttachmentModel fileAttModel = new FileAttachmentModel();

            FileAttachment fileAttachment = fileAttachmentRepository.SingleOrDefault(where => where.DocumentId == fileAttachmentModel.DocumentId);

            AutoMapper.Mapper.Map(fileAttachment, fileAttModel);
            return(fileAttModel);
        }
コード例 #4
0
        public FileAttachmentModel UpdateDocument(FileAttachmentModel fileAttachmentModel)
        {
            FileAttachment fileAttachment = new FileAttachment();

            AutoMapper.Mapper.Map(fileAttachmentModel, fileAttachment);
            fileAttachmentRepository.Update(fileAttachment);
            AutoMapper.Mapper.Map(fileAttachment, fileAttachmentModel);
            return(fileAttachmentModel);
        }
コード例 #5
0
        public FileAttachmentModel AddDocument(FileAttachmentModel fileAttachmentModel)
        {
            FileAttachment fileAttachment = new FileAttachment();

            AutoMapper.Mapper.Map(fileAttachmentModel, fileAttachment);
            fileAttachmentRepository.Insert(fileAttachment);
            AutoMapper.Mapper.Map(fileAttachment, fileAttachmentModel);
            return(fileAttachmentModel);
        }
コード例 #6
0
        public AddClaimAttachmentWithFileApiRequest(
            AddClaimAttachmentApiModel addClaimAttachmentApiModel,
            FileAttachmentModel fileAttachment)
        {
            Ensure.That(addClaimAttachmentApiModel, nameof(addClaimAttachmentApiModel)).IsNotNull();
            Ensure.That(fileAttachment, nameof(fileAttachment)).IsNotNull();

            this.AddClaimAttachmentApiModel = addClaimAttachmentApiModel;
            this.FileAttachment             = fileAttachment;
        }
コード例 #7
0
        public AddClaimCostAttachmentWithFileApiRequest(
            AddClaimCostAttachmentApiModel addClaimCostAttachmentApiModel,
            FileAttachmentModel documentStorageModel)
        {
            Ensure.That(addClaimCostAttachmentApiModel, nameof(addClaimCostAttachmentApiModel)).IsNotNull();
            Ensure.That(documentStorageModel, nameof(documentStorageModel)).IsNotNull();

            this.AddClaimCostAttachmentApiModel = addClaimCostAttachmentApiModel;
            this.FileAttachment = documentStorageModel;
        }
コード例 #8
0
        public async void PickFiles()
        {
            List <FileResult> filesList = (await Helper.PickFilesAndShow())?.ToList();

            if (filesList == null)
            {
                return;
            }

            foreach (FileResult fileResult in filesList)
            {
                if (!FileAlreadyAttached(fileResult.FullPath))
                {
                    var stream = await fileResult.OpenReadAsync();

                    if (stream != null)
                    {
                        FileAttachmentModel fileAttachement = new FileAttachmentModel()
                        {
                            FileId           = Rainbow.Util.GetGUID(),
                            FileName         = fileResult.FileName,
                            FileSize         = Helper.HumanizeFileSize(stream.Length),
                            ImageSourceId    = Helper.GetFileSourceIdFromFileName(fileResult.FileName),
                            SelectionCommand = this.SelectionCommand
                        };
                        fileAttachement.FileDetails = fileAttachement.FileName + " (" + fileAttachement.FileSize + ")";

                        // Add to the list of FileAttachmentModel
                        FilesAttached.Insert(0, fileAttachement);

                        // Add to the list of FileResult
                        filesResultAttached.Insert(0, fileResult);

                        stream.Close();
                        stream.Dispose();
                    }
                }
            }

            UpdateFrameSize();
        }
コード例 #9
0
 public void RemoveDocument(FileAttachmentModel fileAttachmentModel)
 {
     fileAttachmentRepository.Delete(where => where.DocumentId == fileAttachmentModel.DocumentId);
 }