Пример #1
0
        static void Main(string[] args)
        {
            const int NUMBER_OWNERS = 5;

            CarOwners[] carsOwners = new CarOwners[NUMBER_OWNERS];

            //lists of cars and owners
            List <Cars>      carList      = new List <Cars>();
            List <Customers> customerList = new List <Customers>();


            if (args.Length == 1 && args[0].Length > 0)
            {
                //read cars into list
                Console.WriteLine("\n" + "Types of cars:");
                if (ReadCars(args[0], carList))
                {
                    //read cars to user
                    foreach (Cars car in carList)
                    {
                        Console.WriteLine(car.Model + " " + car.Manufacturer + " " + car.Price);
                    }
                }
                else
                {
                    Console.WriteLine("Error reading file;");
                }
                //read customer
                Console.Write("\n" + "Enter customers.csv to load customer list: ");
                string custList = Console.ReadLine();
                Console.WriteLine("\n" + "Customers: ");
                if (ReadCustomer(custList, customerList))
                {
                    foreach (Customers cust in customerList)
                    {
                        Console.WriteLine(cust.Name + " " + cust.Phone + " " + cust.Email + " " + cust.Model);
                    }
                }
                else
                {
                    Console.WriteLine("Error reading file;");
                }

                //match and assign customers to their model information
                AssignMethod(carList, customerList, ref carsOwners);

                //save customer and their cars
                WriteCustomer(carsOwners, "Result.csv");

                //display joined array of customers and their cars
                DisplayCustomerCars(carsOwners);

                //search for car owner and display car price
                LinqSearchDisplay(carsOwners);
            }
            else
            {
                Console.WriteLine("Please enter file name/path");
            }
        }
Пример #2
0
        public void AddCarOwner()
        {
            var carOwner = new CarOwnerViewModel();

            CarOwners.Add(carOwner);
            CurrentOwner = carOwner;
        }
Пример #3
0
 public CarOwner GetCarOwnerByID(int id)
 {
     if (CarOwners.Any(p => p.ID == id))
     {
         return(CarOwners.First(p => p.ID == id));
     }
     return(null);
 }
Пример #4
0
 public void DeleteCarOwner(int id)
 {
     if (CarOwners.Any(p => p.ID == id))
     {
         CarOwners.Remove(CarOwners.First(p => p.ID == id));
     }
     fileDataAccess.SetModel(this);
 }
Пример #5
0
 public void AddCarOwner(CarOwner carOwner)
 {
     if (CarOwners.Any(p => p.ID == carOwner.ID))
     {
         var co = CarOwners.First(p => p.ID == carOwner.ID);
         co.Name       = carOwner.Name;
         co.Surname    = carOwner.Surname;
         co.SecondName = carOwner.SecondName;
         co.Phone      = carOwner.Phone;
         co.Birthday   = carOwner.Birthday;
     }
     else
     {
         iCarOwners++;
         carOwner.ID = iCarOwners;
         CarOwners.Add(carOwner);
     }
     fileDataAccess.SetModel(this);
 }
Пример #6
0
        //assign car info to customer with the same model
        private static void AssignMethod(List <Cars> carList, List <Customers> customerList, ref CarOwners[] carsOwners)
        {
            for (int i = 0; i < customerList.Count; i++)
            {
                for (int carCount = 0; carCount < carList.Count; carCount++)
                {
                    if (customerList[i].Model == carList[carCount].Model)
                    {
                        //assign customer and car info to struct
                        CarOwners ownerStruct = new CarOwners();
                        ownerStruct.custName        = customerList[i].Name;
                        ownerStruct.custEmail       = customerList[i].Email;
                        ownerStruct.custPhone       = customerList[i].Phone;
                        ownerStruct.custModel       = customerList[i].Model;
                        ownerStruct.carManufacturer = carList[carCount].Manufacturer;
                        ownerStruct.carPrice        = carList[carCount].Price;

                        //assign struct to list
                        carsOwners[i] = ownerStruct;
                    }
                }
            }
        }
Пример #7
0
 public List <CarOwner> GetCarOwners()
 {
     return(CarOwners.ToList());
 }