Exemplo n.º 1
0
        public void DeleteInvestorCommitment(InvestorCommitment commitment)
        {
            using (HqTrustData dbContext = new HqTrustData())
            {
                InvestorCommitment old = dbContext.InvestorCommitmnents.
                                         FirstOrDefault(c => c.Id == commitment.Id);
                if (old == null)
                {
                    throw new Exception($"Das Commitment mit der Id {commitment.Id} für den Investor {commitment.InvestorId} wurde nicht in der Datenbank gefunden");
                }

                dbContext.InvestorCommitmnents.Remove(old);

                foreach (InvestorCommitmentDetail detail in commitment.InvestorCommitmentDetails)
                {
                    InvestorCommitmentDetail icDetail = dbContext.InvestorCommitmentDetails.FirstOrDefault(d => d.Id == detail.Id);
                    if (icDetail == null)
                    {
                        throw new Exception($"Das CommitmentDetail mit der Id {icDetail.Id} für das Commitment {old.Id} wurde nicht in der Datenbank gefunden");
                    }
                    dbContext.InvestorCommitmentDetails.Remove(icDetail);
                }
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("Das Commitment konnte in der Datenbank nicht gelöscht werden" + Environment.NewLine + ex.InnerException.Message);
                }
            }
        }
Exemplo n.º 2
0
        public void InsertInvestor(Investor investor)
        {
            //
            // UpdateClientAdvisor has updated investor.ClientAdvisor to a new clientadvisor
            //
            if (investor.ClientIsOwnAdvisor == true)
            {
                UpdateClientAdvisor(investor);
            }
            Investor newInvestor = investor.Copy(investor);

            newInvestor.BankAccounts       = new List <BankAccount>();
            newInvestor.DocumentAndLetters = new List <DocumentAndLetter>();
            newInvestor.TaxInformations    = new List <TaxInformation>();
            newInvestor.EMailAccounts      = new List <EMailAccount>();
            newInvestor.Currency           = new Currency();

            using (HqTrustData dbContext = new HqTrustData())
            {
                dbContext.Investors.Add(newInvestor);
                try
                {
                    dbContext.SaveChanges();
                    investor.Id = newInvestor.Id;
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Einfügen eines neuen Investors: {ex.InnerException.Message}");
                }
            }
            UpdateBankAccountsForInvestor(investor);
            UpdateDocumentAndLettersForInvestor(investor);
            UpdateTaxInformationsForInvestor(investor);
            UpdateEMailAccountsForInvestor(investor);
        }
Exemplo n.º 3
0
 /// <summary>
 /// takes each element within a List of InvestorPcap and inserts or updates the database
 /// </summary>
 /// <param name="pcaps">List<InvestorPcap></InvestorPcap> </param>
 public static void UpdateOrInsertPcaps(List <InvestorPcap> pcaps)
 {
     if (pcaps.Count() == 0)
     {
         return;
     }
     using (HqTrustData dbContext = new HqTrustData())
     {
         foreach (InvestorPcap pcap in pcaps)
         {
             if (pcap.Id == 0)
             {
                 dbContext.InvestorPcaps.Add(pcap);
             }
             else
             {
                 InvestorPcap existingPcap = dbContext.InvestorPcaps.FirstOrDefault(p => p.Id == pcap.Id);
                 if (existingPcap == null)
                 {
                     throw new Exception($"Das PCAP mit der Id {pcap.Id} wurde nicht gefunden");
                 }
                 dbContext.Entry(existingPcap).CurrentValues.SetValues(pcap);
             }
         }
         try
         {
             dbContext.SaveChanges();
         }
         catch (Exception ex)
         {
             throw new Exception($"Fehler beim Ändern der Tabelle InvestorPcaps. {ex.InnerException.Message}");
         }
     }
 }
 public static string GetApplicationInformation(string Key)
 {
     using (HqTrustData dbContext = new HqTrustData())
     {
         AnwendungsInformationen info = dbContext.AnwendungsInformationen.FirstOrDefault(a => a.Key == Key);
         if (info == null)
         {
             // if record is not found add Anwndungsinformation-Record
             info = new AnwendungsInformationen()
             {
                 Key   = Key,
                 Value = string.Empty
             };
             dbContext.AnwendungsInformationen.Add(info);
             try
             {
                 dbContext.SaveChanges();
             }
             catch (Exception)
             {
                 throw new Exception("Fehler beim Eintragen einer AnwendungsInformation");
             }
         }
         if (info.Value == null)
         {
             return(string.Empty);
         }
         else
         {
             return(info.Value);
         }
     }
 }
