Exemple #1
0
        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));
        }