// GET: AdController/Create
        public async Task <ActionResult> Create()
        {
            var makeItems = await _makeRepo.GetSelectListItem();

            var modelItems = await _modelRepo.GetSelectListItem();

            var fuelTypeItems = await _fuelTypeRepo.GetSelectListItem();

            var bodyTypeItems = await _bodyTypeRepo.GetSelectListItem();

            var damageItems = await _damageRepo.GetSelectListItem();

            var colorItems = await _colorRepo.GetSelectListItem();

            var gearBoxItems = await _gearBoxRepo.GetSelectListItem();


            var model = new CreateAdVM
            {
                MakeList     = makeItems,
                ModelList    = modelItems,
                FuelTypeList = fuelTypeItems,
                BodyTypeList = bodyTypeItems,
                DamageList   = damageItems,
                ColorList    = colorItems,
                GearBoxList  = gearBoxItems
            };

            return(View(model));
        }
        public async Task <ActionResult> Create(CreateAdVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                var ads       = _mapper.Map <Ad>(model);
                var isSuccess = await _adRepo.Create(ads);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something went wrong...");
                    return(View(model));
                }



                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(model));
            }
        }
        // GET: AdController/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            var ad = await _adRepo.FindById(id);

            var makeItems = await _makeRepo.GetSelectListItem();

            var modelItems = await _modelRepo.GetSelectListItem();

            var fuelTypeItems = await _fuelTypeRepo.GetSelectListItem();

            var bodyTypeItems = await _bodyTypeRepo.GetSelectListItem();

            var damageItems = await _damageRepo.GetSelectListItem();

            var colorItems = await _colorRepo.GetSelectListItem();

            var gearBoxItems = await _gearBoxRepo.GetSelectListItem();

            var model = new CreateAdVM
            {
                MakeList       = makeItems,
                CarMakeId      = ad.CarMakeId,
                ModelList      = modelItems,
                CarModelId     = ad.CarModelId,
                Year           = ad.Year,
                Price          = ad.Price,
                FuelTypeList   = fuelTypeItems,
                FuelTypeId     = ad.FuelTypeId,
                BodyTypeList   = bodyTypeItems,
                EngineCapacity = ad.EngineCapacity,
                Kilometrage    = ad.Kilometrage,
                DamageList     = damageItems,
                DamageId       = ad.DamageId,
                ColorList      = colorItems,
                ColorId        = ad.ColorId,
                NumberOfSeats  = ad.NumberOfSeats,
                GearBoxList    = gearBoxItems,
                GearBoxId      = ad.GearBoxId,
                SteeringWheel  = ad.SteeringWheel
            };

            if (model == null)
            {
                return(NotFound());
            }

            return(View(model));
        }