Exemplo n.º 5
0
        public int DeleteInvestorCashFlows(List <InvestorCashFlow> cashFlows)
        {
            int counter = 0;

            using (HqTrustData dbContext = new HqTrustData())
            {
                foreach (InvestorCashFlow cf in cashFlows)
                {
                    InvestorCashFlow item = dbContext.InvestorCashFlows.FirstOrDefault(c => c.Id == cf.Id);
                    if (item != null)
                    {
                        dbContext.InvestorCashFlows.Remove(item);
                    }
                    counter++;
                }
                try
                {
                    dbContext.SaveChanges();
                    return(counter);
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Löschen von Cashflows. {ex.InnerException.Message}");
                }
            }
        }
Exemplo n.º 6
0
 public static int GetUniqueCashFlowNumber(DateTime cfDate, int fundId)
 {
     using (HqTrustData dbContext = new HqTrustData())
     {
         UniqueCashFlowNumber record = new UniqueCashFlowNumber()
         {
             CashFlowDate = cfDate,
             PeFundId     = fundId
         };
         dbContext.UniqueCashFlowNumbers.Add(record);
         dbContext.SaveChanges();
         return(record.Id);
     }
 }
Exemplo n.º 7
0
        private static void UpdateDocumentAndLettersForPeFund(PeFund fund)
        {
            using (HqTrustData dbContext = new HqTrustData())
            {
                var existingDocs = dbContext.DocumentAndLetters.Where(b => b.PeFundId == fund.Id).ToList();

                // foreach account in existingAccounts try to find a record in investor.BankAccounts
                // if found --> update properties
                // if not found --> record was deleted by user --> remove account

                foreach (DocumentAndLetter document in existingDocs)
                {
                    DocumentAndLetter newDoc = fund.DocumentAndLetters.FirstOrDefault(b => b.Id == document.Id);
                    if (newDoc == null)
                    {
                        // not found --> remove
                        dbContext.DocumentAndLetters.Remove(document);
                    }
                    else
                    {
                        // found --> update properties
                        document.DocumentDate        = newDoc.DocumentDate;
                        document.DocumentDescription = newDoc.DocumentDescription;
                        document.DocumentFileName    = newDoc.DocumentFileName;
                        document.DocumentType        = newDoc.DocumentType;
                    }
                }


                foreach (DocumentAndLetter document in fund.DocumentAndLetters)
                {
                    if (document.Id != 0)
                    {
                        continue;
                    }
                    document.PeFundId   = fund.Id;
                    document.InvestorId = null;
                    dbContext.DocumentAndLetters.Add(document);
                }
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Einfügen eines neuen Private Equity Funds (Tabelle: DocumentAndLetters) Fehler: {ex.InnerException.Message}");
                }
            }
        }
Exemplo n.º 8
0
 public void InsertImportCommitment(ImportCommitment import)
 {
     using (HqTrustData dbContext = new HqTrustData())
     {
         dbContext.ImportCommitments.Add(import);
         try
         {
             dbContext.SaveChanges();
         }
         catch (Exception ex)
         {
             throw new Exception($"Fehler beim Einfügen eines PS Plus Commitments {ex.Message}");
         }
     }
 }
 public static void SetApplicationInformation(string key, string value)
 {
     using (HqTrustData dbContext = new HqTrustData())
     {
         AnwendungsInformationen info = dbContext.AnwendungsInformationen.FirstOrDefault(a => a.Key == key);
         if (info == null)
         {
             info = new AnwendungsInformationen()
             {
                 Key   = key,
                 Value = value
             };
             dbContext.AnwendungsInformationen.Add(info);
             try
             {
                 dbContext.SaveChanges();
             }
             catch (Exception)
             {
                 throw new Exception("Fehler beim Eintragen einer AnwendungsInformation");
             }
         }
         else
         {
             info.Value = value;
             try
             {
                 dbContext.SaveChanges();
             }
             catch (Exception)
             {
                 throw new Exception("Fehler beim Ändern einer AnwendungsInformation");
             }
         }
     }
 }
