public static void Action(User user) { bool flag = true; XmlParser xmlp = new XmlParser(); user.Сalculation(); xmlp.UpdateUser(user, "../../xmls/Users.xml", "user", "id", user.GetId().ToString()); do { switch (Menu()) { case 1: Console.WriteLine("Сумма:" + user.showCashAmount()); HistoryUnit log = new HistoryUnit(); log.Date = DateTime.Today; log.Operation = "Запрос баланса пользователем"; xmlp.UpdateUserHistory(log, user.fio); break; case 2: Console.WriteLine("Введите сумму, которую хотите добавить "); double money = Double.Parse(Console.ReadLine()); user.addFund(money); HistoryUnit log2 = new HistoryUnit(); log2.Date = DateTime.Today; log2.Operation = "Зачислено " + money + " денежных единиц на счёт"; xmlp.UpdateUserHistory(log2, user.fio); xmlp.UpdateUser(user, "../../xmls/Users.xml", "user", "id", user.GetId().ToString()); break; case 3: Console.WriteLine("Введите сумму, которую хотите снять "); double moneyOut = Double.Parse(Console.ReadLine()); user.getProfit(moneyOut); HistoryUnit log3 = new HistoryUnit(); log3.Date = DateTime.Today; log3.Operation = "Снято " + moneyOut + " денежных единиц со счёта"; xmlp.UpdateUserHistory(log3, user.fio); xmlp.UpdateUser(user, "../../xmls/Users.xml", "user", "id", user.GetId().ToString()); break; case 4: Console.WriteLine("Выписка: "); foreach (HistoryUnit hu in xmlp.ReadUserHistory(user.fio)) { if (hu.Date >= DateTime.Today.AddMonths(-1)) { System.Console.WriteLine("\n"); System.Console.WriteLine(hu.Date); System.Console.WriteLine(hu.Operation); System.Console.WriteLine("==================="); } } break; case 5: Console.WriteLine("Вы действительно хотите закрыть свой депозит??? 1 - Да 2 - Нет. "); int decision = Int32.Parse(Console.ReadLine()); if (decision == 1) { xmlp.DeleteRootInFileByRootnameAndId("../../xmls/Users.xml", "user", "id", user.GetId().ToString()); flag = false; } else break; break; case 0: flag = false; break; } } while (flag); }
public bool UpdateUser(User usr, String file, String rootName, String idName, String id) { XDocument doc = XDocument.Load(usersFile); IEnumerable<XElement> entities = doc.Root.Descendants(rootName).Where( t => t.Element(idName).Value.Equals(id)).ToList(); if (entities.Count() != 0) { foreach (XElement t in entities) { t.SetElementValue("id", usr.GetId()); t.SetElementValue("FIO", usr.GetFIO()); t.SetElementValue("summa", usr.GetSumma()); t.SetElementValue("nameDeposit", usr.GetNameDeposit()); t.SetElementValue("date", usr.GetDate()); } doc.Save(file); return true; } else return false; }