yavsc/src/Yavsc/Controllers/HomeController.cs

133 lines
4.2 KiB
C#

using Microsoft.AspNet.Mvc.Localization;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Identity;
using System.Linq;
using System.Security.Claims;
using Microsoft.Data.Entity;
using Microsoft.AspNet.Http;
using System.Threading.Tasks;
namespace Yavsc.Controllers
{
8 years ago
using System.IO;
using Models;
using Yavsc;
8 years ago
using Yavsc.Helpers;
[AllowAnonymous]
public class HomeController : Controller
{
5 years ago
readonly ApplicationDbContext _dbContext;
6 years ago
readonly IHtmlLocalizer _localizer;
5 years ago
public HomeController(IHtmlLocalizer<Startup> localizer,
ApplicationDbContext context)
{
_localizer = localizer;
7 years ago
_dbContext = context;
}
public async Task<IActionResult> Index(string id)
{
5 years ago
ViewBag.IsFromSecureProx = Request.Headers.ContainsKey(Constants.SshHeaderKey) && Request.Headers[Constants.SshHeaderKey] == "on";
6 years ago
ViewBag.SecureHomeUrl = "https://" + Request.Headers["X-Forwarded-Host"];
ViewBag.SshHeaderKey = Request.Headers[Constants.SshHeaderKey];
var uid = User.GetUserId();
6 years ago
long[] clicked = null;
if (uid == null)
{
await HttpContext.Session.LoadAsync();
var strclicked = HttpContext.Session.GetString("clicked");
6 years ago
if (strclicked != null) clicked = strclicked.Split(':').Select(c => long.Parse(c)).ToArray();
if (clicked == null) clicked = new long[0];
}
6 years ago
else clicked = _dbContext.DimissClicked.Where(d => d.UserId == uid).Select(d => d.NotificationId).ToArray();
7 years ago
var notes = _dbContext.Notification.Where(
6 years ago
n => !clicked.Contains(n.Id)
);
8 years ago
this.Notify(notes);
6 years ago
ViewData["HaircutCommandCount"] = _dbContext.HairCutQueries.Where(
q => q.ClientId == uid && q.Status < QueryStatus.Failed
8 years ago
).Count();
6 years ago
var toShow = _dbContext.Activities
.Include(a => a.Forms)
.Include(a => a.Parent)
.Include(a => a.Children)
.Where(a => !a.Hidden)
.Where(a => a.ParentCode == id)
.OrderByDescending(a => a.Rate).ToList();
foreach (var a in toShow)
{
a.Children = a.Children.Where(c => !c.Hidden).ToList();
}
8 years ago
return View(toShow);
}
8 years ago
public async Task<IActionResult> About()
{
8 years ago
FileInfo fi = new FileInfo("wwwroot/version");
6 years ago
return View("About", fi.Exists ? _localizer["Version logicielle: "] + await fi.OpenText().ReadToEndAsync() : _localizer["Aucune information sur la version logicielle n'est publiée."]);
}
9 years ago
public IActionResult Privacy()
{
return View();
}
public IActionResult AboutMarkdown()
{
return View();
}
public IActionResult Contact()
{
return View();
}
public ActionResult Chat()
{
6 years ago
if (User.Identity.IsAuthenticated)
{
ViewBag.IsAuthenticated = true;
string uid = User.GetUserId();
6 years ago
ViewBag.Contacts = _dbContext.Contact.Where(c => c.OwnerId == uid)
;
6 years ago
}
else ViewBag.IsAuthenticated = false;
return View();
}
public IActionResult Error()
{
var feature = this.HttpContext.Features.Get<IExceptionHandlerFeature>();
return View("~/Views/Shared/Error.cshtml", feature?.Error);
}
public IActionResult Status(int id)
{
ViewBag.StatusCode = id;
6 years ago
return View("~/Views/Shared/Status.cshtml");
}
6 years ago
public IActionResult Todo()
{
9 years ago
User.GetUserId();
6 years ago
return View();
}
6 years ago
public IActionResult VideoChat()
{
return View();
}
6 years ago
public IActionResult Audio()
{
return View();
}
6 years ago
}
}