Exemplo n.º 10
0
        private void UpdateTaxInformationsForInvestor(Investor investor)
        {
            using (HqTrustData dbContext = new HqTrustData())
            {
                var existingTax = dbContext.TaxInformations.Where(b => b.InvestorId == investor.Id).ToList();

                // foreach account in existingAccounts try to find a record in investor.BankAccounts
                // if found --> update properties
                // if not found --> record was deleted by user --> remove account

                foreach (TaxInformation document in existingTax)
                {
                    TaxInformation newDoc = investor.TaxInformations.FirstOrDefault(b => b.Id == document.Id);
                    if (newDoc == null)
                    {
                        // not found --> remove
                        dbContext.TaxInformations.Remove(document);
                    }
                    else
                    {
                        // found --> update properties
                        document.CountryId = newDoc.CountryId;
                        document.Remarks   = newDoc.Remarks;
                        document.TaxIdentificationNumber = newDoc.TaxIdentificationNumber;
                        document.TaxStatus = newDoc.TaxStatus;
                    }
                }


                foreach (TaxInformation document in investor.TaxInformations)
                {
                    if (document.Id != 0)
                    {
                        continue;
                    }
                    document.InvestorId = investor.Id;
                    dbContext.TaxInformations.Add(document);
                }
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Einfügen eines neuen Investors (Tabelle: TaxInformations) Fehler: {ex.InnerException.Message}");
                }
            }
        }
Exemplo n.º 11
0
 public int AddInvestorCashFlows(List <InvestorCashFlow> cashFlows)
 {
     using (HqTrustData dbContext = new HqTrustData())
     {
         var entityList = dbContext.InvestorCashFlows.AddRange(cashFlows);
         try
         {
             dbContext.SaveChanges();
             return(entityList.Count());
         }
         catch (Exception ex)
         {
             throw new Exception($"Beim Eintragen von CashFlows ist ein Fehler aufgetreten: {ex.InnerException.Message}");
         }
     }
 }
Exemplo n.º 12
0
        private void UpdateEMailAccountsForInvestor(Investor investor)
        {
            using (HqTrustData dbContext = new HqTrustData())
            {
                var existingEmails = dbContext.EmailAccounts.Where(b => b.InvestorId == investor.Id).ToList();

                // foreach account in existingAccounts try to find a record in investor.BankAccounts
                // if found --> update properties
                // if not found --> record was deleted by user --> remove account

                foreach (EMailAccount document in existingEmails)
                {
                    EMailAccount newDoc = investor.EMailAccounts.FirstOrDefault(b => b.Id == document.Id);
                    if (newDoc == null)
                    {
                        // not found --> remove
                        dbContext.EmailAccounts.Remove(document);
                    }
                    else
                    {
                        // found --> update properties
                        document.EmailAddress = newDoc.EmailAddress;
                        document.Salutation   = newDoc.Salutation;
                    }
                }


                foreach (EMailAccount document in investor.EMailAccounts)
                {
                    if (document.Id != 0)
                    {
                        continue;
                    }
                    document.InvestorId = investor.Id;
                    dbContext.EmailAccounts.Add(document);
                }
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Einfügen eines neuen Investors (Tabelle: EMailAccounts) Fehler: {ex.InnerException.Message}");
                }
            }
        }
