예제 #1
0
        /// <summary>
        /// Gets the id of the Extra that needs to be updated. Sets the new values based on the parameters.
        /// </summary>
        /// <param name="selected">id of the extra that needs to be updated</param>
        /// <param name="catname">updated category name</param>
        /// <param name="name">updated name of the extra</param>
        /// <param name="price">updated price </param>
        /// <param name="newReuse">updated value of reuseable field.</param>
        public void UpdateExtraRepo(int selected, string catname, string name, int price, int newReuse)
        {
            extra extra = this.DataBase.extras
                          .Where(e => e.id == selected).First();

            if (catname != string.Empty)
            {
                extra.category_name = catname;
            }

            if (name != string.Empty)
            {
                extra.name = name;
            }

            if (price != default(int))
            {
                extra.price = price;
            }

            if (newReuse != default(int))
            {
                extra.reuseable = (byte)newReuse;
            }

            this.DataBase.SaveChanges();
        }
예제 #2
0
        /// <summary>
        /// Creates new extra in the Database based on the parameter.
        /// </summary>
        /// <param name="newExtra">new extra that needs to be created.</param>
        public void CreateExtraRepo(extra newExtra)
        {
            int last_id = this.DataBase.extras.Max(i => i.id);

            newExtra.id = last_id + 1;
            this.DataBase.extras.Add(newExtra);
            this.DataBase.SaveChanges();
        }
예제 #3
0
 /// <summary>
 /// Deletes Extra from the databse.
 /// </summary>
 /// <param name="extra">extra that needs to be delted.</param>
 public void DeleteExtraRepo(extra extra)
 {
     try
     {
         this.DataBase.extras.Remove(extra);
         this.DataBase.SaveChanges();
     }
     catch (DbUpdateException e)
     {
         Console.WriteLine(e.InnerException.InnerException.Message);
         Console.ReadLine();
     }
 }
예제 #4
0
        /// <summary>
        /// Checks the parameters of the new extra and forwards it to the repository if everything is correct.
        /// </summary>
        /// <param name="categoryName">new categpory name for the extra</param>
        /// <param name="extraName"> nam eof the new extra</param>
        /// <param name="color">color of the extra</param>
        /// <param name="price">new price </param>
        /// <param name="reusable">value of the reusable field of the new extra</param>
        public void CreateExtraLogic(string categoryName, string extraName, string color, string price, string reusable)
        {
            extra newExtra  = new extra();
            int   newPrice  = this.SetIntValue(price);
            int   reuseAble = this.SetIntValue(reusable);

            if (categoryName != string.Empty && extraName != string.Empty && newPrice > 0 && reuseAble >= 0 && reuseAble <= 1)
            {
                newExtra.category_name = categoryName;
                newExtra.name          = extraName;
                newExtra.color         = color;
                newExtra.price         = newPrice;
                newExtra.reuseable     = (byte)reuseAble;
                this.repository.CreateExtraRepo(newExtra);
            }
            else
            {
                throw new InvalidParameterException("Invalid parmeters. Extra cannot be created");
            }
        }
예제 #5
0
        /// <summary>
        /// Checks if the Extra that needs to be deleted is proper. Searches based on Extra Id.
        /// </summary>
        /// <param name="selection">Id of the extra that needs to be deleted.</param>
        public void DeleteExtra(string selection)
        {
            IEnumerable <extra> extras    = this.repository.ListExtraRepo();
            IEnumerable <int>   extra_ids = extras.Select(x => x.id);

            if (this.IsStringNumber(selection) && extra_ids.Contains(int.Parse(selection)))
            {
                extra toBeDeleted = extras.Where(x => x.id == int.Parse(selection)).First();
                this.repository.DeleteExtraRepo(toBeDeleted);
            }
            else
            {
                if (!this.IsStringNumber(selection))
                {
                    throw new InvalidParameterException("Invalid id. You have to select number");
                }
                else
                {
                    throw new InvalidParameterException("Extra cannot be found. Please select another one");
                }
            }
        }
예제 #6
0
 void IHasExtra.Add(extra ChildExtra)
 {
     if(Extras == null)
         Extras	= new List<extra>();
     Extras.Add(ChildExtra);
 }
예제 #7
0
        public void Setup()
        {
            this.mockedRepository = new Mock <ICarRepository>();

            car_brands brand1 = new car_brands()
            {
                id = 1, name = "Ferari", url = "valami", country = "hungary"
            };
            car_brands brand2 = new car_brands()
            {
                id = 2, name = "Lambo", url = "semmi", country = "italy"
            };
            car_brands brand3 = new car_brands()
            {
                id = 3, name = "Peugeot", url = "halad", country = "france"
            };

            this.mockedRepository
            .Setup(m => m.ListBrandsRepo())
            .Returns(new[] { brand1, brand2, brand3 });

            car_models model1 = new car_models()
            {
                id = 1, brand_id = 2, name = "MurceLago", horsepower = 300
            };
            car_models model2 = new car_models()
            {
                id = 2, brand_id = 1, name = "Testarosa", horsepower = 120
            };
            car_models model3 = new car_models()
            {
                id = 3, brand_id = 3, name = "406", horsepower = 60
            };

            this.mockedRepository
            .Setup(m => m.ListModelsRepo())
            .Returns(new[] { model1, model2, model3 });

            extra extra1 = new extra()
            {
                id = 1, name = "turbo", category_name = "Engine", price = 20
            };
            extra extra2 = new extra()
            {
                id = 2, name = "air conditioning", category_name = "Interior", price = 20
            };
            extra extra3 = new extra()
            {
                id = 3, name = "dark windows", category_name = "Exterior", price = 20
            };

            this.mockedRepository
            .Setup(m => m.ListExtraRepo())
            .Returns(new[] { extra1, extra2, extra3 });

            model_extra_connection connection1 = new model_extra_connection()
            {
                id = 1, extra_id = 1, model_id = 1
            };
            model_extra_connection connection2 = new model_extra_connection()
            {
                id = 2, extra_id = 1, model_id = 3
            };
            model_extra_connection connection3 = new model_extra_connection()
            {
                id = 3, extra_id = 2, model_id = 4
            };

            this.mockedRepository
            .Setup(m => m.ListExtraConnectionRepo())
            .Returns(new[] { connection1, connection2, connection3 });
        }
