public ActionResult Image(int id, string password) { var mgr = new ImageManager(Properties.Settings.Default.ConStr); ImageModelView mv = new ImageModelView(); mv.Image = mgr.GetSingleImage(id); HttpCookie fromRequest = Request.Cookies[$"PasswordForImageId{mv.Image.Id}"]; HttpCookie cookie = new HttpCookie($"PasswordForImageId{mv.Image.Id}", $"{ mv.Image.Password }"); if (fromRequest != null) { mv.PassedInPassword = fromRequest.Value; mv.Image.Views++; mgr.UpdateImageViews(id, mv.Image.Views); } else { if (password == mv.Image.Password) { Response.Cookies.Add(cookie); mv.PassedInPassword = mv.Image.Password; mv.Image.Views++; mgr.UpdateImageViews(id, mv.Image.Views); } else { mv.PassedInPassword = password; } } return(View(mv)); }
private List <ImageProcductModel> ImageAdd(ImageModelView userImage) { List <ImageProcductModel> liste = new List <ImageProcductModel>(); if (userImage.ImageFile != null) { foreach (var image in userImage.ImageFile) { if (image != null && image.ContentLength > 0) { //Save image name path string FileName = Path.GetFileNameWithoutExtension(image.FileName); // save extension of image string FileExtension = Path.GetExtension(image.FileName); //Add a curent date to attached file name FileName = DateTime.Now.ToString("yyyyMMdd") + "-" + FileName + FileExtension; //Create complete path to store in server var path = Server.MapPath("~/UserImage/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } userImage.Image = $"/UserImage/{FileName}"; ImageProcductModel picture = new ImageProcductModel { Image = userImage.Image, id = Guid.NewGuid(), }; liste.Add(picture); FileName = Path.Combine(path, FileName); image.SaveAs(FileName); } else { ImageProcductModel picture = new ImageProcductModel { id = Guid.NewGuid(), Image = "https://particulier-employeur.fr/wp-content/themes/fepem/img/general/avatar.png", ImageMobile = "https://particulier-employeur.fr/wp-content/themes/fepem/img/general/avatar.png" }; liste.Add(picture); } } return(liste); } else { ImageProcductModel picture = new ImageProcductModel { id = Guid.NewGuid(), Image = "https://particulier-employeur.fr/wp-content/themes/fepem/img/general/avatar.png", ImageMobile = "https://particulier-employeur.fr/wp-content/themes/fepem/img/general/avatar.png" }; liste.Add(picture); } return(liste); }
public async Task <ActionResult> EditJob(JobEditViewModel job, ImageModelView userImage) { if (ModelState.IsValid) { ProductCoordinateModel coordinate = dal.GetListProduct().FirstOrDefault(m => m.id == job.JobEditid).Coordinate; string userId = User.Identity.GetUserId(); ApplicationUser user = dal.GetUserByStrId(userId); JobModel model = new JobModel() { id = job.JobEditid, Title = job.TitleJob, Description = job.DescriptionJob, TypeContract = job.TypeContractJob, Coordinate = coordinate, Town = job.TownJob, Price = job.PriceJob, Street = job.StreetJob, ActivitySector = job.ActivitySectorJob, DateAdd = DateTime.Now, SearchOrAskJob = job.SearchOrAskJobJob, Category = new CategoryModel { CategoryName = "Emploi" }, User = user }; using (var httpClient = new HttpClient()) { var fullAddress = $"{model.Street}"; 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 = ImageEdit(userImage, model); model.Images = images; dal.EditJob(model, latt, lonn); return(RedirectToAction("GetListProductByUser_PartialView", "User")); } } } return(View(job)); }
private List <ImageProcductModel> ImageEdit(ImageModelView userImage, ProductModel product) { List <ImageProcductModel> liste = new List <ImageProcductModel>(); if (userImage.ImageFile != null) { foreach (var image in userImage.ImageFile) { if (image != null && image.ContentLength > 0) { //Save image name path string FileName = Path.GetFileNameWithoutExtension(image.FileName); // save extension of image string FileExtension = Path.GetExtension(image.FileName); //Add a curent date to attached file name FileName = DateTime.Now.ToString("yyyyMMdd") + "-" + FileName + FileExtension; //Create complete path to store in server var path = Server.MapPath("~/UserImage/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } userImage.Image = $"/UserImage/{FileName}"; ImageProcductModel picture = new ImageProcductModel { Image = userImage.Image, id = Guid.NewGuid(), ProductId = product.id }; liste.Add(picture); FileName = Path.Combine(path, FileName); image.SaveAs(FileName); } } return(liste); } else { // Guid guid = new Guid(userImage.id); List <ImageProcductModel> picture = dal.GetImageList().Where(s => s.ProductId == product.id).ToList(); foreach (var im in picture) { liste.Add(im); } } return(liste); }
public JsonResult AddImage(ProductModel model, ImageModelView userImage) { try { var file = userImage.ImageFile[0]; string requestUri = "https://lookaukwatapi.azurewebsites.net/api/Product/UploadImages/?id=" + model.id; using (HttpClient client = new HttpClient()) { using (var content = new MultipartFormDataContent()) { byte[] fileBytes = new byte[file.InputStream.Length + 1]; file.InputStream.Read(fileBytes, 0, fileBytes.Length); var fileContent = new ByteArrayContent(fileBytes); fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = file.FileName }; content.Add(fileContent); var result = client.PostAsync(requestUri, content).Result; if (result.StatusCode == System.Net.HttpStatusCode.Created) { ViewBag.Message = "Created"; return(Json(new { Result = "OK" })); } else { ViewBag.Message = "Failed"; return(Json(new { Result = "Failed" })); } } } //ProductModel modell = dal.GetListProductWhithNoInclude().FirstOrDefault(m => m.id == model.id); //List<ImageProcductModel> images = ImageEdit(userImage, modell); //modell.Images = images; //dal.AddImage(modell); //return Json(new { Result = "OK" }); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public async Task <ActionResult> AddAppartment(ApartmentRentalViewModel apart, ImageModelView userImage) { string success = null; 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 (apart.Stock == 0) { apart.Stock = 1; } ApartmentRentalModel model = new ApartmentRentalModel() { id = apart.Id, Title = apart.TitleAppart, Description = apart.DescriptionAppart, ApartSurface = apart.ApartSurface, Town = apart.TownAppart, Price = apart.PriceAppart, Street = apart.StreetAppart, FurnitureOrNot = apart.FurnitureOrNot, RoomNumber = apart.RoomNumber, DateAdd = DateTime.UtcNow, SearchOrAskJob = apart.SearchOrAskJobAppart, Type = apart.Type, IsActive = true, ProductCountry = apart.ProductCountry, IsLookaukwat = isLookAuKwat, IsParticulier = isParticuler, IsPromotion = isPromotion, VideoUrl = apart.VideoUrl, Provider_Id = apart.Provider_Id, Stock_Initial = apart.Stock, Stock = apart.Stock, }; 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 = "Immobilier" }; dal.AddAppartment(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 })); }
public async Task <ActionResult> EditApartment(ApartmentRentalViewModel apart, ImageModelView userImage) { ProductCoordinateModel coordinate = dal.GetListProduct().FirstOrDefault(m => m.id == apart.Id).Coordinate; string userId = User.Identity.GetUserId(); ApplicationUser user = dal.GetUserByStrId(userId); ApartmentRentalModel model = new ApartmentRentalModel() { id = apart.Id, Title = apart.TitleAppart, Description = apart.DescriptionAppart, ApartSurface = apart.ApartSurface, Town = apart.TownAppart, Price = apart.PriceAppart, Street = apart.StreetAppart, FurnitureOrNot = apart.FurnitureOrNot, RoomNumber = apart.RoomNumber, Coordinate = coordinate, Type = apart.Type, DateAdd = DateTime.Now, SearchOrAskJob = apart.SearchOrAskJobAppart, Category = new CategoryModel { CategoryName = "Immobilier" }, User = user }; using (var httpClient = new HttpClient()) { var fullAddress = $"{model.Street}"; 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 = ImageEdit(userImage, model); model.Images = images; dal.EditApartment(model, latt, lonn); return(RedirectToAction("GetListProductByUser_PartialView", "User")); } } return(View(apart)); }
public async Task <ActionResult> EditMultimedia_PartialView(MultimediaViewModel multi, ImageModelView userImage) { List <string> brandList = new List <string>(); brandList.Add(multi.BrandConsoleGame); brandList.Add(multi.BrandInformatiquePhotocopi); brandList.Add(multi.BrandPhoneAccesories); brandList.Add(multi.BrandSon); brandList.Add(multi.BrandTv); string Brand = null; foreach (var brand in brandList) { if (brand != null) { Brand = brand; } } List <string> ModeleList = new List <string>(); ModeleList.Add(multi.ModelAlcatelPhoneAccesorie); ModeleList.Add(multi.ModelApplePhoneAccesorie); ModeleList.Add(multi.ModelAzusPhoneAccesorie); ModeleList.Add(multi.ModelConsoleGame); ModeleList.Add(multi.ModelHonorPhoneAccesorie); ModeleList.Add(multi.ModelHTCPhoneAccesorie); ModeleList.Add(multi.ModelHuaweiPhoneAccesorie); ModeleList.Add(multi.ModelInformatiquePhotocopy); ModeleList.Add(multi.ModelLenovoPhoneAccesorie); ModeleList.Add(multi.ModelLGPhoneAccesorie); ModeleList.Add(multi.ModelMicrosoftPhoneAccesorie); ModeleList.Add(multi.ModelMotorolaPhoneAccesorie); ModeleList.Add(multi.ModelOnePlusPhoneAccesorie); ModeleList.Add(multi.ModelOtherMultimedia); ModeleList.Add(multi.ModelSamsungPhoneAccesorie); ModeleList.Add(multi.ModelSon); ModeleList.Add(multi.ModelSonyPhoneAccesorie); ModeleList.Add(multi.ModelTV); ModeleList.Add(multi.ModelWikoPhoneAccesorie); ModeleList.Add(multi.ModelXaomiPhoneAccesorie); ModeleList.Add(multi.ModelZTEPhoneAccesorie); string Model = null; foreach (var model in ModeleList) { if (model != null) { Model = model; } } if (ModelState.IsValid) { string userId = User.Identity.GetUserId(); ApplicationUser user = dal.GetUserByStrId(userId); MultimediaModel model = new MultimediaModel() { id = multi.id, Title = multi.TitleMultimedia, Description = multi.DescriptionMultimedia, Type = multi.TypeMultimedia, Town = multi.TownMultimedia, Price = multi.PriceMultimedia, Street = multi.StreetMultimedia, Brand = Brand, Model = Model, DateAdd = DateTime.Now, SearchOrAskJob = multi.SearchOrAskJobMultimedia, Category = new CategoryModel { CategoryName = "Multimedia" }, User = user }; using (var httpClient = new HttpClient()) { var fullAddress = $"{model.Street}"; 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 = ImageEdit(userImage, model); model.Images = images; dal.EditMultimedia(model, latt, lonn); return(RedirectToAction("GetListProductByUser_PartialView", "User")); } } } return(View(multi)); }
public async Task <ActionResult> AddMultimedia(MultimediaViewModel multi, ImageModelView userImage) { List <string> brandList = new List <string>(); brandList.Add(multi.BrandConsoleGame); brandList.Add(multi.BrandInformatiquePhotocopi); brandList.Add(multi.BrandPhoneAccesories); brandList.Add(multi.BrandSon); brandList.Add(multi.BrandTv); string Brand = null; foreach (var brand in brandList) { if (brand != null) { Brand = brand; } } List <string> ModeleList = new List <string>(); ModeleList.Add(multi.ModelAlcatelPhoneAccesorie); ModeleList.Add(multi.ModelApplePhoneAccesorie); ModeleList.Add(multi.ModelAzusPhoneAccesorie); ModeleList.Add(multi.ModelConsoleGame); ModeleList.Add(multi.ModelHonorPhoneAccesorie); ModeleList.Add(multi.ModelHTCPhoneAccesorie); ModeleList.Add(multi.ModelHuaweiPhoneAccesorie); ModeleList.Add(multi.ModelInformatiquePhotocopy); ModeleList.Add(multi.ModelLenovoPhoneAccesorie); ModeleList.Add(multi.ModelLGPhoneAccesorie); ModeleList.Add(multi.ModelMicrosoftPhoneAccesorie); ModeleList.Add(multi.ModelMotorolaPhoneAccesorie); ModeleList.Add(multi.ModelOnePlusPhoneAccesorie); ModeleList.Add(multi.ModelOtherMultimedia); ModeleList.Add(multi.ModelSamsungPhoneAccesorie); ModeleList.Add(multi.ModelSon); ModeleList.Add(multi.ModelSonyPhoneAccesorie); ModeleList.Add(multi.ModelTV); ModeleList.Add(multi.ModelWikoPhoneAccesorie); ModeleList.Add(multi.ModelXaomiPhoneAccesorie); ModeleList.Add(multi.ModelZTEPhoneAccesorie); string Model = null; foreach (var modell in ModeleList) { if (modell != null) { Model = modell; } } 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 (multi.Stock == 0) { multi.Stock = 1; } MultimediaModel model = new MultimediaModel() { id = multi.id, Title = multi.TitleMultimedia, Description = multi.DescriptionMultimedia, Type = multi.TypeMultimedia, Town = multi.TownMultimedia, Price = multi.PriceMultimedia, Street = multi.StreetMultimedia, Brand = Brand, Model = Model, Capacity = multi.Capacity, DateAdd = DateTime.Now, SearchOrAskJob = multi.SearchOrAskJobMultimedia, IsActive = true, IsLookaukwat = isLookAuKwat, IsParticulier = isParticuler, IsPromotion = isPromotion, Provider_Id = multi.Provider_Id, Stock_Initial = multi.Stock, Stock = multi.Stock, ProductCountry = multi.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 + "," + ",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 = "Multimedia" }; dal.AddMultimedia(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 })); }
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 })); }
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 })); }
public async Task <ActionResult> AddHouse(HouseViewModel house, 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 (house.Stock == 0) { house.Stock = 1; } HouseModel model = new HouseModel() { Title = house.Title, Description = house.Description, RubriqueHouse = house.RubriqueHouse, Town = house.Town, Price = house.Price, Street = house.Street, ColorHouse = house.ColorHouse, FabricMaterialeHouse = house.FabricMaterialeHouse, StateHouse = house.StateHouse, TypeHouse = house.TypeHouse, DateAdd = DateTime.UtcNow, SearchOrAskJob = house.SearchOrAskJob, IsActive = true, IsLookaukwat = isLookAuKwat, IsParticulier = isParticuler, IsPromotion = isPromotion, Provider_Id = house.Provider_Id, Stock_Initial = house.Stock, Stock = house.Stock, ProductCountry = house.ProductCountry, }; 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 = "Maison" }; dal.AddHouse(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); } //string success = "Annonce ajoutée avec succès dans la liste !"; //return RedirectToAction("UserProfile", "Home",new { message= success }); return(RedirectToAction("AddImage", "Job", new { id = model.id })); } } } ViewBag.Erreur = "Une erreur s'est produite lors de l'enregistrement de votre annonce"; return(View("AddFullModel", house)); }