Exemplo n.º 13
0
        private void UpdateClientAdvisor(Investor investor)
        {
            // if investor.ClientAdvisorId == 0 Insert ClientAdviosr
            //                              else Update ClientAdvisor

            if (investor.ClientAdvisorId == null || investor.ClientAdvisorId == 0)
            {
                ClientAdvisor newAdvisor = new ClientAdvisor()
                {
                    Address     = investor.PrivateAddress,
                    AdvisorName = investor.IName,
                    IsClient    = true
                };
                using (HqTrustData dbContext = new HqTrustData())
                {
                    dbContext.ClientAdvisors.Add(newAdvisor);
                    try
                    {
                        dbContext.SaveChanges();
                        investor.ClientAdvisorId = newAdvisor.Id;
                        return;
                    }
                    catch (Exception)
                    {
                        throw new Exception("Fehler beim Einfügen eines Ansprechpartners");
                    }
                }
            }

            // Read Clientadvisor and set Address of Investor
            using (HqTrustData dbContext = new HqTrustData())
            {
                ClientAdvisor newAdvisor = dbContext.ClientAdvisors.FirstOrDefault(c => c.Id == investor.ClientAdvisorId);
                if (newAdvisor == null)
                {
                    throw new Exception("Ansprechpartner wurde nicht gefunden");
                }
                newAdvisor.AdvisorName = investor.IName;
                newAdvisor.Address     = investor.PrivateAddress;
                newAdvisor.IsClient    = true;
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 14
0
        public static void RemovePeFund(PeFund fund)
        {
            using (HqTrustData dbContext = new HqTrustData())
            {
                PeFund removefund = dbContext.PeFunds.FirstOrDefault(i => i.Id == fund.Id);
                if (removefund == null)
                {
                    throw new Exception($"Der Fund mit der Id {fund.Id} wurde in der Datenbank nicht gefunden.");
                }
                dbContext.PeFunds.Remove(removefund);

                try
                {
                    // remove related BankAccounts
                    var results = dbContext.BankAccounts.Where(b => b.PefundId == fund.Id).ToList();
                    if (results.Count > 0)
                    {
                        dbContext.BankAccounts.RemoveRange(results);
                    }

                    // remove related Documents and LetterInformation
                    var docs = dbContext.DocumentAndLetters.Where(e => e.PeFundId == fund.Id).ToList();
                    if (docs.Count > 0)
                    {
                        dbContext.DocumentAndLetters.RemoveRange(docs);
                    }
                }

                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Löschen von abhängigen Tabellen: {ex.InnerException.Message}");
                }
                // save changes
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Löschen des Funds. Ursache: {ex.InnerException.Message}");
                }
            }
        }
Exemplo n.º 15
0
 public static void UpdateInitiator(Initiator initiator)
 {
     if (initiator.Id == 0)
     {
         // add new Iniitiator
         using (HqTrustData dbContext = new HqTrustData())
         {
             dbContext.Initiators.Add(initiator);
             try
             {
                 dbContext.SaveChanges();
                 return;
             }
             catch (Exception ex)
             {
                 throw new Exception($"Fehler beim Hinzufügen eines Initiators. {ex.InnerException.Message}");
             }
         }
     }
     else
     {
         using (HqTrustData dbContext = new HqTrustData())
         {
             Initiator oldInitiator = dbContext.Initiators.FirstOrDefault(i => i.Id == initiator.Id);
             if (oldInitiator == null)
             {
                 throw new Exception($"Fehler beim Lesen des Initiators mit der Id {initiator.Id.ToString()}");
             }
             dbContext.Entry(oldInitiator).CurrentValues.SetValues(initiator);
             try
             {
                 dbContext.SaveChanges();
                 return;
             }
             catch (Exception ex)
             {
                 throw new Exception($"Fehler beim Ändern eines Initiators. {ex.InnerException.Message}");
             }
         }
     }
 }
Exemplo n.º 16
0
 public static void RemoveInitiator(Initiator initiator)
 {
     using (HqTrustData dbContext = new HqTrustData())
     {
         Initiator item = dbContext.Initiators.FirstOrDefault(i => i.Id == initiator.Id);
         if (item == null)
         {
             throw new Exception($"Fehler beim Lesen des Initiators mit der Id {initiator.Id.ToString()}");
         }
         try
         {
             dbContext.Initiators.Remove(item);
             dbContext.SaveChanges();
             return;
         }
         catch (Exception ex)
         {
             throw new Exception($"Fehler beim Löschen eines Initiators. {ex.InnerException.Message}");
         }
     }
 }
Exemplo n.º 17
0
 public void UpdateInvestorCashFlow(InvestorCashFlow cashflow)
 {
     if (cashflow.Id == 0)
     {
         using (HqTrustData dbContext = new HqTrustData())
         {
             dbContext.InvestorCashFlows.Add(cashflow);
             try
             {
                 dbContext.SaveChanges();
                 return;
             }
             catch (Exception ex)
             {
                 throw new Exception($"Fehler beim Einfügen eines CashFlows. {ex.InnerException.Message}");
             }
         }
     }
     else
     {
         using (HqTrustData dbContext = new HqTrustData())
         {
             InvestorCashFlow cf = dbContext.InvestorCashFlows.FirstOrDefault(c => c.Id == cashflow.Id);
             if (cf == null)
             {
                 throw new Exception($"Fehler beim Lesen eines CashFlows mit der Id {cashflow.Id}.");
             }
             dbContext.Entry(cf).CurrentValues.SetValues(cashflow);
             try
             {
                 dbContext.SaveChanges();
                 return;
             }
             catch (Exception ex)
             {
                 throw new Exception($"Fehler beim Ändern des CashFlows mit der Id {cashflow.Id}. {ex.InnerException.Message}");
             }
         }
     }
 }
