public async Task <IActionResult> Edit(int id, LocalAuthorityViewModel viewModel) { if (id != viewModel.LocalAuthorityId) { return(NotFound()); } if (ModelState.IsValid) { try { LocalAuthority model = new LocalAuthority(); _mapper.Map(viewModel, model); _context.Update(model); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocalAuthorityExists(viewModel.LocalAuthorityId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
// GET: LocalAuthorities/Create public IActionResult Create() { LocalAuthorityViewModel viewModel = new LocalAuthorityViewModel(); PopulateDropDowns(viewModel); return(View(viewModel)); }
public async Task <IActionResult> Create(LocalAuthorityViewModel viewModel) { if (ModelState.IsValid) { LocalAuthority model = new LocalAuthority(); _mapper.Map(viewModel, model); _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } PopulateDropDowns(viewModel); return(View(viewModel)); }
// GET: LocalAuthorities public async Task <IActionResult> Index(int?pageNumber) { var outcomesFirstContext = _context.LocalAuthority .Include(r => r.LocalAuthorityRegion) .OrderBy(o => o.LocalAuthorityName); LocalAuthorityViewModel viewModel = new LocalAuthorityViewModel(); var localAuthorities = await _context.LocalAuthority .Include(r => r.LocalAuthorityRegion) .OrderBy(o => o.LocalAuthorityName) .ToArrayAsync(); IEnumerable <LocalAuthorityViewModel> localauthorityVM = _mapper.Map <LocalAuthority[], IEnumerable <LocalAuthorityViewModel> >(localAuthorities); return(View(localauthorityVM)); }
// GET: LocalAuthorities/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var model = await _context.LocalAuthority.FindAsync(id); if (model == null) { return(NotFound()); } LocalAuthorityViewModel viewModel = new LocalAuthorityViewModel(); _mapper.Map(model, viewModel); PopulateDropDowns(viewModel); return(View(viewModel)); }
private void PopulateDropDowns(LocalAuthorityViewModel viewModel) { viewModel.regions = _context.Region.ToList(); }