public IActionResult CreateAdvertise()
        {
            var model = new CreateBikeViewModel();

            model.ProductAge = DateTime.Today;
            BikeAndCarViewModel combinedModel = new BikeAndCarViewModel
            {
                car        = initializeCarModel(),
                bike       = model,
                Currencies = new SelectList(currencyContainer.GetCurrencyNameList())
            };


            return(View(combinedModel));
        }
        public async Task <IActionResult> CreateBikeAd(BikeAndCarViewModel compositeModel)
        {
            // Google reCaptcha
            var googleRecaptcha = googleRecaptchaService.VerifyRecaptcha(compositeModel.RecaptchaToken);

            if (!googleRecaptcha.Result.success && googleRecaptcha.Result.score <= 0.5)
            {
                ModelState.AddModelError("", "Captcha failed, please try again");
                compositeModel.car        = initializeCarModel();
                compositeModel.Currencies = new SelectList(currencyContainer.GetCurrencyNameList());
                return(View("CreateAdvertise", compositeModel));
            }

            if (ModelState.IsValid)
            {
                var    model          = compositeModel.bike;
                string uniqueFileName = null;
                if (model.Picture != null)
                {
                    uniqueFileName = ProcessUploadedPhoto(model.Picture);
                }

                var user = await userManager.GetUserAsync(User);

                if (user == null)
                {
                    ViewBag.ErrorMessage = "User cannot be found";
                    return(View("NotFound"));
                }
                else
                {
                    Advertisment advertisment = new Advertisment
                    {
                        Title           = model.Title,
                        PostDate        = DateTime.UtcNow,
                        ApplicationUser = user,
                        Item            = new BikeItem
                        {
                            Price       = Double.Parse(model.Price),
                            Brand       = model.Brand,
                            ProductAge  = model.ProductAge,
                            Description = model.Description,
                            CurrencyId  = currencyContainer.GetIdByName(model.CurrencyName)
                        }
                    };

                    if (model.Mileage != null)
                    {
                        advertisment.Item.Mileage = Int32.Parse(model.Mileage);
                    }
                    if (model.TopSpeed != null)
                    {
                        ((BikeItem)(advertisment.Item)).TopSpeed = Int32.Parse(model.TopSpeed);
                    }
                    if (model.Picture != null)
                    {
                        advertisment.Picture = uniqueFileName;
                    }

                    try
                    {
                        await advertismentRepository.Add(advertisment);

                        InitializeResultView(true, "You have successfuly created a new article", "MyAdvertisments", "Advertisment", "my articles");
                    }
                    catch (Exception e)
                    {
                        InitializeResultView(true, "Failed to create new article", "CreateCarAD", "Advertisment", "");
                    }

                    return(View("ResultView"));
                }
            }
            compositeModel.car        = initializeCarModel();
            compositeModel.Currencies = new SelectList(currencyContainer.GetCurrencyNameList());
            return(View("CreateAdvertise", compositeModel));
        }