예제 #1
0
        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;
        }
예제 #2
0
        public int Add(Car data)
        {
            if (data != null)
            {
                repo.Add(data);
                return data.Id;
            }

            throw new ArgumentNullException();
        }
예제 #3
0
 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;
 }
예제 #4
0
 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;
 }
예제 #5
0
 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);
 }
예제 #6
0
        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");
        }
예제 #7
0
 public void Update(Car data)
 {
     repo.Update(data);
 }
예제 #8
0
 public void Remove(Car data)
 {
     repo.Remove(data);
 }
예제 #9
0
 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);
 }
예제 #10
0
 public void Remove(Car entity)
 {
     CheckSource();
     xmlCars.Root.Descendants("Car").ElementAt<XElement>(entity.Id).Remove();
     xmlCars.Save(SourcePath);
 }
예제 #11
0
 public void Remove(Car entity)
 {
     if (cars.Contains(entity))
         cars.Remove(entity);
 }
예제 #12
0
 public void Add(Car entity)
 {
     prevIndex++;
     entity.Id = prevIndex;
     cars.Add(entity);
 }