private void CreateLandAd(LandsDbContext context, string description, User seller, Land land) { LandAdvertise landAd = new LandAdvertise() { Description = description, Seller = seller, Land = land }; context.LandAdvertises.Add(landAd); context.SaveChanges(); }
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)); }