예제 #8
0
    public static void Main()
    {
        extra       E = new extra();
        Requirments R = new Requirments();
        Algorithms  A = new Algorithms();


        //R.array= read_single("Open_128.txt");
        //A.sort(R.array);
        //E.print(R.array);



        //reference arrays
        string[] names      = { "Change_1024.txt", "Change_256.txt", "Change_128.txt", "Close_1024.txt", "Close_256.txt", "Close_128.txt", "High_1024.txt", "High_256.txt", "High_128.txt", "Low_1024.txt", "Low_256.txt", "Low_128.txt", "Open_1024.txt", "Open_256.txt", "Open_128.txt" };
        string[] algorithms = { "bubble_sort", "quick_sort", "merge_sort", "insertion_sort", "binary_search", "linear_search" };


        Console.Clear();
        int count = 0;

        foreach (string s in names)
        {
            Console.WriteLine("({0}) {1} ", count, s);
            count++;
        }                //prints the names of the arrays
                         //part of the display


        //gets user input of which array they want
        Console.WriteLine("Please choose one off the arrays by typing the refernce number to the left");
        int input1;                //array needed

        while (true)
        {
            while (!int.TryParse(Console.ReadLine(), out input1))                    //only runs if its not a number
            {
                Console.WriteLine("please enter a valid number");
            }
            if (input1 >= 0 && input1 <= 14)                    //makes sure input is within the list range
            {
                break;
            }
        }

        R.array = read_single(names[input1]);                //creates and array of selected file
        //its stored in Requirements


        //this sections gets the direction of the sorted array
        while (true)
        {
            Console.WriteLine("would you like it in accending or decending order A/D");
            R.order = Console.ReadLine();
            R.order = R.order.ToLower();

            if (R.order == "a")
            {
                Console.WriteLine("you've chosen accending order");
                break;
            }

            if (R.order == "d")
            {
                Console.WriteLine("you've chosen decending order");
                break;
            }
            else
            {
                Console.WriteLine("please choose a valid input");
            }
        }
        Console.ReadKey();
        //R.order is set here



        //the following section is for getting the algorithm
        Console.Clear();
        count = 0;                 // resets count from before
        foreach (string s in algorithms)
        {
            Console.WriteLine("({0}) {1} ", count, s);
            count++;
        }                //prints the algorithm names

        Console.WriteLine("please enter the reference number of an algorithm on the left");

        int process;

        while (true)
        {
            while (!int.TryParse(Console.ReadLine(), out process))                    //only runs if its not a number
            {
                Console.WriteLine("not a valid reference");
            }
            if (process >= 0 && process <= 5)                    //makes sure input is within the list range
            {
                break;
            }
        }


        switch (process)
        {
        case 0:
        {
            Console.Clear();
            Console.WriteLine("bubble_sort");
            A.bubble(R.array);
            R.iterations = A.counter;
            A.counter    = 0;
            E.print(R.array, R.order, R.iterations);



            break;
        }

        case 1:
        {
            Console.Clear();
            Console.WriteLine("quick_sort");
            A.QuickSort(R.array);
            R.iterations = A.counter;
            A.counter    = 0;
            E.print(R.array, R.order, R.iterations);


            break;
        }

        case 2:
        {
            Console.Clear();
            Console.WriteLine("merge_sort");
            R.array      = A.MergeSort(R.array);
            R.iterations = A.counter;
            A.counter    = 0;
            E.print(R.array, R.order, R.iterations);

            break;
        }

        case 3:
        {
            Console.Clear();
            Console.WriteLine("insertion_sort");
            A.insertionsort(R.array);
            R.iterations = A.counter;
            A.counter    = 0;
            E.print(R.array, R.order, R.iterations);


            break;
        }

        case 4:
        {                        //iterations is still broken on this
            Console.Clear();
            Console.WriteLine("binary_search");
            A.QuickSort(R.array);
            E.print(R.array, R.order);
            A.counter = 0;
            int result = A.binary_search(R.array);
            Console.WriteLine("iterations:{0}", R.iterations);
            if (result >= 0)
            {
                Console.WriteLine("your search was found at index:{0}", result);
            }
            else
            {
                Console.WriteLine();
            }



            break;
        }

        case 5:
        {
            Console.Clear();
            Console.WriteLine("linear_search");
            A.QuickSort(R.array);
            E.print(R.array, R.order);
            A.linear(R.array);
            R.iterations = A.counter;
            A.counter    = 0;



            break;
        }

        default:
            break;
        }                //switch statement

        Console.WriteLine();
        Console.WriteLine("go again? y/n");
        string input = Console.ReadLine();

        input = input.ToLower();

        if (input == "y")
        {
            Main();
        }
    }    //main