Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("IdRegion,Name")] Region region, string[] selectedTrails)
        {
            if (selectedTrails != null)
            {
                region.RegionLocation = new List <RegionLocation>();
                foreach (var trail in selectedTrails)
                {
                    var trailToAdd = new RegionLocation {
                        IdRegion = region.IdRegion, IdTrail = int.Parse(trail)
                    };
                    region.RegionLocation.Add(trailToAdd);
                }
            }

            if (ModelState.IsValid)
            {
                await _regionRepository.AddRegionAsync(region);

                return(RedirectToAction(nameof(Index)));
            }

            PopulateRegion(region);

            return(View(region));
        }