273 lines
12 KiB
C#
273 lines
12 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Dynamic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using AutoMapper;
|
|
using gehGassi.Core.Interfaces;
|
|
using gehGassi.Domain.Common;
|
|
using gehGassi.Web.Auth;
|
|
using gehGassi.Web.Auth.Attributes;
|
|
using gehGassi.Web.Helper;
|
|
using gehGassi.Web.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Routing;
|
|
|
|
namespace gehGassi.Web.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Controller für die Verwaltung des Dashboards je nach Rolle
|
|
/// </summary>
|
|
[Authorize]
|
|
public class HomeController : BaseController
|
|
{
|
|
public static ConcurrentBag<Boolean> bs = new ConcurrentBag<Boolean>();
|
|
private readonly IUserService _userService;
|
|
private readonly IMapper _mapper;
|
|
private readonly ICustomerService _customerService;
|
|
private readonly IAppUserService _appUserService;
|
|
private readonly IListingService _listingService;
|
|
private readonly IAdvertisementService _advertisementService;
|
|
private readonly IBannerService _bannerService;
|
|
private readonly IPinService _pinService;
|
|
private readonly IWebHostEnvironment _environment;
|
|
private readonly IUrlHelperFactory _urlHelperFactory;
|
|
private readonly IOrderService _orderService;
|
|
private readonly IInvoiceService _invoiceService;
|
|
private readonly IAppUserReportService _appUserReportService;
|
|
private readonly IWalkComplaintService _walkComplaintService;
|
|
private readonly IAppFeedbackService _appFeedbackService;
|
|
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="userService">Instanz eines IUserService</param>
|
|
/// <param name="mapper">Instanz eines IMapper</param>
|
|
/// <param name="customerService">Instanz eines ICustomerService</param>
|
|
/// <param name="appUserService">Instanz eines IDogOwnerService</param>
|
|
/// <param name="listingService">Instanz eines IListingService</param>
|
|
/// <param name="advertisementService">Instanz eines IAdvertisementService</param>
|
|
/// <param name="bannerService">Instanz eines IBannerService</param>
|
|
/// <param name="pinService">Instanz eines IPinService</param>
|
|
/// <param name="environment">Instanz eines IWebHostEnvironment</param>
|
|
/// <param name="urlHelperFactory">Instanz einer IUrlHelperFactory</param>
|
|
/// <param name="orderService">Instanz eines IOrderService</param>
|
|
/// <param name="invoiceService">Instanz eines IInvoiceService</param>
|
|
/// <param name="appUserReportService">Instanz eines IAppUserReportService</param>
|
|
/// <param name="walkComplaintService">Instanz eines IWalkComplaintService</param>
|
|
/// <param name="appFeedbackService">Instanz eines IAppFeedbackService</param>
|
|
public HomeController(IUserService userService, IMapper mapper, ICustomerService customerService, IAppUserService appUserService,
|
|
IListingService listingService, IAdvertisementService advertisementService, IBannerService bannerService, IPinService pinService,
|
|
IWebHostEnvironment environment, IUrlHelperFactory urlHelperFactory, IOrderService orderService, IInvoiceService invoiceService,
|
|
IAppUserReportService appUserReportService, IWalkComplaintService walkComplaintService, IAppFeedbackService appFeedbackService) : base()
|
|
{
|
|
_userService = userService;
|
|
_mapper = mapper;
|
|
_customerService = customerService;
|
|
_appUserService = appUserService;
|
|
_listingService = listingService;
|
|
_advertisementService = advertisementService;
|
|
_bannerService = bannerService;
|
|
_pinService = pinService;
|
|
_environment = environment;
|
|
_urlHelperFactory = urlHelperFactory;
|
|
_orderService = orderService;
|
|
_invoiceService = invoiceService;
|
|
_appUserReportService = appUserReportService;
|
|
_walkComplaintService = walkComplaintService;
|
|
_appFeedbackService = appFeedbackService;
|
|
}
|
|
|
|
//[AllowAnonymous]
|
|
//public async Task<IActionResult> Test(long orderId)
|
|
//{
|
|
// var order = await _orderService.GetAsync(orderId);
|
|
// var invoice = await _invoiceService.GetByOrderAsync(orderId);
|
|
|
|
// var fileName = $"{invoice.Number}.pdf";
|
|
// var file = ControllerContext.GetPdfWithHeaderAndFooter(_urlHelperFactory, _environment, "Print", "CreditNote", new { orderId = order.Id, language = SelectedLanguage });
|
|
|
|
// var outputStream = new MemoryStream();
|
|
// outputStream.Write(file, 0, file.Length);
|
|
// outputStream.Position = 0;
|
|
// return File(file, "application/pdf");
|
|
//}
|
|
|
|
/// <summary>
|
|
/// Dash-Board View
|
|
/// </summary>
|
|
/// <returns>View</returns>
|
|
[Authorize(Policy = Policies.PowerUserOnly)]
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
var users = await _userService.CountAsync();
|
|
var customers = await _customerService.CountAsync();
|
|
var appUsers = await _appUserService.CountAsync(false);
|
|
var listingsTotal = await _listingService.CountAsync(false, true);
|
|
var listingsRunning = await _listingService.CountAsync(ListingStatus.Running, false);
|
|
var advertisementTotal = await _advertisementService.CountAsync(false, true);
|
|
var advertisementsRunning = await _advertisementService.CountAsync(AdvertisementStatus.Running, false);
|
|
var bannersTotal = await _bannerService.CountAsync(false, true);
|
|
var bannersRunning = await _bannerService.CountAsync(BannerStatus.Running, false);
|
|
var pinsTotal = await _pinService.CountAsync(false, true);
|
|
var pinsRunning = await _pinService.CountAsync(PinStatus.Running, false);
|
|
|
|
var appUserReportsTotal = await _appUserReportService.CountAsync();
|
|
var appUserReportsOpen = await _appUserReportService.CountAsync(AppUserReportStatus.Open);
|
|
appUserReportsOpen += await _appUserReportService.CountAsync(AppUserReportStatus.Processing);
|
|
var complaintsTotal = await _walkComplaintService.CountAsync();
|
|
var complaintssOpen = await _walkComplaintService.CountAsync(WalkComplaintStatus.Open);
|
|
complaintssOpen += await _walkComplaintService.CountAsync(WalkComplaintStatus.InProgress);
|
|
var feedbackTotal = await _appFeedbackService.CountAsync();
|
|
var feedbackOpen = await _appFeedbackService.CountAsync(AppFeedbackStatus.Open);
|
|
|
|
dynamic model = new ExpandoObject();
|
|
model.Users = users;
|
|
model.Customers = customers;
|
|
model.DogOwners = appUsers;
|
|
model.AppUsers = appUsers;
|
|
model.ListingsTotal = listingsTotal;
|
|
model.ListingsRunning = listingsRunning;
|
|
model.AdvertisementsTotal = advertisementTotal;
|
|
model.AdvertisementsRunning = advertisementsRunning;
|
|
model.BannersTotal = bannersTotal;
|
|
model.BannersRunning = bannersRunning;
|
|
model.PinsTotal = pinsTotal;
|
|
model.PinsRunning = pinsRunning;
|
|
model.AppUserReportsTotal = appUserReportsTotal;
|
|
model.AppUserReportsOpen = appUserReportsOpen;
|
|
model.ComplaintsTotal = complaintsTotal;
|
|
model.ComplaintssOpen = complaintssOpen;
|
|
model.FeedbackTotal = feedbackTotal;
|
|
model.FeedbackOpen = feedbackOpen;
|
|
|
|
return View(model);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dash-Board View Kunden
|
|
/// </summary>
|
|
/// <returns>View</returns>
|
|
[Authorize(Policy = Policies.CustomerOnly)]
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult IndexCustomer()
|
|
{
|
|
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dash-Board View App-User
|
|
/// </summary>
|
|
/// <returns>View</returns>
|
|
[Authorize(Policy = Policies.AppUserOnly)]
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult IndexAppUser()
|
|
{
|
|
|
|
return View();
|
|
}
|
|
|
|
#region Common
|
|
|
|
[AllowAnonymous]
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorVm { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Status401()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Status403()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Status404()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Setzen der neue gewählten Sprache
|
|
/// </summary>
|
|
/// <param name="culture">gewünschte Sprache</param>
|
|
/// <param name="returnUrl">Return Url</param>
|
|
/// <returns>Redirect</returns>
|
|
[HttpPost]
|
|
[AllowAnonymous]
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult SetLanguage(string culture, string returnUrl)
|
|
{
|
|
if(!IsValidCulture(culture))
|
|
return RedirectToAction("Login", "Account");
|
|
|
|
Response.Cookies.Append(
|
|
CookieRequestCultureProvider.DefaultCookieName,
|
|
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)),
|
|
new CookieOptions
|
|
{
|
|
Expires = DateTimeOffset.UtcNow.AddYears(1)
|
|
}
|
|
);
|
|
var currentCultureIso = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
|
|
CultureInfo.CurrentCulture = new CultureInfo(culture);
|
|
|
|
if (string.IsNullOrWhiteSpace(returnUrl))
|
|
returnUrl = "/";
|
|
|
|
if (!Uri.IsWellFormedUriString(returnUrl, UriKind.RelativeOrAbsolute))
|
|
returnUrl = "/";
|
|
|
|
if(returnUrl.ToLower().Contains("setlanguage"))
|
|
returnUrl = "/";
|
|
|
|
if (returnUrl.Contains($"/{currentCultureIso}/"))
|
|
returnUrl = returnUrl.Replace($"/{currentCultureIso}/", $"/{culture}/");
|
|
else if (returnUrl.Length <= 2 || returnUrl == $"/{currentCultureIso}")
|
|
returnUrl = $"~/{culture}/";
|
|
//else if (returnUrl.StartsWith("/") && !returnUrl.Contains($"/{currentCultureIso}/"))
|
|
// returnUrl = $"/{culture}{returnUrl}";
|
|
|
|
return LocalRedirect(returnUrl);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüfen ob ein Eingabestring eine gültige Culture repräsentiert
|
|
/// </summary>
|
|
/// <param name="culture">Zu prüfende Culture</param>
|
|
/// <returns>true wenn exisitert, false sonst</returns>
|
|
private bool IsValidCulture(string culture)
|
|
{
|
|
return
|
|
CultureInfo
|
|
.GetCultures(CultureTypes.SpecificCultures)
|
|
.Any(c => c.TwoLetterISOLanguageName == culture);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|