Exemplo n.º 1
0
        public async Task UploadSideLetter(int id)
        {
            using (var dataAccess = new MasterSideLetterDataAccess(_connectionStrings.MasterSideLetterDb))
            {
                //save the document
                if (Request.Form.Files[0].Length > 0)
                {
                    var fileExtension = Path.GetExtension(Request.Form.Files[0].FileName).ToLower();
                    if (fileExtension != ".doc" && fileExtension != ".docx")
                    {
                        throw new ArgumentException($"Invalid file type {fileExtension}.");
                    }
                    using (var readStream = Request.Form.Files[0].OpenReadStream())
                    {
                        await dataAccess.UpdateFundInvestorSideLetterAsync(id, Request.Form.Files[0].FileName, readStream);

                        await dataAccess.DeleteProvisionsByFundInvestorAsync(id);

                        var paragraphs = fileExtension == ".docx" ? DocumentHelper.ExtractDocxParagraphs(readStream) : DocumentHelper.ExtractDocParagraphs(readStream);
                        foreach (var paragraph in paragraphs.Where(paragraph => !string.IsNullOrWhiteSpace(paragraph)))
                        {
                            await dataAccess.CreateProvisionAsync(new Provision { FundInvestorId = id, Content = paragraph });
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task InvestorBatchUpload(int investorId)
        {
            using (var dataAccess = new MasterSideLetterDataAccess(_connectionStrings.MasterSideLetterDb))
            {
                foreach (var file in Request.Form.Files)
                {
                    var fileExtension = Path.GetExtension(file.FileName).ToLower();
                    if (fileExtension != ".doc" && fileExtension != ".docx")
                    {
                        throw new ArgumentException($"Invalid file type {fileExtension}.");
                    }
                    var fundInvestor = new FundInvestor {
                        InvestorId = investorId
                    };
                    fundInvestor.Id = await dataAccess.CreateFundInvestorAsync(fundInvestor);

                    using (var readStream = file.OpenReadStream())
                    {
                        await dataAccess.UpdateFundInvestorSideLetterAsync(fundInvestor.Id, file.FileName, readStream);

                        await dataAccess.DeleteProvisionsByFundInvestorAsync(fundInvestor.Id);

                        var paragraphs = fileExtension == ".docx" ? DocumentHelper.ExtractDocxParagraphs(readStream) : DocumentHelper.ExtractDocParagraphs(readStream);
                        foreach (var paragraph in paragraphs.Where(paragraph => !string.IsNullOrWhiteSpace(paragraph)))
                        {
                            await dataAccess.CreateProvisionAsync(new Provision { FundInvestorId = fundInvestor.Id, Content = paragraph });
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public async Task <int> Post([FromBody] Provision provision)
 {
     using (var dataAccess = new MasterSideLetterDataAccess(_connectionStrings.MasterSideLetterDb))
     {
         if (string.IsNullOrWhiteSpace(provision.Content))
         {
             return(0);
         }
         return(await dataAccess.CreateProvisionAsync(provision));
     }
 }