public IActionResult Create([Bind("HouseId,Name,Price,Bedrooms,Bathrooms,Size,ProvinceId,ImageUploaded,Description")] AddHouseViewModel model, IEnumerable <int> features, IEnumerable <int> services) { if (ModelState.IsValid) { var house = _autoMapper.Map <House>(model); var houseFeatures = features.Select(id => new HouseFeature() { FeatureId = id }); foreach (var id in features) { house.Features.Add(new HouseFeature() { FeatureId = id }); } var houseServices = services.Select(id => new HouseService() { ServiceId = id }); foreach (var id in services) { house.Services.Add(new HouseService() { ServiceId = id }); } _houseService.Insert(house, model.ImageUploaded); _houseService.Save(); TempData["TransactionCompleted"] = "House added Sucessfully"; return(RedirectToAction(nameof(List))); } model.Provinces = new SelectList(_provinceService.GetAll(), "ProvinceId", "Name"); model.Features = _featureService.GetAll(); model.SelectedFeatures = features.Select(id => new HouseFeature() { FeatureId = id }); model.Services = _servicexService.GetAll(); model.SelectedServices = services.Select(id => new HouseService() { ServiceId = id }); return(View(model)); }