private void CreateHouseAd(LandsDbContext context, string description, User seller, House house)
        {
            HouseAdvertise houseAd = new HouseAdvertise()
            {
                Description = description,
                Seller      = seller,
                House       = house
            };

            context.HouseAdvertises.Add(houseAd);
            context.SaveChanges();
        }
        public ActionResult CreateHouse(HouseCreateModel model)
        {
            if (this.ModelState.IsValid)
            {
                if (model == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                using (var context = new LandsDbContext())
                {
                    var ownerId = this.User.Identity.GetUserId();

                    var house = new House
                    {
                        Address      = model.Address,
                        Price        = model.Price,
                        YearOfBuilt  = model.YearOfBuilt,
                        LandArea     = model.LandArea,
                        HouseArea    = model.HouseArea,
                        Floors       = model.Floors,
                        Bedrooms     = model.Bedrooms,
                        LivingRooms  = model.LivingRooms,
                        Bathrooms    = model.Bathrooms,
                        HaveBasement = model.HaveBasement,
                        HavePool     = model.HavePool,
                        HaveGarage   = model.HaveGarage,
                        ParkSlots    = model.ParkSlots,
                        ImageUrl     = model.ImageUrl
                    };

                    context.Houses.Add(house);
                    context.SaveChanges();

                    var adHouse = new HouseAdvertise
                    {
                        Description = model.Description,
                        SellerId    = ownerId,
                        HouseId     = house.Id
                    };

                    context.HouseAdvertises.Add(adHouse);
                    context.SaveChanges();

                    return(RedirectToAction("Houses", "Buy"));
                }
            }
            return(View(model));
        }