public void Update(Trunk entity) { Trunk found = null; if (trunks.Contains(entity)) found = trunks.FirstOrDefault(x => x.Id == entity.Id); if (found != null) found = entity; }
public Trunk GetById(int id) { CheckSource(); Trunk getTrunk = new Trunk(); XElement element = xmlTrunks.Root.Descendants("Trunk").ElementAt<XElement>(id); getTrunk.Name = element.Element("Name").Value; getTrunk.Address = element.Element("Address").Value; getTrunk.CarCount = int.Parse(element.Element("CarCount").Value); return getTrunk; }
public int Add(Trunk data) { if (data != null) { repo.Add(data); // add to cache return data.Id; } throw new ArgumentNullException(); }
public IEnumerable<Trunk> GetAll() { CheckSource(); List<Trunk> trunks = new List<Trunk>(); xmlTrunks = XDocument.Load(SourcePath); Trunk newTrunk = null; foreach (XElement el in xmlTrunks.Root.Elements()) { newTrunk = new Trunk(); newTrunk.Id = Convert.ToInt32(el.Element("Id").Value); newTrunk.Name = el.Element("Name").Value; newTrunk.Address = el.Element("Address").Value; newTrunk.CarCount = int.Parse(el.Element("CarCount").Value); newTrunk.Cars = new List<Car>(); trunks.Add(newTrunk); } return trunks; }
public void Add(Trunk entity) { CheckSource(); prevIndex++; entity.Id = prevIndex; XElement trunk = new XElement("Trunk"); XElement id = new XElement("Id", entity.Id); trunk.Add(id); XElement name = new XElement("Name", entity.Name); trunk.Add(name); XElement address = new XElement("Address", entity.Address); trunk.Add(address); XElement carCount = new XElement("CarCount", entity.CarCount); trunk.Add(carCount); xmlTrunks.Root.Add(trunk); //xmlTrunks = new XDocument(new XElement("Trunk", new XElement("Id", entity.Id), new XElement("Name", entity.Name), new XElement("Address", entity.Address))); xmlTrunks.Save(SourcePath); }
private void AddButton_Click(object sender, EventArgs e) { string chekingName = NameBox.Text.Trim(); string chekingAddress = AddressBox.Text.Trim(); if (!string.IsNullOrEmpty(chekingName) && !string.IsNullOrEmpty(chekingAddress)) { Trunk newTrunk = new Trunk(); newTrunk.Name = chekingName; newTrunk.Address = chekingAddress; using (TrunkProxy proxy = new TrunkProxy(Program.TrunkUrl)) { int id= proxy.Add(newTrunk); newTrunk.Id = id; } //Program.trunkRepo.Add(newTrunk); this.Close(); } else MessageBox.Show("You don't enter a trunk name or address"); }
public void Remove(Trunk entity) { if (trunks.Contains(entity)) trunks.Remove(entity); }
public void Add(Trunk entity) { prevIndex++; entity.Id = prevIndex; trunks.Add(entity); }
public void Update(Trunk data) { repo.Update(data); }
public void Remove(Trunk data) { repo.Remove(data); }
public void Update(Trunk entity) { CheckSource(); XElement element = xmlTrunks.Root.Descendants("Trunk").ElementAt<XElement>(entity.Id); element.Element("Name").Value = entity.Name; element.Element("Address").Value = entity.Address; element.Element("CarCount").Value = entity.CarCount.ToString(); xmlTrunks.Save(SourcePath); }
public void Remove(Trunk entity) { CheckSource(); xmlTrunks.Root.Descendants("Trunk").ElementAt<XElement>(entity.Id).Remove(); xmlTrunks.Save(SourcePath); }