Пример #1
0
        public bool transact()
        {
            try
            {
                if (!AccountXmlLoader.checkIfExists(this.ReceiverID))
                {
                    throw new Exception("Receiver not found");
                }

                Account sender   = AccountXmlLoader.pull(this.SenderID);
                Account receiver = AccountXmlLoader.pull(this.ReceiverID);


                //no commision
                if (receiver.currency == this.currency)
                {
                    receiver.Balance += this.Sum;
                }
                else
                {
                    double defaultvalue          = this.Sum * (double)CurrencyProcessor.convertCoeficient(this.currency);
                    double receiverCurrencyValue =
                        defaultvalue / (double)CurrencyProcessor.convertCoeficient(receiver.currency);
                    receiver.Balance += receiverCurrencyValue;
                }
                AccountXmlLoader.update(receiver);
                this.Verified = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                this.Verified = false;
            }
            finally
            {
                TransactionXmlLoader.push(this);
            }
            return(this.Verified);
        }
Пример #2
0
        public static void update(Account ac)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(FILENAME);

            if (xmlDocument.SelectSingleNode($"//*[@id='{ac.AccountId}']") == null)
            {
                throw new Exception("Account not found");
            }
            XmlNode root = xmlDocument.DocumentElement;
            XmlNode xmlNode;
            //string balance = xmlDocument.SelectSingleNode($"//*[@id='{id}']")["Balance"].InnerText;
            List <Transaction> list = TransactionXmlLoader.pull(ac.AccountId);


            xmlNode           = root.SelectSingleNode($"//*[@id='{ac.AccountId}']")["Balance"];
            xmlNode.InnerText = ac.Balance.ToString();

            xmlNode           = root.SelectSingleNode($"//*[@id='{ac.AccountId}']")["currency"];
            xmlNode.InnerText = ac.currency.ToString();

            xmlNode           = root.SelectSingleNode($"//*[@id='{ac.AccountId}']")["ClientName"];
            xmlNode.InnerText = ac.ClientName.ToString();
            if (list != null)
            {
                xmlNode           = root.SelectSingleNode($"//*[@id='{ac.AccountId}']")["journal"];
                xmlNode.InnerText = "";
                foreach (Transaction transaction in list)
                {
                    XmlNode child = xmlDocument.CreateElement("transaction");
                    child.InnerText = transaction.ToString();
                    xmlNode.AppendChild(child);
                }
            }
            xmlDocument.Save(FILENAME);
        }