public ActionResult ApartmentEdit(ApartmentDetailsModel model) { if (this.ModelState.IsValid) { using (var context = new LandsDbContext()) { var apartment = context.Apartments.FirstOrDefault(a => a.Id == model.ApartmentId); if (apartment == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } apartment.Address = model.Address; apartment.Price = model.Price; apartment.YearOfBuilt = model.YearOfBuilt; apartment.ApartmentArea = model.ApartmentArea; apartment.Floor = model.Floor; apartment.Bedrooms = model.Bedrooms; apartment.LivingRooms = model.LivingRooms; apartment.Bathroom = model.Bathroom; apartment.TerraceArea = model.TerraceArea; apartment.HaveBasement = model.HaveBasement; apartment.HaveElevator = model.HaveElevator; apartment.HaveGarage = model.HaveGarage; apartment.ParkSlots = model.ParkSlots; apartment.ImageUrl = model.ImageUrl; var apartmentAd = context.ApartmentAdvertises .FirstOrDefault(aa => aa.Id == model.ApartmentAdId); if (apartmentAd == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } apartmentAd.Description = model.Description; context.SaveChanges(); return(RedirectToAction("Apartments", "Buy")); } } return(View(model)); }
public ActionResult HouseEdit(HouseDetailsModel model) { if (this.ModelState.IsValid) { using (var context = new LandsDbContext()) { var house = context.Houses.FirstOrDefault(h => h.Id == model.HouseId); if (house == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } house.Address = model.Address; house.Price = model.Price; house.YearOfBuilt = model.YearOfBuilt; house.LandArea = model.LandArea; house.HouseArea = model.HouseArea; house.Floors = model.Floors; house.Bedrooms = model.Bedrooms; house.LivingRooms = model.LivingRooms; house.Bathrooms = model.Bathrooms; house.HaveBasement = model.HaveBasement; house.HavePool = model.HavePool; house.HaveGarage = model.HaveGarage; house.ParkSlots = model.ParkSlots; house.ImageUrl = model.ImageUrl; var houseAd = context.HouseAdvertises .FirstOrDefault(ha => ha.Id == model.HouseAdId); if (houseAd == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } houseAd.Description = model.Description; context.SaveChanges(); return(RedirectToAction("Houses", "Buy")); } } return(View(model)); }
public ActionResult CreateLand(LandCreateModel model) { if (model == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (this.ModelState.IsValid) { using (var context = new LandsDbContext()) { var ownerId = this.User.Identity.GetUserId(); var land = new Land { Address = model.Address, Price = model.Price, Area = model.Area, Electricity = model.Electricity, Water = model.Water, Sewage = model.Sewage, ImageUrl = model.ImageUrl }; context.Lands.Add(land); context.SaveChanges(); var adLand = new LandAdvertise() { Description = model.Description, SellerId = ownerId, LandId = land.Id }; context.LandAdvertises.Add(adLand); context.SaveChanges(); return(RedirectToAction("Lands", "Buy")); } } return(View(model)); }
public ActionResult ApartmentEdit(int?apartmentAdId) { if (apartmentAdId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var context = new LandsDbContext()) { var a = context.ApartmentAdvertises.FirstOrDefault(x => x.Id == apartmentAdId); var model = new ApartmentDetailsModel() { ApartmentAdId = a.Id, Description = a.Description, SellerId = a.SellerId, SellerName = a.Seller.UserName, ApartmentId = a.Apartment.Id, Address = a.Apartment.Address, Price = a.Apartment.Price, YearOfBuilt = a.Apartment.YearOfBuilt, ApartmentArea = a.Apartment.ApartmentArea, Floor = a.Apartment.Floor, Bedrooms = a.Apartment.Bedrooms, LivingRooms = a.Apartment.LivingRooms, Bathroom = a.Apartment.Bathroom, TerraceArea = a.Apartment.TerraceArea, HaveBasement = a.Apartment.HaveBasement, HaveElevator = a.Apartment.HaveElevator, HaveGarage = a.Apartment.HaveGarage, ParkSlots = a.Apartment.ParkSlots, ImageUrl = a.Apartment.ImageUrl }; if (model == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } return(View(model)); } }
public ActionResult HouseEdit(int?houseAdId) { if (houseAdId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var context = new LandsDbContext()) { var h = context.HouseAdvertises.FirstOrDefault(x => x.Id == houseAdId); var model = new HouseDetailsModel() { HouseAdId = h.Id, Description = h.Description, SellerId = h.SellerId, SellerName = h.Seller.UserName, HouseId = h.House.Id, Address = h.House.Address, Price = h.House.Price, YearOfBuilt = h.House.YearOfBuilt, LandArea = h.House.LandArea, HouseArea = h.House.HouseArea, Floors = h.House.Floors, Bedrooms = h.House.Bedrooms, LivingRooms = h.House.LivingRooms, Bathrooms = h.House.Bathrooms, HaveBasement = h.House.HaveBasement, HavePool = h.House.HavePool, HaveGarage = h.House.HaveGarage, ParkSlots = h.House.ParkSlots, ImageUrl = h.House.ImageUrl }; if (model == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } return(View(model)); } }
public ActionResult LandEdit(LandDetailsModel model) { if (this.ModelState.IsValid) { using (var context = new LandsDbContext()) { var land = context.Lands .FirstOrDefault(l => l.Id == model.LandId); if (land == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } land.Address = model.Address; land.Price = model.Price; land.Area = model.Area; land.Electricity = model.Electricity; land.Water = model.Water; land.Sewage = model.Sewage; land.ImageUrl = model.ImageUrl; var landAd = context.LandAdvertises .FirstOrDefault(la => la.Id == model.LandAdId); if (landAd == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } landAd.Description = model.Description; context.SaveChanges(); return(RedirectToAction("Lands", "Buy")); } } return(View(model)); }