public async Task <ActionResult> AddVehicule(VehiculeViewModel Vehi, ImageModelView userImage) { List <string> brandList = new List <string>(); brandList.Add(Vehi.BrandAccessoryAutoVehicule); brandList.Add(Vehi.BrandAccessoryBikeVehicule); brandList.Add(Vehi.BrandVehiculeAuto); brandList.Add(Vehi.BrandVehiculeBike); string Brand = null; foreach (var brand in brandList) { if (brand != null) { Brand = brand; } } List <string> ModeleList = new List <string>(); ModeleList.Add(Vehi.ModelVehiculeAutoEquipment); ModeleList.Add(Vehi.ModelVehiculeBike); ModeleList.Add(Vehi.ModelVehiculeBikeEquipment); ModeleList.Add(Vehi.ModelVehiculeHuyndrai); ModeleList.Add(Vehi.ModelVehiculeKia); ModeleList.Add(Vehi.ModelVehiculeMazda); ModeleList.Add(Vehi.ModelVehiculeMercedes); ModeleList.Add(Vehi.ModelVehiculeToyota); string Model = null; foreach (var modell in ModeleList) { if (modell != null) { Model = modell; } } if (Vehi.SearchOrAskJobVehicule == "Je vends") { Vehi.SearchOrAskJobVehicule = "J'offre"; } bool isLookAuKwat = false; bool isParticuler = false; bool isPromotion = false; if (User.IsInRole(MyRoleConstant.RoleAdmin) || (User.IsInRole(MyRoleConstant.Role_SuperAgent))) { isLookAuKwat = true; isPromotion = true; } else { isParticuler = true; } if (Vehi.Stock == 0) { Vehi.Stock = 1; } VehiculeModel model = new VehiculeModel() { id = Vehi.id, Title = Vehi.TitleVehicule, Description = Vehi.DescriptionVehicule, TypeVehicule = Vehi.TypeVehicule, Town = Vehi.TownVehicule, Price = Vehi.PriceVehicule, Street = Vehi.StreetVehicule, BrandVehicule = Brand, ModelVehicule = Model, RubriqueVehicule = Vehi.RubriqueVehicule, PetrolVehicule = Vehi.PetrolVehicule, FirstYearVehicule = Vehi.FirstYearVehicule, YearVehicule = Vehi.YearVehicule, MileageVehicule = Vehi.MileageVehicule, NumberOfDoorVehicule = Vehi.NumberOfDoorVehicule, ColorVehicule = Vehi.ColorVehicule, GearBoxVehicule = Vehi.GearBoxVehicule, DateAdd = DateTime.UtcNow, SearchOrAskJob = Vehi.SearchOrAskJobVehicule, StateVehicule = Vehi.StateVehicule, IsActive = true, ProductCountry = Vehi.ProductCountry, IsLookaukwat = isLookAuKwat, IsParticulier = isParticuler, IsPromotion = isPromotion, VideoUrl = Vehi.VideoUrl, Provider_Id = Vehi.Provider_Id, Stock_Initial = Vehi.Stock, Stock = Vehi.Stock, }; string success = null; if (ModelState.IsValid) { using (var httpClient = new HttpClient()) { string userId = User.Identity.GetUserId(); ApplicationUser user = dal.GetUserByStrId(userId); var fullAddress = $"{ model.Street /*+ model.Town + "," + ",Cameroon"*/}"; var response = await httpClient.GetAsync("https://api.opencagedata.com/geocode/v1/json?q=" + fullAddress + "&key=a196040df44a4a41a471173aed07635c"); if (response.IsSuccessStatusCode) { var jsonn = await response.Content.ReadAsStringAsync(); var joo = JObject.Parse(jsonn); var latt = (string)joo["results"][0]["geometry"]["lat"]; var lonn = (string)joo["results"][0]["geometry"]["lng"]; List <ImageProcductModel> images = ImageAdd(userImage); model.Images = images; model.User = user; model.Category = new CategoryModel { CategoryName = "Vehicule" }; dal.AddVehicule(model, latt, lonn); //check if email or phone is confirm and update date of publish announce for agent pay if ((user.EmailConfirmed == true || user.PhoneNumberConfirmed == true) && user.Date_First_Publish == null) { dal.Update_Date_First_Publish(user); } // success = "Annonce ajoutée avec succès dans la liste !"; //return RedirectToAction("UserProfile", "Home", new { message = success }); // return RedirectToAction("GetListProductByUser_PartialView", "User"); return(RedirectToAction("AddImage", "Job", new { id = model.id })); } } } success = "Désolé une erreur s'est produite!"; return(RedirectToAction("UserProfile", "Home", new { message = success })); }