Skip to content

Commit

Permalink
[#22 and #36]
Browse files Browse the repository at this point in the history
Start work on dropdown for user profile

Admin can promote team leader
  • Loading branch information
IceSentry committed Feb 23, 2016
1 parent c5004c9 commit 52e970a
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 23 deletions.
3 changes: 3 additions & 0 deletions LanAdept/LanAdept.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@
<Compile Include="Views\Tournament\ModelController\TeamModel.cs" />
<Compile Include="Views\Tournament\ModelController\TournamentController.cs" />
<Compile Include="Views\Tournament\ModelController\TournamentModel.cs" />
<Compile Include="Views\User\ModelController\UserController.cs" />
<Compile Include="Views\User\ModelController\UserModel.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Content\bootstrap-lan.css" />
Expand Down Expand Up @@ -354,6 +356,7 @@
<Content Include="Views\Auth\ExternalLoginConfirmation.cshtml" />
<Content Include="Views\Emails\Confirmation.Text.cshtml" />
<Content Include="Views\Emails\Confirmation.Html.cshtml" />
<Content Include="Views\User\Index.cshtml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
Expand Down
68 changes: 45 additions & 23 deletions LanAdept/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,49 @@
@Html.ListItemAction("Connexion", "Login", "Auth", new { ReturnUrl = Request.Url.AbsolutePath })
@Html.ListItemAction("Inscription", "Register", "Auth")

@if (LanAdeptCore.Service.UserService.IsTeamLeader())
@if (LanAdeptCore.Service.UserService.IsUserLoggedIn())
{
int nbDemandes = @LanAdeptCore.Service.UserService.GetNbTeamDemand();
<li class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-user"></span>
@if (LanAdeptCore.Service.UserService.IsTeamLeader() && LanAdeptCore.Service.UserService.GetNbTeamDemand() > 0)
{
<span class="label label-danger">@LanAdeptCore.Service.UserService.GetNbTeamDemand()</span>
}
</button>
<ul class="dropdown-menu">
@Html.ListItemAction("Mon profil", "Index", "User")
@if (LanAdeptCore.Service.UserService.IsTeamLeader())
{
int nbDemandes = @LanAdeptCore.Service.UserService.GetNbTeamDemand();

<li>
<a href="@Url.Action("Index", "Team")" class="hidden-sm">
@if (LanAdeptCore.Service.UserService.GetNbTeams() > 1)
{
<span>Mes équipes</span>
}
else if (LanAdeptCore.Service.UserService.GetNbTeams() == 1)
{
<span>Mon équipe</span>
}
@if (nbDemandes > 0)
{
<span class="label label-danger">@nbDemandes</span>
}
</a>
</li>
@*@Html.ListItemAction("Mes équipes", "Index", "Team", null, new { @class = "hidden-sm" })*@
}

<li>
<a href="@Url.Action("Index", "Team")" class="hidden-sm">
Mes équipes
@if (nbDemandes > 0)
@if (LanAdeptCore.Service.ReservationService.HasUserPlace())
{
<span class="label label-danger">@nbDemandes</span>
@Html.ListItemAction("Ma place", "MaPlace", "Place")
}
</a>
@Html.ListItemAction("Déconnexion", "Logout", "Auth")
</ul>
</li>
@*@Html.ListItemAction("Mes équipes", "Index", "Team", null, new { @class = "hidden-sm" })*@
}

@if (LanAdeptCore.Service.ReservationService.HasUserPlace())
{
@Html.ListItemAction("Ma place", "MaPlace", "Place")
}
@Html.ListItemAction("Déconnexion", "Logout", "Auth")
</ul>
</div>
</div>
Expand All @@ -92,15 +114,15 @@
</div>

<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-32262555-4', 'auto');
ga('send', 'pageview');
ga('create', 'UA-32262555-4', 'auto');
ga('send', 'pageview');
</script>
@Scripts.Render("~/bundles/jquery")
Expand Down
10 changes: 10 additions & 0 deletions LanAdept/Views/User/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@model LanAdept.Views.User.ModelController.UserModel

@{
ViewBag.Title = "Index";
}

<h2>Mon profil</h2>

@Html.DisplayFor(model => model.CompleteName)
@Html.DisplayFor(model => model.Email)
33 changes: 33 additions & 0 deletions LanAdept/Views/User/ModelController/UserController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using LanAdept.Views.User.ModelController;
using LanAdeptCore.Service;
using LanAdeptData.DAL;
using LanAdeptData.Model.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LanAdept.Controllers
{
public class UserController : Controller
{
private UnitOfWork uow
{
get { return UnitOfWork.Current; }
}

[AllowAnonymous]
public ActionResult Index()
{
User u = UserService.GetLoggedInUser();

UserModel um = new UserModel();
um.CompleteName = u.CompleteName;
um.Email = u.Email;
um.UserId = u.Id;

return View(um);
}
}
}
17 changes: 17 additions & 0 deletions LanAdept/Views/User/ModelController/UserModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace LanAdept.Views.User.ModelController
{
public class UserModel
{
public string UserId { get; set; }
[Required]
public string CompleteName { get; set; }
[Required]
public string Email { get; set; }
}
}
31 changes: 31 additions & 0 deletions LanAdeptAdmin/Views/Tournaments/DetailsTeam.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<td class="text-right">
@if (Model.TeamLeaderTag != gamerTag)
{
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#promoteModal" data-gamertag="@gamerTag.Gamertag" data-gamertag-id="@gamerTag.GamerTagID">
Promote
</button>
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#kickModal" data-gamertag="@gamerTag.Gamertag" data-gamertag-id="@gamerTag.GamerTagID">
Exclure
</button>
Expand Down Expand Up @@ -122,6 +125,24 @@
</div>
</div>

<div class="modal fade" id="promoteModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Exclure un joueur</h4>
</div>
<div class="modal-body">
<p>Voulez-vous vraiment promouvoir le joueur "<span id="modal-gamertag"></span>"?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
<a href="#" class="btn btn-success" id="modal-link">Promouvoir</a>
</div>
</div>
</div>
</div>

@section Scripts {
<script>
$('#kickModal').on('show.bs.modal', function (event) {
Expand All @@ -133,5 +154,15 @@
modal.find('#modal-gamertag').text(gamertag);
modal.find('#modal-link').attr("href", "@Url.Action("KickPlayer", new { teamId = Model.TeamID })" + "&GamerTagId=" + gamertagId)
});
$('#promoteModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var gamertagId = button.data('gamertagId');
var gamertag = button.data('gamertag');
var modal = $(this);
modal.find('#modal-gamertag').text(gamertag);
modal.find('#modal-link').attr("href", "@Url.Action("PromotePlayer", new { teamId = Model.TeamID })" + "&GamerTagId=" + gamertagId)
});
</script>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Microsoft.AspNet.Identity.Owin;
using LanAdeptCore.Attribute.Authorization;
using LanAdeptData.Model.Tournaments;
using LanAdeptData.Model.Users;
using LanAdeptCore.Service;

namespace LanAdeptAdmin.Views
{
Expand Down Expand Up @@ -231,6 +233,30 @@ public ActionResult KickPlayer(int? gamerTagId, int? teamId)
return RedirectToAction("DetailsTeam", new { id = teamId });
}

[LanAuthorize(Roles = "tournamentAdmin, tournamentMod")]
public ActionResult PromotePlayer(int? gamerTagId, int? teamId)
{
GamerTag gamerTag = uow.GamerTagRepository.GetByID(gamerTagId);
Team team = uow.TeamRepository.GetByID(teamId);

if (team.TeamLeaderTag == gamerTag || team.GamerTags.Count == 1)
{
TempData["ErrorMessage"] = "Vous ne pouvez pas promouvoir le team leader.";
return RedirectToAction("DetailsTeam", new { id = teamId });
}
else
{

team.TeamLeaderTag = gamerTag;

uow.TeamRepository.Update(team);
uow.GamerTagRepository.Update(gamerTag);
uow.Save();
}

return RedirectToAction("DetailsTeam", new { id = teamId });
}

[LanAuthorize(Roles = "tournamentAdmin, tournamentMod")]
public ActionResult EditTeam(int? teamId)
{
Expand Down
10 changes: 10 additions & 0 deletions LanAdeptCore/Service/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,15 @@ public static int GetNbTeamDemand()

return nbDemands;
}

public static int GetNbTeams()
{
if (!IsTeamLeader())
return 0;

IEnumerable<Team> teams = uow.TeamRepository.GetByTeamLeaderID(GetLoggedInUser().Id);

return teams.Count();
}
}
}

0 comments on commit 52e970a

Please sign in to comment.