This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Aberwyn.Models;
|
||||
using Aberwyn.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
namespace Aberwyn.Controllers
|
||||
{
|
||||
@@ -10,13 +13,20 @@ namespace Aberwyn.Controllers
|
||||
{
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
private readonly RoleManager<IdentityRole> _roleManager;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public AdminController(UserManager<ApplicationUser> userManager, RoleManager<IdentityRole> roleManager)
|
||||
|
||||
public AdminController(
|
||||
UserManager<ApplicationUser> userManager,
|
||||
RoleManager<IdentityRole> roleManager,
|
||||
ApplicationDbContext context)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_roleManager = roleManager;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var users = _userManager.Users.ToList();
|
||||
@@ -86,8 +96,48 @@ namespace Aberwyn.Controllers
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Todo()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetTodoTasks()
|
||||
{
|
||||
var tasks = await _context.TodoTasks.ToListAsync();
|
||||
return Json(tasks);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AddTodoTask([FromBody] TodoTask task)
|
||||
{
|
||||
task.CreatedAt = DateTime.UtcNow;
|
||||
task.Priority = task.Priority == 0 ? 1 : task.Priority; // default till låg om ej satt
|
||||
_context.TodoTasks.Add(task);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(task);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> UpdateTodoTask([FromBody] TodoTask task)
|
||||
{
|
||||
var existing = await _context.TodoTasks.FindAsync(task.Id);
|
||||
if (existing == null) return NotFound();
|
||||
|
||||
existing.Title = task.Title;
|
||||
existing.Status = task.Status;
|
||||
existing.Priority = task.Priority;
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class AdminUserViewModel
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user