Exemplo n.º 18
0
 public void InsertOrUpdateInvestorPcap(InvestorPcap pcap)
 {
     if (pcap.Id == 0)
     {
         // inser new record
         using (HqTrustData dbContext = new HqTrustData())
         {
             dbContext.InvestorPcaps.Add(pcap);
             try
             {
                 dbContext.SaveChanges();
             }
             catch (Exception ex)
             {
                 throw new Exception($"Fehler beim Eintragen eines PCap. {ex.InnerException.Message}");
             }
         }
     }
     else
     {
         using (HqTrustData dbContext = new HqTrustData())
         {
             InvestorPcap existingPcap = dbContext.InvestorPcaps.FirstOrDefault(p => p.Id == pcap.Id);
             if (existingPcap == null)
             {
                 throw new Exception($"Ein NAV für das Commitment {pcap.InvestorCommitmentId} mit dem Datum {pcap.AsOfDate:d} wurde nicht gefunden.");
             }
             dbContext.Entry(existingPcap).CurrentValues.SetValues(pcap);
             try
             {
                 dbContext.SaveChanges();
             }
             catch (Exception ex)
             {
                 throw new Exception($"Fehler beim Ändern eines PCap. {ex.InnerException.Message}");
             }
         }
     }
 }
Exemplo n.º 19
0
 public static void UpdatePeFund(PeFund fund)
 {
     using (HqTrustData dbContext = new HqTrustData())
     {
         PeFund updatePeFund = dbContext.PeFunds.FirstOrDefault(i => i.Id == fund.Id);
         if (updatePeFund == null)
         {
             throw new Exception($"Der Fund mit der Id {fund.Id} wurde nicht in der Datenbank gefunden");
         }
         dbContext.Entry(updatePeFund).CurrentValues.SetValues(fund);
         try
         {
             dbContext.SaveChanges();
         }
         catch (Exception ex)
         {
             throw new Exception($"Fehler beim Ändern eines PeFunds: {ex.InnerException.Message}");
         }
     }
     UpdateBankAccountsForPeFund(fund);
     UpdateDocumentAndLettersForPeFund(fund);
 }
Exemplo n.º 20
0
        public static void InsertPeFund(PeFund fund)
        {
            PeFund newFund = fund.Copy(fund);

            newFund.BankAccounts       = new System.Collections.ObjectModel.ObservableCollection <BankAccount>();
            newFund.DocumentAndLetters = new System.Collections.ObjectModel.ObservableCollection <DocumentAndLetter>();

            using (HqTrustData dbContext = new HqTrustData())
            {
                dbContext.PeFunds.Add(newFund);
                try
                {
                    dbContext.SaveChanges();
                    fund.Id = newFund.Id;
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Einfügen eines neuen Private Equity Funds: {ex.InnerException.Message}");
                }
            }
            UpdateBankAccountsForPeFund(fund);
            UpdateDocumentAndLettersForPeFund(fund);
        }
Exemplo n.º 21
0
 public void UpdateInvestor(Investor investor)
 {
     using (HqTrustData dbContext = new HqTrustData())
     {
         Investor updateInvestor = dbContext.Investors.FirstOrDefault(i => i.Id == investor.Id);
         if (updateInvestor == null)
         {
             throw new Exception($"Der Investor mit der Id {investor.Id} wurde nicht in der Datenbank gefunden");
         }
         dbContext.Entry(updateInvestor).CurrentValues.SetValues(investor);
         try
         {
             dbContext.SaveChanges();
         }
         catch (Exception ex)
         {
             throw new Exception($"Fehler beim Ändern eines Investors: {ex.InnerException.Message}");
         }
     }
     UpdateBankAccountsForInvestor(investor);
     UpdateDocumentAndLettersForInvestor(investor);
     UpdateTaxInformationsForInvestor(investor);
     UpdateEMailAccountsForInvestor(investor);
 }
