Example #1
0
        public async Task <int> AddNewCarAsync(GasCarTable car)
        {
            // int carId = await GetNextValueAsync();

            //  car.Id = carId;

            var newCar = await this.context.GasCars.AddAsync(car);

            await this.context.SaveChangesAsync();


            return(newCar.Entity.Id);
        }
Example #2
0
        public async Task <int> AddNewCarAsync(CarViewModel carViewModel)
        {
            if (carViewModel == null)
            {
                throw new CarException("Car cannot be null");
            }

            GasCarTable dieselCar = new GasCarTable
            {
                CarBrand = carViewModel.CarBrand,
                CarModel = carViewModel.CarModel
            };

            var carId = await this.dbContextManager
                        .AddNewCarAsync(dieselCar);

            if (carId == 0)
            {
                throw new CarException("Id cannot be zero somthing wrong");
            }
            return(carId);
        }