Example #1
0
        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));
        }
Example #2
0
        // GET: LocalAuthorities/Create
        public IActionResult Create()
        {
            LocalAuthorityViewModel viewModel = new LocalAuthorityViewModel();

            PopulateDropDowns(viewModel);

            return(View(viewModel));
        }
Example #3
0
        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));
        }
Example #4
0
        // 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));
        }
Example #5
0
        // 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));
        }
Example #6
0
 private void PopulateDropDowns(LocalAuthorityViewModel viewModel)
 {
     viewModel.regions = _context.Region.ToList();
 }