示例#1
0
        /// <summary>
        /// Calls repository to update selected brand.
        /// </summary>
        /// <param name="id">id of the brand that needs to be updated </param>
        /// <param name="name">updated name</param>
        /// <param name="country">updated country</param>
        /// <param name="founded">updated foundation date</param>
        /// <param name="revenue">updated revenue</param>
        public void UpdateBrandRepo(int id, string name, string country, DateTime?founded, int?revenue)
        {
            // returns the selected brand
            car_brands brand = this.DataBase.car_brands
                               .Where(b => b.id == id).First();

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

            if (country != string.Empty)
            {
                brand.country = country;
            }

            if (founded != default(DateTime))
            {
                brand.founded = founded;
            }

            if (revenue != default(int))
            {
                brand.yearly_revenue = revenue;
            }

            Console.ReadLine();
            this.DataBase.SaveChanges();
        }
示例#2
0
        /// <summary>
        /// Creates new brand in the Database based on the parameter.
        /// </summary>
        /// <param name="brand">new brand parameter.</param>
        public void CreateBrandRepo(car_brands brand)
        {
            int last_id = this.DataBase.car_brands.Max(i => i.id);

            brand.id = last_id + 1;
            this.DataBase.car_brands.Add(brand);
            this.DataBase.SaveChanges();
        }
示例#3
0
 /// <summary>
 /// Deletes Brand from the databse.
 /// </summary>
 /// <param name="brand">brand that needs to be delted.</param>
 public void DeleteBrandRepo(car_brands brand)
 {
     try
     {
         this.DataBase.car_brands.Remove(brand);
         this.DataBase.SaveChanges();
     }
     catch (DbUpdateException e)
     {
         Console.WriteLine(e.InnerException.InnerException.Message);
         Console.ReadLine();
     }
 }
示例#4
0
        /// <summary>
        /// Checks the parameters of the new brand and forwards it to the repository if everything is correct.
        /// </summary>
        /// <param name="name">new name</param>
        /// <param name="country">new country</param>
        /// <param name="url">new url it can be null</param>
        /// <param name="foundationDate">new date </param>
        /// <param name="revenue">new reveneu </param>
        public void CreateBrandLogic(string name, string country, string url, string foundationDate, string revenue)
        {
            car_brands newBrand   = new car_brands();
            int        newRevenue = this.SetIntValue(revenue);
            DateTime   newDate    = this.SetDate(foundationDate);

            if (name == string.Empty || country == string.Empty || newDate == default(DateTime) || newRevenue <= 0)
            {
                throw new InvalidParameterException("Invalid values. Brand cannot be created");
            }
            else
            {
                newBrand.name           = name;
                newBrand.country        = country;
                newBrand.url            = url;
                newBrand.founded        = newDate;
                newBrand.yearly_revenue = newRevenue;
                this.repository.CreateBrandRepo(newBrand);
            }
        }
示例#5
0
        /// <summary>
        /// Checks if the Brand that needs to be deleted is proper. Searches based on Brand Id.
        /// </summary>
        /// <param name="selection">Id of the brand that needs to be deleted</param>
        public void DeleteBrand(string selection)
        {
            IEnumerable <car_brands> brands = this.repository.ListBrandsRepo();

            IEnumerable <int> brand_ids = brands
                                          .Select(b => b.id);

            if (this.IsStringNumber(selection) && brand_ids.Contains(int.Parse(selection)))
            {
                car_brands toBeDeleted = brands.Where(b => b.id == int.Parse(selection)).First();
                this.repository.DeleteBrandRepo(toBeDeleted);
            }
            else
            {
                if (!this.IsStringNumber(selection))
                {
                    throw new InvalidParameterException("Invalid id. You have to select number");
                }
                else
                {
                    throw new InvalidParameterException("Brand cannot be found. Please select another one");
                }
            }
        }
示例#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 });
        }