public async Task <ActionResult> AddMode(ModeViewModel mode, ImageModelView userImage) { 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 (mode.Stock == 0) { mode.Stock = 1; } List <string> TypeList = new List <string>(); TypeList.Add(mode.TypeModeAccesorieLugages); TypeList.Add(mode.TypeModeBabyClothes); TypeList.Add(mode.TypeModeBabyEquipment); TypeList.Add(mode.TypeModeClothes); TypeList.Add(mode.TypeModeShoes); TypeList.Add(mode.TypeModeWatchJewelry); string type = null; foreach (var brand in TypeList) { if (brand != null) { type = brand; } } List <string> BrandList = new List <string>(); BrandList.Add(mode.BrandModeClothes); BrandList.Add(mode.BrandModeShoes); string Brand = null; foreach (var modell in BrandList) { if (modell != null) { Brand = modell; } } List <string> SizeList = new List <string>(); SizeList.Add(mode.SizeModeClothes); SizeList.Add(mode.SizeModeShoes); string Size = null; foreach (var modell in SizeList) { if (modell != null) { Size = modell; } } if (mode.SearchOrAskMode == "Je vends") { mode.SearchOrAskMode = "J'offre"; } ModeModel model = new ModeModel() { id = mode.id, Title = mode.TitleMode, Description = mode.DescriptionMode, RubriqueMode = mode.RubriqueMode, Town = mode.TownMode, Price = mode.PriceMode, Street = mode.StreetMode, BrandMode = Brand, TypeMode = type, SizeMode = Size, StateMode = mode.StateMode, UniversMode = mode.UniversMode, ColorMode = mode.ColorMode, DateAdd = DateTime.Now, SearchOrAskJob = mode.SearchOrAskMode, IsActive = true, IsLookaukwat = isLookAuKwat, IsParticulier = isParticuler, IsPromotion = isPromotion, Provider_Id = mode.Provider_Id, Stock_Initial = mode.Stock, Stock = mode.Stock, ProductCountry = mode.ProductCountry, }; 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 + ",Cameroun"*/}"; 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 = "Mode" }; dal.AddMode(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 })); }