public void Update(Car entity) { Car found = null; if (cars.Contains(entity)) found = cars.FirstOrDefault(x => x.Id == entity.Id); if (found != null) found = entity; }
public int Add(Car data) { if (data != null) { repo.Add(data); return data.Id; } throw new ArgumentNullException(); }
public Car GetById(int id) { CheckSource(); Car getCar = new Car(); XElement element = xmlCars.Root.Descendants("Car").ElementAt<XElement>(id); getCar.Cost = float.Parse(element.Element("Cost").Value); getCar.Color = element.Element("Color").Value; getCar.Mark = element.Element("Mark").Value; getCar.TrunkId = int.Parse(element.Element("TrunkId").Value); return getCar; }
public IEnumerable<Car> GetAll() { CheckSource(); List<Car> cars = new List<Car>(); xmlCars = XDocument.Load(SourcePath); Car newCar = null; foreach (XElement el in xmlCars.Root.Elements()) { newCar = new Car(); newCar.Id = Convert.ToInt32(el.Element("Id").Value); newCar.Cost = float.Parse(el.Element("Cost").Value); newCar.Color = el.Element("Color").Value; newCar.Mark = el.Element("Mark").Value; newCar.TrunkId = int.Parse(el.Element("TrunkId").Value); cars.Add(newCar); } return cars; }
public void Add(Car entity) { CheckSource(); prevIndex++; entity.Id = prevIndex; XElement car = new XElement("Car"); XElement id = new XElement("Id",entity.Id); car.Add(id); XElement cost = new XElement("Cost", entity.Cost); car.Add(cost); XElement color = new XElement("Color", entity.Color); car.Add(color); XElement mark = new XElement("Mark", entity.Mark); car.Add(mark); XElement trunkId = new XElement("TrunkId", entity.TrunkId); car.Add(trunkId); xmlCars.Root.Add(car); //xmlCars = new XDocument(new XElement("Trunk", new XElement("Id", entity.Id), new XElement("Name", entity.Name), new XElement("Address", entity.Address))); xmlCars.Save(SourcePath); }
private void AddButton_Click(object sender, EventArgs e) { string chekingCost = CostBox.Text.Trim(); string chekingMark = MarkBox.Text.Trim(); string chekingColor = ColorBox.Text.Trim(); float cost; bool chekParse = float.TryParse(chekingCost, out cost); if (!string.IsNullOrEmpty(chekingCost) && !string.IsNullOrEmpty(chekingMark) && !string.IsNullOrEmpty(chekingColor) && chekParse && TrunkChoseBox.SelectedIndex > -1) { Car newCar = new Car(); newCar.Cost = cost; newCar.Mark = chekingMark; newCar.Color = chekingColor; Trunk selectedTrunk = (TrunkChoseBox.SelectedValue as Trunk); if (selectedTrunk != null) { newCar.TrunkId = selectedTrunk.Id; selectedTrunk.Cars.Add(newCar); selectedTrunk.CarCount++; using (TrunkProxy proxy = new TrunkProxy(Program.TrunkUrl)) { proxy.Update(selectedTrunk); //Program.trunkRepo.Update(selectedTrunk); } } using (CarProxy carproxy = new CarProxy(Program.CarUrl)) { carproxy.Add(newCar); } //Program.carRepo.Add(newCar); this.Close(); } else MessageBox.Show("Maybe, You forgot fill some fields or You enter a wrong cost or don't chose a trunk"); }
public void Update(Car data) { repo.Update(data); }
public void Remove(Car data) { repo.Remove(data); }
public void Update(Car entity) { CheckSource(); XElement element = xmlCars.Root.Descendants("Car").ElementAt<XElement>(entity.Id); element.Element("Cost").Value = entity.Cost.ToString(); element.Element("Color").Value = entity.Color; element.Element("Mark").Value = entity.Mark; element.Element("TrunkId").Value = entity.TrunkId.ToString(); xmlCars.Save(SourcePath); }
public void Remove(Car entity) { CheckSource(); xmlCars.Root.Descendants("Car").ElementAt<XElement>(entity.Id).Remove(); xmlCars.Save(SourcePath); }
public void Remove(Car entity) { if (cars.Contains(entity)) cars.Remove(entity); }
public void Add(Car entity) { prevIndex++; entity.Id = prevIndex; cars.Add(entity); }