Esempio n. 1
0
        public async Task <ActionResult> Create(FileUpload fileObj)
        {
            var lastFolderCreated = await _attachmentMasterManager.GetLastFolderCreated();

            var files = fileObj.Files;
            //List<AttachmentDetail.AttachmentDetail> MasterFiles = new List<AttachmentDetail.AttachmentDetail>();

            var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");

            if (!Directory.Exists(uploads))
            {
                Directory.CreateDirectory(uploads);
            }

            if (files != null)
            {
                foreach (var file in files)
                {
                    var filePath = Path.Combine(uploads, file.FileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        await file.CopyToAsync(fileStream);

                        using (var ms = new MemoryStream())
                        {
                            file.CopyTo(ms);
                            var fileBytes = ms.ToArray();

                            AttachmentDetail.AttachmentDetail attachmentDetail = new AttachmentDetail.AttachmentDetail
                            {
                                FileName           = file.FileName,
                                File               = fileBytes,
                                AttachmentMasterId = lastFolderCreated.Id
                            };

                            await _attachmentDetailManager.CreateFile(attachmentDetail);

                            //    MasterFiles.Add(attachmentDetail);
                        }
                    }
                }
                // attachmentMaster.Files = MasterFiles;

                //order.Files = orderFiles;
            }

            return(Ok("ok"));
        }
 public async Task CreateFile(AttachmentDetail.AttachmentDetail entity)
 {
     await _attachmentDetailRepository.InsertAsync(entity);
 }