gehgassi_backend/gehGassi.Web/Views/Page/ShowCompetitionMonthWalker.cshtml

202 lines
6.8 KiB
Plaintext

@using Microsoft.AspNetCore.Mvc.Localization
@using gehGassi.Domain.Coins
@using gehGassi.Core.Interfaces
@using gehGassi.Domain.Dogs
@using gehGassi.Web.Helper
@model List<CoinsPerMonthWithNames>
@inject IViewLocalizer Localizer
@{
ViewData["Title"] = Localizer["Common_Competition"];
Layout = "_LayoutApp";
string selectedLanguage = "de";
if(ViewBag.SelectedLanguage != null)
{
selectedLanguage = ViewBag.SelectedLanguage;
}
string gassiUrl = string.Empty;
if (selectedLanguage.ToLower() == "de")
{
gassiUrl = "https://gehgassi.com/de/wettbewerb?role=walker";
}
else
{
gassiUrl = "https://gehgassi.com/en/competition?role=walker";
}
bool dark = ViewBag.DarkMode;
int year = ViewBag.Year;
int month = ViewBag.Month;
var isCurrent = year == DateTimeOffset.UtcNow.Year && month == DateTimeOffset.UtcNow.Month;
var hasNext = !isCurrent;
var hasPrevious = false;
var nextMonth = new DateTimeOffset(year, month, 1, 0, 0, 0, TimeSpan.Zero).AddMonths(1);
var previousMonth = new DateTimeOffset(year, month, 1, 0, 0, 0, TimeSpan.Zero).AddMonths(-1);
if (previousMonth >= new DateTimeOffset(2023, 11, 1, 0, 0, 0, TimeSpan.Zero))
{
hasPrevious = true;
}
var appUserId = string.Empty;
AppUser appUser = null;
if (ViewBag.AppUser != null)
{
appUser = ViewBag.AppUser;
appUserId = appUser.Id;
}
var appUserIsInList = false;
long selectedId = -1;
CoinsPerMonth myCoins = null;
if (ViewBag.MyCoins != null)
{
myCoins = ViewBag.MyCoins;
selectedId = myCoins.Id;
}
var minCoins = 0m;
if (ViewBag.MinCoins != null)
{
minCoins = ViewBag.MinCoins;
}
CoinsOptions coinsOptions = ViewBag.CoinsOptions;
}
<div class="mt-4 ">
<div class="row">
<div class="col-2">
@if (hasPrevious)
{
<a href="@Url.Action("ShowCompetitionMonthWalker", new{year=previousMonth.Year, month=previousMonth.Month, a=appUserId, dark=dark})" class="btn btn-primary">&lt;</a>
}
else
{
<button class="btn btn-primary" disabled>&lt;</button>
}
</div>
<div class="col-8 text-center"><h2 class="mb-1">@month-@year</h2></div>
<div class="col-2 text-end">
@if (hasNext)
{
<a href="@Url.Action("ShowCompetitionMonthWalker", new{year=nextMonth.Year, month=nextMonth.Month, a=appUserId, dark=dark})" class="btn btn-primary">&gt;</a>
}
else
{
<button class="btn btn-primary" disabled>&gt;</button>
}
</div>
</div>
@if (isCurrent)
{
<h5 class="mb-4 text-center mt-2">Min. @minCoins gassiCoins</h5>
}
@if (Model.Count == 0)
{
if (isCurrent)
{
<div class="alert alert-info mt-5 mb-5">
<div>@Localizer["Competition_Criteria_None"]</div>
<div>@Localizer["Competition_Criteria"] <strong>@minCoins gassiCoins</strong>.</div>
</div>
@if (appUser != null)
{
<h3 class="text-center mb-5">@Localizer["Competition_Coins_Current"]: @myCoins.Balance</h3>
}
}
else
{
<div class="alert alert-info mt-5">
<div>@Localizer["Competition_NoWinner"]</div>
</div>
}
}
else
{
var counter = 1;
<div class="mt-2 mb-5">
@if (Model.Count >= 10)
{
<div class="text-center"><h5>TOP 10</h5></div>
}
<table class="table">
<thead>
<tr>
<th scope="col">@Localizer["Competition_Place"]</th>
<th scope="col">@Localizer["Competition_Walker"]</th>
<th scope="col" class="text-end">gassiCoins</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
string selected;
if (item.Id == selectedId)
{
selected = "competition-selected";
appUserIsInList = true;
}
else
{
selected = string.Empty;
}
<tr class="@selected">
<th scope="row">@counter</th>
<td>@item.AppUserName.AnonymizeFullName()</td>
<td class="text-end">@item.Balance</td>
</tr>
counter++;
}
@if (!appUserIsInList && appUser != null)
{
<tr>
<th scope="row">...</th>
<td>...</td>
<td class="text-end">...</td>
</tr>
<tr class="competition-selected">
<th scope="row">
@if (Model.Count >= 10)
{
<span>11+</span>
}
else
{
<span>?</span>
}
</th>
<td>@((appUser.FirstName + " " + appUser.LastName).AnonymizeFullName())</td>
<td class="text-end">@myCoins.Balance</td>
</tr>
<tr>
<th scope="row">...</th>
<td>...</td>
<td class="text-end">...</td>
</tr>
}
</tbody>
</table>
</div>
}
@if (isCurrent)
{
<div class="text-center mb-3">
<a href="@gassiUrl">@Localizer["Competition_Price_About_Month"]</a>
</div>
<div class="alert alert-info">
<h4>@Localizer["Competition_Coins_HowToEarn"]</h4>
<div>@Localizer["Competition_Coins_Walk"]: <strong>@coinsOptions.WalkForDogwalker</strong></div>
<div>@Localizer["Competition_Coins_Sitting"]: <strong>@coinsOptions.SittingForDowgWalker</strong></div>
<div>@Localizer["Competition_Coins_Daycare"]: <strong>@coinsOptions.DayCareForDowgWalker</strong></div>
</div>
}
<div class="mt-4 mb-4 text-center">
<a class="btn btn-secondary" href="@Url.Action("Show", new{code="CMRULESDW", language=selectedLanguage})">@Localizer["Competition_Rules"]</a>
</div>
</div>