2023-07-04 20:40:37 -04:00
|
|
|
using System.Diagnostics;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using vassago.Models;
|
|
|
|
|
|
|
|
namespace vassago.Controllers;
|
|
|
|
|
|
|
|
public class UsersController : Controller
|
|
|
|
{
|
|
|
|
private readonly ILogger<UsersController> _logger;
|
|
|
|
private readonly ChattingContext _db;
|
|
|
|
|
|
|
|
public UsersController(ILogger<UsersController> logger, ChattingContext db)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_db = db;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IActionResult> Index(string searchString)
|
|
|
|
{
|
|
|
|
return _db.Users != null ?
|
|
|
|
View(await _db.Users.Include(u => u.Accounts).ToListAsync()) :
|
2023-12-01 09:49:21 -05:00
|
|
|
Problem("Entity set '_db.Users' is null.");
|
|
|
|
}
|
|
|
|
public async Task<IActionResult> Details(Guid id)
|
|
|
|
{
|
2024-07-07 15:27:48 -04:00
|
|
|
var user = await _db.Users
|
|
|
|
.Include(u => u.Accounts)
|
|
|
|
.FirstAsync(u => u.Id == id);
|
|
|
|
var allTheChannels = await _db.Channels.ToListAsync();
|
|
|
|
foreach(var acc in user.Accounts)
|
|
|
|
{
|
|
|
|
acc.SeenInChannel = allTheChannels.FirstOrDefault(c => c.Id == acc.SeenInChannel.Id);
|
|
|
|
}
|
2023-12-01 09:49:21 -05:00
|
|
|
return _db.Users != null ?
|
2024-07-07 15:27:48 -04:00
|
|
|
View(user) :
|
2023-12-01 09:49:21 -05:00
|
|
|
Problem("Entity set '_db.Users' is null.");
|
2023-07-04 20:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
public IActionResult Error()
|
|
|
|
{
|
|
|
|
return View(new ErrorPageViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
}
|
|
|
|
}
|