Пример #1
0
        /// <summary>
        /// Gets the id of the Model that needs to be updated. Sets the new values based on the parameters.
        /// </summary>
        /// <param name="selected">id of the model that needs to be updated</param>
        /// <param name="name">updated name</param>
        /// <param name="productionStart">updated production start date.</param>
        /// <param name="engineSize">updated engine size.</param>
        /// <param name="horsePower">updated horsepower</param>
        /// <param name="startingPrice">updated starting price.</param>
        public void UpdateModelRepo(int selected, string name, DateTime?productionStart, int?engineSize, int?horsePower, int?startingPrice)
        {
            car_models model = this.DataBase.car_models
                               .Where(m => m.id == selected).First();

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

            if (productionStart != default(DateTime))
            {
                model.production_start = productionStart;
            }

            if (engineSize != default(int))
            {
                model.engine_size = engineSize;
            }

            if (horsePower != default(int))
            {
                model.horsepower = horsePower;
            }

            if (startingPrice != default(int))
            {
                model.starting_price = startingPrice;
            }

            this.DataBase.SaveChanges();
        }
Пример #2
0
        /// <summary>
        /// Creates new model in the Database based on the parameter.
        /// </summary>
        /// <param name="model">new model that needs to be created.</param>
        public void CreateModelRepo(car_models model)
        {
            int last_id = this.DataBase.car_models.Max(i => i.id);

            model.id = last_id + 1;
            this.DataBase.car_models.Add(model);
            this.DataBase.SaveChanges();
        }
Пример #3
0
 /// <summary>
 /// Deletes Model from the databse.
 /// </summary>
 /// <param name="model">model that needs to be delted.</param>
 public void DeleteModelRepo(car_models model)
 {
     try
     {
         this.DataBase.car_models.Remove(model);
         this.DataBase.SaveChanges();
     }
     catch (DbUpdateException e)
     {
         Console.WriteLine(e.InnerException.InnerException.Message);
         Console.ReadLine();
     }
 }
Пример #4
0
        /// <summary>
        /// Checks if the Model that needs to be deleted is proper. Searches based on Model Id.
        /// </summary>
        /// <param name="selection">Id of the model that needs to be deleted.</param>
        public void DeleteModel(string selection)
        {
            IEnumerable <car_models> models = this.repository.ListModelsRepo();

            IEnumerable <int> model_ids = models
                                          .Select(m => m.id);

            if (this.IsStringNumber(selection) && model_ids.Contains(int.Parse(selection)))
            {
                car_models toBeDeleted = models.Where(m => m.id == int.Parse(selection)).First();
                this.repository.DeleteModelRepo(toBeDeleted);
            }
            else
            {
                if (!this.IsStringNumber(selection))
                {
                    throw new InvalidParameterException("Invalid id. You have to select number");
                }
                else
                {
                    throw new InvalidParameterException("Conection cannot be found. Please select another one");
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Checks the parameters of the new model and forwards it to the repository if everything is correct.
        /// </summary>
        /// <param name="brandId">new id of the brand of the model</param>
        /// <param name="name">new name</param>
        /// <param name="startDate">new production start date</param>
        /// <param name="engineSize">new engine size</param>
        /// <param name="horsePower">new horspower</param>
        /// <param name="price">new price</param>
        public void CreateModelLogic(string brandId, string name, string startDate, string engineSize, string horsePower, string price)
        {
            car_models newModel = new car_models();
            int        newBrandId;
            DateTime   newDate   = this.SetDate(startDate);
            int        newEngine = this.SetIntValue(engineSize);
            int        newHorseP = this.SetIntValue(horsePower);
            int        newPrice  = this.SetIntValue(price);

            if (int.TryParse(brandId, out newBrandId) && this.BrandExists(newBrandId) && newDate != default(DateTime) && newEngine > 0 && newHorseP > 0 && newPrice > 0 && name != string.Empty)
            {
                newModel.name             = name;
                newModel.brand_id         = newBrandId;
                newModel.production_start = newDate;
                newModel.engine_size      = newEngine;
                newModel.horsepower       = newHorseP;
                newModel.starting_price   = newPrice;
                this.repository.CreateModelRepo(newModel);
            }
            else
            {
                throw new InvalidParameterException("Invalid values. Model cannot be created");
            }
        }
Пример #6
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 });
        }