public FundInvestmentModel(FundInvestment fundInvestement) { //Id = fundInvestement.Id; }
public static void Update(FundInvestment investement) { MongoDBContext _client = new MongoDBContext(_settings.MongoDBConnectionString); _client.SaveDocument <FundInvestment>(investement, FUND_INVESTMENTS_COLLECTION); }
private static void SaveDailyActivity(Dictionary <Entity, List <Investment> > dic) { if (dic.Count == 0) { return; } Dictionary <Entity, List <Investment> > toSave = new Dictionary <Entity, List <Investment> >(); foreach (var item in dic) { toSave.Add(item.Key, item.Value); } #region Update FundInvestment existant try { List <FundInvestment> existingFundInvestments = InvestmentDataAccess.FindExistingInvestments(toSave.Select(i => i.Key.Id).ToList()); if (existingFundInvestments.Count > toSave.Count) { Log.Error("SaveDailyActivity", "Too much FundInvestment found"); return; } foreach (var fundInvestment in existingFundInvestments) { var current = toSave.FirstOrDefault(i => i.Key.Id == fundInvestment.Fund.Id); Entity fund = current.Key; List <Investment> updatedInvestments = fundInvestment.Investments; bool newInvestment = false; foreach (var invest in current.Value) { // vérifie que l'investissement courant n'existe pas dans l'investissement existant Investment investement = fundInvestment.Investments.FirstOrDefault(i => i.Id == invest.Id); if (investement == null) { updatedInvestments.Add(invest); newInvestment = true; } else { toSave.Remove(fund); } } if (newInvestment) { var updatedFundInvestment = new FundInvestment(fundInvestment, fund, updatedInvestments); InvestmentDataAccess.Update(updatedFundInvestment); Log.Info("SaveDailyActivity", "Update fund investments", string.Format("{0} in {1}", updatedFundInvestment.Fund.Name, string.Join(", ", updatedFundInvestment.Investments.Select(investment => investment.Startup.Name)))); } } } catch (Exception ex) { Log.Error("SaveDailyActivity", "Update", ex); throw; } #endregion #region Insert nouveau FundInvestment try { if (toSave.Any()) { List <FundInvestment> investments = new List <FundInvestment>(); foreach (var item in toSave) { investments.Add(new FundInvestment() { Fund = item.Key, Investments = item.Value, LastUpdate = DateTime.UtcNow }); } InvestmentDataAccess.SaveDailyActivity(investments); Log.Info("SaveDailyActivity", "New funds investments", string.Join(", ", investments.ToString())); } else { Log.Info("SaveDailyActivity", "No new fund investment"); } } catch (Exception ex) { Log.Error("SaveDailyActivity", "Insert", ex); throw; } #endregion }