Esempio n. 1
0
 public async Task <int> Post([FromBody] FundInvestor fundInvestor)
 {
     using (var dataAccess = new MasterSideLetterDataAccess(_connectionStrings.MasterSideLetterDb))
     {
         return(await dataAccess.CreateFundInvestorAsync(fundInvestor));
     }
 }
Esempio 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 });
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public async Task SaveAll([FromBody] FundInvestor[] fundInvestors)
 {
     using (var dataAccess = new MasterSideLetterDataAccess(_connectionStrings.MasterSideLetterDb))
     {
         foreach (var fundInvestor in fundInvestors)
         {
             if (fundInvestor.Id == 0)
             {
                 await dataAccess.CreateFundInvestorAsync(fundInvestor);
             }
             else
             {
                 await dataAccess.UpdateFundInvestorAsync(fundInvestor);
             }
         }
     }
 }