Exemplo n.º 22
0
        /// <summary>
        /// Removes an investor and the related bankaccounts, EMailAccounts, taxinformation, Todos and documents from the database
        /// </summary>
        /// <param name="investor"></param>
        public void RemoveInvestor(Investor investor)
        {
            using (HqTrustData dbContext = new HqTrustData())
            {
                Investor removeInvestor = dbContext.Investors.FirstOrDefault(i => i.Id == investor.Id);
                if (removeInvestor == null)
                {
                    throw new Exception($"Der Investor mit der Id {investor.Id} wurde in der Datenbank nicht gefunden.");
                }
                dbContext.Investors.Remove(removeInvestor);

                try
                {
                    // remove related BankAccounts
                    var results = dbContext.BankAccounts.Where(b => b.InvestorId == investor.Id).ToList();
                    if (results.Count > 0)
                    {
                        dbContext.BankAccounts.RemoveRange(results);
                    }

                    // remove related E-MailAccounts
                    var emails = dbContext.EmailAccounts.Where(e => e.InvestorId == investor.Id).ToList();
                    if (emails.Count > 0)
                    {
                        dbContext.EmailAccounts.RemoveRange(emails);
                    }

                    // remove related TaxInformation
                    var taxes = dbContext.TaxInformations.Where(e => e.InvestorId == investor.Id).ToList();
                    if (taxes.Count > 0)
                    {
                        dbContext.TaxInformations.RemoveRange(taxes);
                    }

                    // remove related Documents and LetterInformation
                    var docs = dbContext.DocumentAndLetters.Where(e => e.InvestorId == investor.Id).ToList();
                    if (docs.Count > 0)
                    {
                        dbContext.DocumentAndLetters.RemoveRange(docs);
                    }

                    // remove related Todos
                    var todos = dbContext.InvestorToDos.Where(e => e.InvestorId == investor.Id).ToList();
                    if (todos.Count > 0)
                    {
                        dbContext.InvestorToDos.RemoveRange(todos);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Löschen von abhängigen Tabellen: {ex.InnerException.Message}");
                }



                // save changes
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Löschen des Investors. Ursache: {ex.InnerException.Message}");
                }
            }
        }
