Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Site.Data;
  5. using System.Threading.Tasks;
  6. using Microsoft.EntityFrameworkCore;
  7. using Site.Data.Models;
  8.  
  9. namespace Ad.Areas.Admin.Controllers
  10. {
  11. [Area("Admin")]
  12. // [Authorize(Roles = "Admin")]
  13. public class PageController : Controller
  14. {
  15. private readonly ApplicationContext _context;
  16.  
  17. public PageController(ApplicationContext context)
  18. {
  19. _context = context;
  20. }
  21.  
  22. public async Task<IActionResult> Index()
  23. {
  24. return View(await _context.Pages
  25. .OrderBy(a=>a.Position) //not working
  26. .ToListAsync());
  27. }
  28.  
  29. public IActionResult Edit(int id)
  30. {
  31. return View(_context.Pages.Find(id));
  32. }
  33. [HttpPost]
  34. [ValidateAntiForgeryToken]
  35. public async Task<IActionResult> Edit(Page page)
  36. {
  37. if (ModelState.IsValid)
  38. {
  39. _context.Update(page);
  40. await _context.SaveChangesAsync();
  41. return RedirectToAction(nameof(Index));
  42. }
  43. return View(page);
  44. }
  45.  
  46.  
  47.  
  48.  
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement