change site
This commit is contained in:
@@ -13,7 +13,7 @@ namespace pointMaster.Controllers
|
|||||||
{
|
{
|
||||||
if (!this.User.Identity!.IsAuthenticated)
|
if (!this.User.Identity!.IsAuthenticated)
|
||||||
{
|
{
|
||||||
return this.Challenge(OpenIdConnectDefaults.AuthenticationScheme);
|
return Challenge(OpenIdConnectDefaults.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Redirect(redirectUrl);
|
return Redirect(redirectUrl);
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ namespace pointMaster.Controllers
|
|||||||
|
|
||||||
if (HttpContext.User.Claims.FirstOrDefault(x => x.Value == Roles.Editor) != null)
|
if (HttpContext.User.Claims.FirstOrDefault(x => x.Value == Roles.Editor) != null)
|
||||||
{
|
{
|
||||||
vm.links.Add(new NavUrl("Patruljer", "Patrulje"));
|
vm.links.Add(new NavUrl("Patruljer", "/Patrulje"));
|
||||||
vm.links.Add(new NavUrl("Point", "Point"));
|
vm.links.Add(new NavUrl("Point", "/Point"));
|
||||||
vm.links.Add(new NavUrl("Poster", "Poster"));
|
vm.links.Add(new NavUrl("Poster", "/Poster"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(vm);
|
return View(vm);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using pointMaster.Data;
|
||||||
using pointMaster.Models;
|
using pointMaster.Models;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
@@ -8,17 +10,49 @@ namespace pointMaster.Controllers
|
|||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<HomeController> _logger;
|
private readonly ILogger<HomeController> _logger;
|
||||||
|
private readonly DataContext context;
|
||||||
|
|
||||||
public HomeController(ILogger<HomeController> logger)
|
public HomeController(ILogger<HomeController> logger, DataContext context)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
var vm = new HomePageViewModel();
|
var vm = new HomePageViewModel();
|
||||||
|
|
||||||
vm.loggedIn = User.Identity.IsAuthenticated;
|
var patruljer = await context.Patruljer.Include(p => p.Points).ToListAsync();
|
||||||
|
|
||||||
|
vm.Samlet = new List<PatruljePlacering>();
|
||||||
|
vm.Turnout= new List<PatruljePlacering>();
|
||||||
|
vm.Points = new List<PatruljePlacering>();
|
||||||
|
|
||||||
|
foreach (var patrulje in patruljer)
|
||||||
|
{
|
||||||
|
vm.Points.Add(new PatruljePlacering
|
||||||
|
{
|
||||||
|
Patrulje = patrulje,
|
||||||
|
point = patrulje.Points.Sum(x => x.Points),
|
||||||
|
});
|
||||||
|
|
||||||
|
vm.Turnout.Add(new PatruljePlacering
|
||||||
|
{
|
||||||
|
Patrulje = patrulje,
|
||||||
|
point = patrulje.Points.Sum(x => x.Turnout),
|
||||||
|
});
|
||||||
|
|
||||||
|
vm.Samlet.Add(new PatruljePlacering
|
||||||
|
{
|
||||||
|
Patrulje = patrulje,
|
||||||
|
point = patrulje.Points.Sum(x => x.Points) + patrulje.Points.Sum(x => x.Turnout),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
vm.Samlet = vm.Samlet.OrderByDescending(x => x.point).ToList();
|
||||||
|
vm.Points = vm.Points.OrderByDescending(x => x.point).ToList();
|
||||||
|
vm.Turnout = vm.Turnout.OrderByDescending(x => x.point).ToList();
|
||||||
|
|
||||||
|
|
||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
@@ -43,6 +77,13 @@ namespace pointMaster.Controllers
|
|||||||
|
|
||||||
public class HomePageViewModel
|
public class HomePageViewModel
|
||||||
{
|
{
|
||||||
public bool loggedIn { get; set; } = false;
|
public List<PatruljePlacering> Samlet { get; set; } = null!;
|
||||||
|
public List<PatruljePlacering> Turnout { get; set; } = null!;
|
||||||
|
public List<PatruljePlacering> Points { get; set; } = null!;
|
||||||
|
}
|
||||||
|
public class PatruljePlacering
|
||||||
|
{
|
||||||
|
public Patrulje Patrulje { get; set; } = null!;
|
||||||
|
public int point { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,25 @@ namespace pointMaster.Controllers
|
|||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
var vm = new IndexViewModel();
|
var vm = new IndexViewModel();
|
||||||
vm.patruljeModels = await _context.Patruljer.Include(p => p.PatruljeMedlems).ToListAsync();
|
|
||||||
|
vm.patruljePoints = new Dictionary<int, int>();
|
||||||
|
vm.patruljeTurnout = new Dictionary<int, int>();
|
||||||
|
|
||||||
|
vm.patruljeModels = await _context.Patruljer.Include(p => p.PatruljeMedlems).Include(p => p.Points).ToListAsync();
|
||||||
|
|
||||||
|
foreach (var patrulje in vm.patruljeModels)
|
||||||
|
{
|
||||||
|
if (patrulje.Points == null)
|
||||||
|
{
|
||||||
|
vm.patruljePoints.Add(patrulje.Id, 0);
|
||||||
|
vm.patruljeTurnout.Add(patrulje.Id, 0);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
vm.patruljePoints.Add(patrulje.Id, patrulje.Points.Sum(x => x.Points));
|
||||||
|
vm.patruljeTurnout.Add(patrulje.Id, patrulje.Points.Sum(x => x.Turnout));
|
||||||
|
}
|
||||||
|
|
||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
@@ -108,7 +126,9 @@ namespace pointMaster.Controllers
|
|||||||
|
|
||||||
public class IndexViewModel
|
public class IndexViewModel
|
||||||
{
|
{
|
||||||
public List<Patrulje> patruljeModels { get; set; }
|
public List<Patrulje> patruljeModels { get; set; } = null!;
|
||||||
|
public Dictionary<int, int> patruljePoints { get; set; } = null!;
|
||||||
|
public Dictionary<int, int> patruljeTurnout { get; set; } = null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,28 @@ namespace pointMaster.Controllers
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
return View();
|
var vm = new PointViewModel();
|
||||||
|
|
||||||
|
vm.points = await context.Points.Include(p => p.Patrulje).Include(p => p.Poster).ToListAsync();
|
||||||
|
|
||||||
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult SkiftPatrulje()
|
public async Task<IActionResult> SkiftPatrulje()
|
||||||
{
|
{
|
||||||
var vm = new SkiftPatruljeViewModel();
|
var vm = new SkiftPatruljeViewModel();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(Request.Cookies["Post"]))
|
||||||
|
{
|
||||||
|
return RedirectToAction(nameof(SelectPoster));
|
||||||
|
}
|
||||||
|
|
||||||
|
int.TryParse(Request.Cookies["Post"], out var postId);
|
||||||
|
|
||||||
|
vm.post = await context.Poster.FindAsync(postId);
|
||||||
|
|
||||||
vm.Patruljer = context.Patruljer.ToList();
|
vm.Patruljer = context.Patruljer.ToList();
|
||||||
|
|
||||||
return View(vm);
|
return View(vm);
|
||||||
@@ -125,7 +138,18 @@ namespace pointMaster.Controllers
|
|||||||
|
|
||||||
Response.Cookies.Append("Post", id.ToString(), cookieOptions);
|
Response.Cookies.Append("Post", id.ToString(), cookieOptions);
|
||||||
|
|
||||||
return RedirectToAction("index", "home");
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult DeletePoint(int id)
|
||||||
|
{
|
||||||
|
var point = context.Points.FirstOrDefault(p => p.Id == id);
|
||||||
|
if (point == null) { return NotFound(); }
|
||||||
|
|
||||||
|
context.Points.Remove(point);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,5 +167,10 @@ namespace pointMaster.Controllers
|
|||||||
public class SkiftPatruljeViewModel
|
public class SkiftPatruljeViewModel
|
||||||
{
|
{
|
||||||
public List<Patrulje> Patruljer { get; set; } = null!;
|
public List<Patrulje> Patruljer { get; set; } = null!;
|
||||||
|
public Post? post { get; set; } = null!;
|
||||||
|
}
|
||||||
|
public class PointViewModel
|
||||||
|
{
|
||||||
|
public List<Point> points { get; set; } = null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,73 @@
|
|||||||
<div>
|
<div>
|
||||||
<h1>Velkommen til PointMaster</h1>
|
<h1>Velkommen til PointMaster</h1>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
@if (Model.loggedIn)
|
<div class="col-sm">
|
||||||
{
|
<h3>Samlet</h3>
|
||||||
<a class="btn btn-primary" asp-action="GivPoint" asp-controller="Point">Giv point</a>
|
<table class="table table-striped">
|
||||||
}
|
<thead>
|
||||||
else
|
<tr>
|
||||||
{
|
<th></th>
|
||||||
<a class="btn btn-primary" asp-action="signin" asp-controller="Account">Log ind</a>
|
<th>Patrulje</th>
|
||||||
}
|
<th>Point</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@for (var i = 0; i < Model.Samlet.Count; i++)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@(i+1)</td>
|
||||||
|
<td>@Model.Samlet[i].Patrulje.Name</td>
|
||||||
|
<td>@Model.Samlet[i].point</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm">
|
||||||
|
<h3>Point</h3>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Patrulje</th>
|
||||||
|
<th>Point</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@for (var i = 0; i < Model.Points.Count; i++)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@(i+1)</td>
|
||||||
|
<td>@Model.Points[i].Patrulje.Name</td>
|
||||||
|
<td>@Model.Points[i].point</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm">
|
||||||
|
<h3>Turnout</h3>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Patrulje</th>
|
||||||
|
<th>Point</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@for (var i = 0; i < Model.Turnout.Count; i++)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@(i + 1)</td>
|
||||||
|
<td>@Model.Turnout[i].Patrulje.Name</td>
|
||||||
|
<td>@Model.Turnout[i].point</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
@model pointMaster.Controllers.PatruljeController.IndexViewModel
|
@model pointMaster.Controllers.PatruljeController.IndexViewModel
|
||||||
|
|
||||||
<h1>Patruljer</h1>
|
<h1>Patruljer</h1>
|
||||||
|
<a asp-action="Create" asp-controller="Patrulje" class="btn btn-primary">Opret patrulje</a>
|
||||||
@foreach (var patrulje in Model.patruljeModels)
|
@foreach (var patrulje in Model.patruljeModels)
|
||||||
{
|
{
|
||||||
<div class="border m-4 p-4 rounded">
|
<div class="border m-4 p-4 rounded">
|
||||||
<div class="d-flex flex-row justify-content-between">
|
<div class="d-flex flex-row justify-content-between">
|
||||||
<h2>@patrulje.Name</h2>
|
<h2>@patrulje.Name</h2>
|
||||||
|
<p>Points: @Model.patruljePoints[patrulje.Id]</p>
|
||||||
|
<p>Turnout: @Model.patruljeTurnout[patrulje.Id]</p>
|
||||||
<div class="my-auto">
|
<div class="my-auto">
|
||||||
<a
|
<a
|
||||||
asp-action="DeletePatrulje"
|
asp-action="DeletePatrulje"
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
|
|
||||||
<div class="Frame">
|
<div class="Frame">
|
||||||
<div class="Post">
|
<div class="Post">
|
||||||
<h1>@Model.Runde.Name</h1>
|
<h1>Post: @Model.Runde.Name</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>@Model.Patrulje.Name</h2>
|
<h2>Patrulje: @Model.Patrulje.Name</h2>
|
||||||
<form asp-action="GivPoint">
|
<form asp-action="GivPoint">
|
||||||
<div class="inputfield">
|
<div class="inputfield">
|
||||||
<h4>Point</h4>
|
<h4>Point</h4>
|
||||||
|
|||||||
@@ -1,5 +1,30 @@
|
|||||||
@*
|
@model pointMaster.Controllers.PointViewModel;
|
||||||
|
@*
|
||||||
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||||
*@
|
*@
|
||||||
@{
|
@{
|
||||||
}
|
}
|
||||||
|
<a asp-action="GivPoint" asp-controller="Point" class="btn btn-primary">Giv point</a>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Patrulje</th>
|
||||||
|
<th scope="col">Post</th>
|
||||||
|
<th scope="col">Point</th>
|
||||||
|
<th scope="col">Turnout</th>
|
||||||
|
<th scope="col"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var point in Model.points)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td scope="row">@point.Patrulje.Name</td>
|
||||||
|
<td scope="row">@point.Poster.Name</td>
|
||||||
|
<td scope="row">@point.Points</td>
|
||||||
|
<td scope="row">@point.Turnout</td>
|
||||||
|
<td scope="row"><a asp-action="DeletePoint" asp-controller="Point" asp-route-id="@point.Id" class="btn btn-danger">Slet point</a></td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
@model pointMaster.Controllers.SkiftPatruljeViewModel;
|
@model pointMaster.Controllers.SkiftPatruljeViewModel;
|
||||||
|
@if (Model.post != null)
|
||||||
|
{
|
||||||
|
<h3>Du giver point som: @Model.post.Name</h3>
|
||||||
|
}
|
||||||
<h1>Vælg patrulje</h1>
|
<h1>Vælg patrulje</h1>
|
||||||
@foreach (var patrulje in Model.Patruljer)
|
@foreach (var patrulje in Model.Patruljer)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user