public ActionResult EditApartment_PartialView(ApartmentRentalModel apart) { if (apart.id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (apart == null) { return(HttpNotFound()); } ApartmentRentalViewModel model = new ApartmentRentalViewModel() { Id = apart.id, TitleAppart = apart.Title, DescriptionAppart = apart.Description, FurnitureOrNot = apart.FurnitureOrNot, TownAppart = apart.Town, PriceAppart = apart.Price, StreetAppart = apart.Street, RoomNumber = apart.RoomNumber, SearchOrAskJobAppart = apart.SearchOrAskJob, Type = apart.Type, listeImageappart = apart.Images }; return(PartialView(model)); }
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> 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 })); }