public async Task <IActionResult> CreateCarAd(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.CarTypes = initializeCarModel().CarTypes; compositeModel.Currencies = new SelectList(currencyContainer.GetCurrencyNameList()); return(View("CreateAdvertise", compositeModel)); } if (ModelState.IsValid) { var model = compositeModel.car; 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.Now, ApplicationUser = user, Item = new AutoItem { Price = Double.Parse(model.Price), Brand = model.Brand, Car_Type = model.Car_Type, ProductAge = model.ProductAge, Doors = Int32.Parse(model.Doors), Description = model.Description, Seats = Int32.Parse(model.Seats), Mileage = Int32.Parse(model.Mileage), CurrencyId = currencyContainer.GetIdByName(model.CurrencyName) }, }; if (uniqueFileName != 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(false, "Failed to create new article", "CreateCarAD", "Advertisment", ""); } return(View("ResultView")); } } compositeModel.Currencies = new SelectList(currencyContainer.GetCurrencyNameList()); compositeModel.car.CarTypes = initializeCarModel().CarTypes; return(View("CreateAdvertise", compositeModel)); }