public async Task <IActionResult> СhooseLocality(int id) { User user = await userManager.FindByIdAsync(id.ToString()); if (user != null) { LocalityViewModel localityModel = new LocalityViewModel { Id = id, ReturnUrl = Request.Headers["Referer"].ToString() }; var regions = await regionRepository.GetAllAsync(); if (user.LocalityId == null) { localityModel.Regions = regions.Select(r => new SelectListItem { Value = r.Id.ToString(), Text = r.Name }); } else { var locality = await localityRepository.GetOneAsync(user.LocalityId); var region = locality.Region; int regionId = region.Id; localityModel.RegionId = regionId; localityModel.Regions = regions .Select(r => new SelectListItem { Value = r.Id.ToString(), Text = r.Name, Selected = localityModel.RegionId.Equals(regionId) }); localityModel.Localities = region.Localities .Select(l => new SelectListItem { Value = l.Id.ToString(), Text = l.Name }); } if (user.SportClubId == null) { localityModel.AddClub = true; } return(View(localityModel)); } return(BadRequest()); }
public async Task <IActionResult> AddNewSportClub(NewSportClubViewModel sportClubModel) { Locality locality = await localityRepository.GetOneAsync(sportClubModel.LocalityId); if (locality != null && sportClubModel.Name.Length > 0) { var clubs = await sportClubRepository.GetByNameLocalitySportClubsAsync(sportClubModel.LocalityId, sportClubModel.Name); if (clubs.Count > 0) { return(Json(new { success = false, responseText = "Ошибка! " + sportClubModel.Name + " есть в списке!" })); } else { locality.LocalitySportClubs.Add(new SportClub { Name = sportClubModel.Name }); await localityRepository.UpdateAsync(locality); return(Json(new { success = true, responseText = "Список клубов успешно обновлён." })); } } return(Json(new { success = false, responseText = "Ошибка! Выберите регион, населённый пункт и введите название нового спортивного клуба." })); }