public async Task <IActionResult> Create( [Bind("Id,City,Street,Number,SelectedManagers")] BuildingViewModel building) { if (ModelState.IsValid) { var bhm = building.SelectedManagers.Select( b => new BuildingHousemanagers() { BuildingId = building.Id, HouseManagerId = b }); var bld = new Building() { Id = building.Id, City = building.City, Number = building.Number, Street = building.Street, BuildingHouseManagers = bhm.ToList() }; await bldService.AddAsync(bld); return(RedirectToAction("Index")); } return(View(building)); }
public async Task <IActionResult> Edit(int id) { var building = await bldService.GetBuildingByIdAsync(id); if (building == null) { return(NotFound()); } var buildingHouseManagers = await userService.GetBuildingManagersAsync(id); var allHouseManagers = await userService.GetHouseManagersAsync(); MultiSelectList options = new MultiSelectList(allHouseManagers, "Id", "Email", buildingHouseManagers.Select(bhm => bhm.Id)); ViewBag.AllHouseManagers = options; BuildingViewModel vm = new BuildingViewModel() { Id = building.Id, BuildingHouseManagers = building.BuildingHouseManagers, City = building.City, Number = building.Number, Street = building.Street }; return(View(vm)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,City,Street,Number,SelectedManagers")] BuildingViewModel building) { if (id != building.Id) { return(NotFound()); } if (ModelState.IsValid) { var buildingEntity = this.mapper.Map <Building>(building); await bldService.UpdateAsync(buildingEntity); return(RedirectToAction("Index")); } return(View(building)); }