Ejemplo n.º 1
0
        public async Task <Fund> CreateFund(Fund fund)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                EntityEntry <Fund> res = await context.Funds.AddAsync(fund);

                await context.SaveChangesAsync();

                // Once the fund has been created, I then create the accounting periods

                // set the monthly or daily account periods for up to one year ahead...
                DateTime        startDate = fund.LaunchDate;
                List <DateTime> allPeriods;
                if (fund.NAVFrequency == "Daily")
                {
                    // get daily dates from fund launch to a year ahead
                    allPeriods = DateSettings.AnnualWorkingDays(startDate);
                }
                else
                {
                    // get month end dates from fund launch to a year ahead
                    allPeriods = DateSettings.AnnualMonthEnds(startDate);
                }
                // add all the dates to the new periods
                List <AccountingPeriodsDIM> initialPeriods = new List <AccountingPeriodsDIM>();
                foreach (DateTime period in allPeriods)
                {
                    AccountingPeriodsDIM newPeriod;
                    newPeriod = new AccountingPeriodsDIM {
                        AccountingDate = period.Date, isLocked = false, FundId = fund.FundId
                    };
                    initialPeriods.Add(newPeriod);
                }
                context.Periods.AddRange(initialPeriods);
                await context.SaveChangesAsync();

                return(res.Entity);
            }
        }