2016-05-17 18:22:18 +02:00
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 ;
2016-09-23 12:28:38 +02:00
using Microsoft.AspNet.Identity ;
using System.Linq ;
using System.Security.Claims ;
2017-01-24 10:43:42 +01:00
using Microsoft.Data.Entity ;
2017-02-21 03:18:21 +01:00
using Microsoft.AspNet.Http ;
using System.Threading.Tasks ;
2016-05-17 18:22:18 +02:00
namespace Yavsc.Controllers
{
2017-09-13 22:32:17 +02:00
using System.IO ;
2017-02-23 03:10:30 +01:00
using Models ;
2017-05-27 16:22:58 +02:00
using Yavsc ;
2017-03-29 01:55:25 +02:00
[AllowAnonymous]
2016-05-17 18:22:18 +02:00
public class HomeController : Controller
{
public IHostingEnvironment Hosting { get ; set ; }
2016-09-23 12:28:38 +02:00
private ApplicationDbContext DbContext ;
2016-05-17 18:22:18 +02:00
private readonly IHtmlLocalizer _localizer ;
2016-09-23 12:28:38 +02:00
public HomeController ( IHtmlLocalizer < Startup > localizer , IHostingEnvironment hosting ,
ApplicationDbContext context , UserManager < ApplicationUser > userManager )
2016-05-17 18:22:18 +02:00
{
_localizer = localizer ;
Hosting = hosting ;
2016-09-23 12:28:38 +02:00
DbContext = context ;
2016-05-17 18:22:18 +02:00
}
2017-02-21 03:18:21 +01:00
public async Task < IActionResult > Index ( string id )
2016-05-17 18:22:18 +02:00
{
2017-03-22 03:31:29 +01:00
ViewBag . IsFromSecureProx = ( Request . Headers . ContainsKey ( Constants . SshHeaderKey ) ) ? Request . Headers [ Constants . SshHeaderKey ] = = "on" : false ;
ViewBag . SecureHomeUrl = "https://" + Request . Headers [ "X-Forwarded-Host" ] ;
ViewBag . SshHeaderKey = Request . Headers [ Constants . SshHeaderKey ] ;
2017-02-21 03:18:21 +01:00
var uid = User . GetUserId ( ) ;
long [ ] clicked = null ;
if ( uid = = null ) {
await HttpContext . Session . LoadAsync ( ) ;
var strclicked = HttpContext . Session . GetString ( "clicked" ) ;
if ( strclicked ! = null ) clicked = strclicked . Split ( ':' ) . Select ( c = > long . Parse ( c ) ) . ToArray ( ) ;
if ( clicked = = null ) clicked = new long [ 0 ] ;
}
else clicked = DbContext . DimissClicked . Where ( d = > d . UserId = = uid ) . Select ( d = > d . NotificationId ) . ToArray ( ) ;
var notes = DbContext . Notification . Where (
n = > ! clicked . Any ( c = > n . Id = = c )
) ;
ViewData [ "Notify" ] = notes ;
2017-04-08 09:17:15 +02:00
ViewData [ "HasHaircutCommand" ] = DbContext . HairCutQueries . Any
( q = > q . ClientId = = uid & & q . Status < QueryStatus . Failed ) ;
2017-04-08 17:51:58 +02:00
if ( id = = null ) {
// Workaround
// NotImplementedException: Remotion.Linq.Clauses.ResultOperators.ConcatResultOperator
//
// Use Concat()| whatever to do left outer join on ToArray() or ToList(), not on IQueryable
var legacy = DbContext . Activities
. Include ( a = > a . Forms ) . Include ( a = > a . Children )
. Where ( a = > ! a . Hidden )
. Where ( a = > a . ParentCode = = null ) . ToArray ( ) ;
// OMG
var hiddenchildren = DbContext . Activities
. Include ( a = > a . Forms ) . Include ( a = > a . Children )
. Where ( a = > a . Parent . Hidden & & ! a . Hidden ) . ToArray ( ) ;
return View ( legacy . Concat ( hiddenchildren ) . OrderByDescending ( a = > a . Rate ) ) ;
}
else {
return View ( DbContext . Activities
. Include ( a = > a . Forms ) . Include ( a = > a . Children )
. Where ( a = > ! a . Hidden )
. Where ( a = > a . ParentCode = = id ) . OrderByDescending ( a = > a . Rate ) ) ;
}
2016-05-17 18:22:18 +02:00
}
2017-09-13 22:32:17 +02:00
public async Task < IActionResult > About ( )
2016-05-17 18:22:18 +02:00
{
2017-09-13 22:32:17 +02:00
FileInfo fi = new FileInfo ( "wwwroot/version" ) ;
return View ( "About" , fi . Exists ? _localizer [ "Version logicielle: " ] + await fi . OpenText ( ) . ReadToEndAsync ( ) : _localizer [ "Aucune information sur la version logicielle n'est publiée." ] ) ;
2016-05-17 18:22:18 +02:00
}
2017-06-14 12:28:08 +02:00
public IActionResult Privacy ( )
{
return View ( ) ;
}
2016-06-13 13:33:32 +02:00
public IActionResult AboutMarkdown ( )
{
return View ( ) ;
}
2016-05-17 18:22:18 +02:00
public IActionResult Contact ( )
{
return View ( ) ;
}
public ActionResult Chat ( )
{
2016-09-23 12:28:38 +02:00
if ( User . Identity . IsAuthenticated ) {
2016-11-01 23:21:03 +01:00
ViewBag . IsAuthenticated = true ;
2016-09-23 12:28:38 +02:00
string uid = User . GetUserId ( ) ;
2016-11-02 11:27:12 +01:00
ViewBag . Contacts = DbContext . Contacts . Where ( c = > c . OwnerId = = uid )
2016-09-23 12:28:38 +02:00
;
2016-11-01 23:21:03 +01:00
} else ViewBag . IsAuthenticated = false ;
2016-05-17 18:22:18 +02:00
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 ;
return View ( "~/Views/Shared/Status.cshtml" ) ;
}
public IActionResult Todo ( )
{
2017-06-20 02:47:52 +02:00
User . GetUserId ( ) ;
2016-05-17 18:22:18 +02:00
return View ( ) ;
}
2017-08-31 17:36:45 +02:00
public IActionResult VideoChat ( )
{
return View ( ) ;
}
2016-05-17 18:22:18 +02:00
}
}