Exemplo n.º 23
0
        public InvestorCommitment UpdateInvestorCommitments(InvestorCommitment commitment)
        {
            if (commitment.Id == 0)
            {
                // add new commitment
                using (HqTrustData dbContext = new HqTrustData())
                {
                    InvestorCommitment newCommitment = new InvestorCommitment(commitment);
                    newCommitment.PeFund = null;
                    dbContext.InvestorCommitmnents.Add(newCommitment);
                    try
                    {
                        dbContext.SaveChanges();
                        return(newCommitment);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Das Commitment konnte nicht in der Datenbank gespeichert werden" + Environment.NewLine + ex.InnerException.Message);
                    }
                }
            }
            else
            {
                // update commitments
                using (HqTrustData dbContext = new HqTrustData())
                {
                    InvestorCommitment old = dbContext.InvestorCommitmnents.
                                             Include("InvestorCommitmentDetails").
                                             FirstOrDefault(c => c.Id == commitment.Id);
                    if (old == null)
                    {
                        throw new Exception($"Das Commitment mit der Id {commitment.Id} für den Investor {commitment.InvestorId} wurde nicht in der Datenbank gefunden");
                    }
                    old.BankAccountId           = commitment.BankAccountId;
                    old.CommitmentAmount        = commitment.CommitmentAmount;
                    old.CommitmentPlannedAmount = commitment.CommitmentPlannedAmount;
                    old.DateCommitmentAccepted  = commitment.DateCommitmentAccepted;
                    old.PeFundReference         = commitment.PeFundReference;

                    try
                    {
                        dbContext.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Das Commitment konnte in der Datenbank nicht geändert werden" + Environment.NewLine + ex.InnerException.Message);
                    }


                    //foreach(InvestorCommitmentDetail detail in old.InvestorCommitmentDetails)
                    for (int i = 0; i < old.InvestorCommitmentDetails.Count; i++)
                    {
                        InvestorCommitmentDetail detail    = old.InvestorCommitmentDetails.ElementAt(i);
                        InvestorCommitmentDetail oldDetail = dbContext.InvestorCommitmentDetails.FirstOrDefault(d => d.Id == detail.Id);
                        if (oldDetail == null)
                        {
                            throw new Exception($"Das CommitmentDetail mit der Id {detail.Id} für das Commitment {old.Id} wurde nicht in der Datenbank gefunden");
                        }
                        InvestorCommitmentDetail newDetail = commitment.InvestorCommitmentDetails.FirstOrDefault(n => n.Id == detail.Id);
                        if (newDetail == null)
                        {
                            // record has been delete by the user:
                            dbContext.InvestorCommitmentDetails.Remove(oldDetail);

                            dbContext.SaveChanges();
                        }
                        else
                        {
                            oldDetail.CommitmentAmount                  = newDetail.CommitmentAmount;
                            oldDetail.CommitmentDate                    = newDetail.CommitmentDate;
                            oldDetail.SecondaryCallsAfterCutOff         = newDetail.SecondaryCallsAfterCutOff;
                            oldDetail.SecondaryCutOffDate               = newDetail.SecondaryCutOffDate;
                            oldDetail.SecondaryDistributionsAfterCutOff = newDetail.SecondaryDistributionsAfterCutOff;
                            oldDetail.SecondaryOpenCommitment           = newDetail.SecondaryOpenCommitment;
                            oldDetail.SecondaryPurchaseAmount           = newDetail.SecondaryPurchaseAmount;

                            dbContext.SaveChanges();
                        }
                    }

                    foreach (InvestorCommitmentDetail detail in commitment.InvestorCommitmentDetails)
                    {
                        if (detail.Id > 0)
                        {
                            continue;
                        }
                        dbContext.InvestorCommitmentDetails.Add(detail);
                    }

                    try
                    {
                        dbContext.SaveChanges();
                        return(commitment);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Das Commitment konnte in der Datenbank nicht geändert werden" + Environment.NewLine + ex.InnerException.Message);
                    }
                }
            }
        }
Exemplo n.º 24
0
        private static void UpdateBankAccountsForPeFund(PeFund fund)
        {
            using (HqTrustData dbContext = new HqTrustData())
            {
                var existingAccounts = dbContext.BankAccounts.Where(b => b.PefundId == fund.Id).ToList();

                // foreach account in existingAccounts try to find a record in investor.BankAccounts
                // if found --> update properties
                // if not found --> record was deleted by user --> remove account

                foreach (BankAccount account in existingAccounts)
                {
                    BankAccount newAccount = fund.BankAccounts.FirstOrDefault(b => b.Id == account.Id);
                    if (newAccount == null)
                    {
                        // not found --> remove
                        dbContext.BankAccounts.Remove(account);
                    }
                    else
                    {
                        // found --> update properties
                        account.AccountHolder          = newAccount.AccountHolder;
                        account.AccountNumber          = newAccount.AccountNumber;
                        account.AdditionalInstructions = newAccount.AdditionalInstructions;
                        account.BankAddress            = newAccount.BankAddress;
                        account.BankContactId          = newAccount.BankContactId;
                        account.BankName             = newAccount.BankName;
                        account.BankNumberBlz        = newAccount.BankNumberBlz;
                        account.BeneficiaryBank      = newAccount.BeneficiaryBank;
                        account.CurrencyId           = newAccount.CurrencyId;
                        account.FfcAccountHolderName = newAccount.FfcAccountHolderName;
                        account.FfcAccountNumber     = newAccount.FfcAccountNumber;
                        account.Iban         = newAccount.Iban;
                        account.InvestorId   = null;
                        account.PefundId     = fund.Id;
                        account.Signature1   = newAccount.Signature1;
                        account.Signature2   = newAccount.Signature2;
                        account.SwiftAddress = newAccount.SwiftAddress;
                    }
                }


                foreach (BankAccount account in fund.BankAccounts)
                {
                    if (account.Id != 0)
                    {
                        continue;
                    }
                    account.PefundId   = fund.Id;
                    account.InvestorId = null;
                    dbContext.BankAccounts.Add(account);
                }
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Einfügen eines neuen Private Equity Funds (Tabelle: BankAccounts) Fehler: {ex.InnerException.Message}");
                }
            }
        }