public void CreateNetWealthSnapshot(Account account, DateTime period, Entity entity, IEnumerable <WealthItem> wealthItems) { using (Profiler.Step("SnapshotService.CreateNetWealthSnapshot" + account.ID)) { var netWorth = WealthService.GetNetWorthSummary(account, false, wealthItems.ToList()); var newSnapshot = new Snapshot { NetWorth = netWorth.NetWorth, DateTaken = DateTime.Now, Period = period, Owners = SnapshotOwner.Sole(entity) }; DB.Snapshots.Add(newSnapshot); } }
public bool CreateSnapshot(Account account, DateTime period) { using (Profiler.Step("SnapshotService.CreateSnapshot" + account.ID)) { if (account == null) { throw new ArgumentNullException("account"); } var retVal = false; try { var entity = account.GetEntity(); if (entity == null) { throw new NullReferenceException(string.Format("Entity is null for Account ID: {0} with email: {1}", account.ID, account.EmailAddress)); } var entitytoUse = DB.Entities.FirstOrDefault(x => x.ID == entity.ID); var wealthItems = WealthService.GetWealthItems(account, excludeHiddenItem: true, includeDummyItems: false); var frequency = Convert.ToInt32(ConfigHelper.TryGetOrDefault("WealthItemSnapshotFrequency", "0")); var dateTimeToProcess = DateTime.Now.AddDays(-frequency).Date; CreateNetWealthSnapshot(account, period, entitytoUse, wealthItems); // if (dateTimeToProcess > account.LastSnapshotTaken) { // CreateNetWealthSnapshotTest(period, wealthItems); CreateWealthItemsSnapshot(period, wealthItems); } account.LastSnapshotTaken = DateTime.Now; // AccountService.UpdateAccount(account); DB.SaveChanges(); retVal = true; } catch (Exception ex) { ExceptionHelper.HandleException(RequestContext.Current, ex, false, account.EmailAddress); } return(retVal); } }