// GET: Competitions/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var competition = await _bll.Competition.FindAsync(id); if (competition == null) { return(NotFound()); } var vm = new CompetitionsCreateViewModel(); vm.Competition = competition; vm.LocationSelectList = new SelectList(await _bll.Location.AllAsync(), nameof(BLL.App.DTO.Location.Id), nameof(BLL.App.DTO.Location.Locations), vm.Competition.LocationId); return(View(vm)); }
// GET: Competitions/Create public async Task <IActionResult> Create() { var vm = new CompetitionsCreateViewModel() { DogSelectList = new SelectList(await _bll.Dog.AllAsync(), nameof(BLL.App.DTO.Dog.Id), nameof(BLL.App.DTO.Dog.DogName)), LocationSelectList = new SelectList(await _bll.Location.AllAsync(), nameof(BLL.App.DTO.Location.Id), nameof(BLL.App.DTO.Location.Locations)), }; return(View(vm)); }
public async Task <IActionResult> Create(CompetitionsCreateViewModel vm) { if (ModelState.IsValid) { await _bll.Competition.AddAsync(vm.Competition); await _bll.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } vm.LocationSelectList = new SelectList(await _bll.Location.AllAsync(), nameof(BLL.App.DTO.Location.Id), nameof(BLL.App.DTO.Location.Locations), vm.Competition.LocationId); return(View(vm)); }
public async Task <IActionResult> Edit(int id, CompetitionsCreateViewModel vm) { if (id != vm.Competition.Id) { return(NotFound()); } if (ModelState.IsValid) { _bll.Competition.Update(vm.Competition); await _bll.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } vm.LocationSelectList = new SelectList(await _bll.Location.AllForUserAsync(User.GetUserId()), nameof(BLL.App.DTO.Location.Id), nameof(BLL.App.DTO.Location.Locations), vm.Competition.LocationId); return(View(vm)); }