Пример #1
0
        /// <summary>
        /// Main program runs here
        /// </summary>
        public static void Main()
        {
            using (CarShopDataEntities carShopDataEntities = new CarShopDataEntities())
            {
                ICarBrandRepository         carBrandRepository         = new CarBrandRepository(carShopDataEntities);
                IModelRepository            modelRepository            = new ModelRepository(carShopDataEntities);
                IExtraRepository            extraRepository            = new ExtraRepository(carShopDataEntities);
                IModelExtraSwitchRepository modelExtraSwitchRepository = new ModelExtraSwitchRepository(carShopDataEntities);
                IJava  javarepo = new Java();
                ILogic logic    = new CarBrandLogic(carBrandRepository, modelRepository, extraRepository, modelExtraSwitchRepository, javarepo);

                ConsoleMenu(logic);
            }
        }
Пример #2
0
        /// <summary>
        /// agdf
        /// </summary>
        /// <typeparam name="T">gfj</typeparam>
        /// <param name="key">jsf</param>
        /// <param name="newValues">gfjs</param>
        public void Update <T>(int key, object newValues)
        {
            try
            {
                using (CarShopDataEntities carShopDataEntities = new CarShopDataEntities())
                {
                    Type t = typeof(T);

                    // Type a = typeof(object); // Might be used instead of Type t = typeof(T)
                    if (t == typeof(CarBrand))
                    {
                        CarBrand carBrand = carShopDataEntities.CarBrands.FirstOrDefault(x => x.Carbrand_Id == key);
                        carBrand = newValues as CarBrand;
                        Console.WriteLine($"{carBrand.Carbrand_Name} was updated");
                    }
                    else if (t == typeof(Extra))
                    {
                        Extra extra = carShopDataEntities.Extras.FirstOrDefault(x => x.Extra_Id == key);
                        extra = newValues as Extra;
                        Console.WriteLine($"{extra.Extra_Name} was updated");
                    }
                    else if (t == typeof(Model))
                    {
                        Model model = carShopDataEntities.Models.FirstOrDefault(x => x.Model_Id == key);
                        model = newValues as Model;
                        Console.WriteLine($"{model.Model_Name} was updated");
                    }
                    else if (t == typeof(ModelExtraswitch))
                    {
                        ModelExtraswitch modelExtraswitch = carShopDataEntities.ModelExtraswitches.FirstOrDefault(x => x.ModelExtraswitch_Id == key);
                        modelExtraswitch = newValues as ModelExtraswitch;
                        Console.WriteLine($"ModelExtraSwitch ID:{modelExtraswitch.ModelExtraswitch_Id} was updated");
                    }

                    carShopDataEntities.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }
Пример #3
0
        /// <summary>
        /// Read or Select function
        /// </summary>
        /// <typeparam name="T">Type of the object where</typeparam>
        /// <param name="key">The key which will be search for.</param>
        /// <returns>Returns the object with the key</returns>
        public object Read <T>(int key)
        {
            try
            {
                using (CarShopDataEntities carShopDataEntities = new CarShopDataEntities())
                {
                    Type t = typeof(T);

                    // Type a = typeof(object); // Might be used instead of Type t = typeof(T)
                    if (t == typeof(CarBrand))
                    {
                        CarBrand carBrand = carShopDataEntities.CarBrands.FirstOrDefault(x => x.Carbrand_Id == key);
                        return(carBrand);
                    }
                    else if (t == typeof(Extra))
                    {
                        Extra extra = carShopDataEntities.Extras.FirstOrDefault(x => x.Extra_Id == key);
                        return(extra);
                    }
                    else if (t == typeof(Model))
                    {
                        Model model = carShopDataEntities.Models.FirstOrDefault(x => x.Model_Id == key);
                        return(model);
                    }
                    else if (t == typeof(ModelExtraswitch))
                    {
                        ModelExtraswitch modelExtraswitch = carShopDataEntities.ModelExtraswitches.FirstOrDefault(x => x.ModelExtraswitch_Id == key);
                        return(modelExtraswitch);
                    }

                    return(null);
                }
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }
Пример #4
0
        /// <summary>
        /// Insert object in the correct table
        /// </summary>
        /// <typeparam name="T">Type of the object</typeparam>
        /// <param name="value">The object which will be inserted into the database.</param>
        public void Create <T>(object value)
        {
            try
            {
                using (CarShopDataEntities carShopDataEntities = new CarShopDataEntities())
                {
                    Type t = typeof(T);

                    // Type a = typeof(object); // Might be used instead of Type t = typeof(T)
                    if (t == typeof(CarBrand))
                    {
                        CarBrand carBrand = value as CarBrand;
                        carShopDataEntities.CarBrands.Add(carBrand);
                    }
                    else if (t == typeof(Extra))
                    {
                        Extra extra = value as Extra;
                        carShopDataEntities.Extras.Add(extra);
                    }
                    else if (t == typeof(Model))
                    {
                        Model model = value as Model;
                        carShopDataEntities.Models.Add(model);
                    }
                    else if (t == typeof(ModelExtraswitch))
                    {
                        ModelExtraswitch modelExtraswitch = value as ModelExtraswitch;
                        carShopDataEntities.ModelExtraswitches.Add(modelExtraswitch);
                    }

                    carShopDataEntities.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtraRepository"/> class.
 /// </summary>
 /// <param name="carShopDataEntities">Data entities</param>
 public ExtraRepository(CarShopDataEntities carShopDataEntities)
 {
     this.carShopDataEntities = carShopDataEntities;
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CarBrandRepository"/> class.
 /// </summary>
 /// <param name="carShopDataEntities">Data entities</param>
 public CarBrandRepository(CarShopDataEntities carShopDataEntities)
 {
     this.carShopDataEntities = carShopDataEntities;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelExtraSwitchRepository"/> class.
 /// </summary>
 /// <param name="carShopDataEntities">Data entities</param>
 public ModelExtraSwitchRepository(CarShopDataEntities carShopDataEntities)
 {
     this.carShopDataEntities = carShopDataEntities;
 }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelRepository"/> class.
 /// </summary>
 /// <param name="carShopDataEntities">Data entities</param>
 public ModelRepository(CarShopDataEntities carShopDataEntities)
 {
     this.carShopDataEntities = carShopDataEntities;
 }